フィルターのクリア

Finding a largest rectangular object in binary image with minimum length and width

7 ビュー (過去 30 日間)
Az
Az 2023 年 10 月 22 日
編集済み: Az 2023 年 10 月 24 日
How to find a largest rectangular object in binary image. Any connected object should be ignored. The object should have a minimum length of 50 pixels and minimum width of 4 pixels. The examples images are attached.
Thanks
  6 件のコメント
Az
Az 2023 年 10 月 24 日
編集済み: Az 2023 年 10 月 24 日
Both regionprops(BoundingBox) as well as Bwareafilt results in selecting a biggest object.
I want to to find:
biggest rectangular region
Shorter side at least 3 (horizontal or vertical)
Longer side at least 50 (horizontal or vertical)
The region can also be a part of an object (the parts of the object not contributing to the rectangle should be ignored)
Walter Roberson
Walter Roberson 2023 年 10 月 24 日
When you indicated earlier that "Any connected object should be ignored" my understanding was that if you had rectangles that were connected to any other shape, that the entire blob should be ignored . That is why I coded regionprops to compare the convex area to the image area: those two values are only equal for blobs that are rectangles.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 10 月 22 日
P = regionprops(YourBinaryImage, 'Area', 'ConvexArea', 'BoundingBox');
PA = vertcat(P.Area);
PCA = vertcat(P.ConvexArea);
PBB = vertcat(P.BoundingBox);
PW = PBB(:,3);
PH = PBB(:,4);
mask = PA == PCA & PH >= 50 & PW >= 4;
selected_P = P(mask);
[largest_object_area, idx] = max([selected_P.Area]);
largest_BB = selected_P(idx).BoundingBox;
Note that here I am interpreting "width" as horizontal extent, and then by default that means "length" in your question must refer to vertical extent.

Community Treasure Hunt

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

Start Hunting!

Translated by