help me get the points of the mask

6 ビュー (過去 30 日間)
kunal
kunal 2025 年 5 月 9 日
回答済み: Matt J 2025 年 7 月 6 日
I have shapes like this and i want the four points like what i have marked and the enclosing are i drew with lines
  6 件のコメント
kunal
kunal 2025 年 5 月 13 日
ah yes, it's ok if it overlaps or not, sorry if this is confusing. As you can see every part or side i have enclosed it in perfect square/rectangle or four point polygon and where the mask is continuous it also shares 2 point of edges
Image Analyst
Image Analyst 2025 年 5 月 13 日
@kunal did you not understand my Answer below or did you not even see it (scroll down)? I didn't see any response whatsoever to it.

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2025 年 5 月 9 日
編集済み: Image Analyst 2025 年 5 月 9 日
You can find a wealth of information online just by Googling "Minimum perimeter polygon". Yes, it's a thing. And there is much research and published papers and algorithms on it.
"In digital image processing, a minimum perimeter polygon (MPP) is a technique to represent the boundary of a shape or object using a polygon with the fewest possible edges while maintaining the essential shape characteristics. It's a form of polygonal approximation where the goal is to approximate a digital boundary with a polygon with the smallest perimeter."
Also see the PDF I've attached.
Sorry, I don't have any MATLAB code for it but you could try asking MATLAB's AI engine to write it for you:
You might also look at the LIDAR toolbox : https://www.mathworks.com/help/lidar/
See examples at:
  2 件のコメント
kunal
kunal 2025 年 5 月 14 日
this consider the image as an whole but i want to seperate the pieces into part of rectangle
Image Analyst
Image Analyst 2025 年 5 月 14 日
Each "blob" in the image is considered a separate, distinct polygon. You can get the minimum points to define each using the concepts of minimum perimeter polygon.
If you have a single blob that is shaped like an L, the min perimeter polygon will define the whole L shape but it will not split the two L into separate blobs. Not sure why you'd really need that though instead of just a single polygon.

サインインしてコメントする。


Matt J
Matt J 2025 年 7 月 6 日
You can try bwlpolyshape(), downloadable from,
which will fit a polyshape to the mask, subject to a distance tolerance distTol. You will have to do some postprocessing to consolidate some of the spurious vertices.
S=structfun(@logical,load('my_masks'),'uni',0);
p=bwlpolyshape(S.a2,distTol=15,refine=0,Visualize=true)
p =
polyshape with properties: Vertices: [20×2 double] NumRegions: 1 NumHoles: 2
[x,y]=boundary(p);
hold on
plot(x,y,'og','MarkerFaceColor','y');hold off

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by