【matlab程序】多边形多联通区域内的最大矩形正方形圆形等

文摘   2024-06-01 17:37   德国  

matlab程序多边形多联通区域内的最大矩形正方形圆形等


多边形区域:

多连通区域:


多边形和多连通区域都可使用以下代码:

多边形多联通区域内的最大矩形都可分为水平方向任意方向

        1:水平方向是指:矩形和坐标轴(x-y)平行的最大矩形

        2:任意方向是指:矩形和坐标轴(x-y)不平行的最大矩形;


一、多边形内的最大矩形水平方向

注:图中红色边框为最大矩形形状,附有四个顶点的坐标(x,y)。绿色的是和x轴的夹角。图中中心标有矩形面积,单位(pixel).


二、多边形内的最大矩形任意方向

注:图中红色边框为最大矩形形状,附有四个顶点的坐标(x,y绿色的是和x轴的夹角图中中心标有矩形面积,单位(pixel).


一、多边形内的最大正方形水平方向


注:图中红色边框为最大正方形形状,附有四个顶点的坐标(x,y绿色的是和x轴的夹角图中中心标有矩形面积,单位(pixel).


二、多边形内的最大正方形任意方向

注:图中红色边框为最大正方形形状,附有四个顶点的坐标(x,y绿色的是和x轴的夹角图中中心标有矩形面积,单位(pixel).


多边形内的圆形

注:图中红色边框为最大圆形形状,附有圆心坐标(x,y),半径r,图中中心标有矩形面积,单位(pixel).


matlab代码


clear;clc;close all;map_12 =load('mask.txt');LargestSquare(map_12);LargestRectangle(map_12);LargestCircle(map_12);



其中,LargestSquare为函数,并附有画图展示功能。

其他最大都为函数。


函数介绍:

function LRout=LargestRectangle (image,varargin) Function to find the largest inscribed rectangle in an arbitrary shape with multiple holes.  INPUT: The input has a minimum of one entry and maximum of 6 entries in following order:  image: Image, RGB, grey or BW. By preference BW.  E.g.: image=imread(C:\MyImage.tif);  RotationStep: Default: 5°  Rotation Step in degrees. In order to find tilted rectangles, the image is rotated.  Range: 0 < RotationStep <= 90.  If RotationStep>(LastAngle-FirstAngle) then the image is rotated once. iterate: Default: 1 (with iteration)  If 0 then no iteration, if 1 then iteration.  No iteration if (FirstAngle == LastAngle) Iterate refines the rotation steps with the goal to find the largest possible rectangle,  In some cases, it might lock on another smaller local maximum. FirstAngle: Default: 0°, first angle for detection of rectangle with any orientation. 
First angle: 0 <= FirstAngle < 90 LastAngle: Default: 89.9999°, last angle for detection of rectangle with any orientation.
Last angle: FirstAngle <= LastAngle <= 90 OUTPUT LRout: 1st row: Area of the largest rectangle in px, Rotation angle in degrees counterclockwise
2nd row: x,y of top corner of the largest rectangle 3rd row: x,y of right corner of the largest rectangle
4th row: x,y of bottom corner of the largest rectangle
5th row: x,y of left corner of the largest rectangle

reference:


Copyright (c) 2019, Peter SeiboldAll rights reserved.

Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution* Neither the name of nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AREDISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLEFOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIALDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVERCAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USEOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.








海洋与大气科学
海洋与大气科学数据分析,数据可视化分享,可教学。
 最新文章