Drawing 4-sided polygons around objects

3 ビュー (過去 30 日間)
Mohammad Abu-Haifa
Mohammad Abu-Haifa 2020 年 10 月 28 日
コメント済み: Mohammad Abu-Haifa 2020 年 10 月 28 日
Hello
I wrote a code to approximate each brick in this image into rectangles. However, some bricks in other images can't be approximated into rectangles due to the irregular shape
So, I need to draw a 4-sided polygon around each brick. Can any one help me?
Here is the rectangle's code:
clc; clear; close;
I = imread ('1.png');
figure, imshow(I);
IBW = imbinarize(rgb2gray(I));
[L, num ] = bwlabel(IBW);
bboxes = regionprops(L, 'BoundingBox');
figure, imshow(IBW);
hold on
for k=1 : length(bboxes)
curbb = bboxes(k). BoundingBox;
rectangle ('Position',[curbb(1),curbb(2),curbb(3),curbb(4)], 'EdgeColor','g', 'LineWidth', 1)
end
hold off

回答 (1 件)

Matt J
Matt J 2020 年 10 月 28 日
This will help to find the corners of the boxes.
Use the line() command instead of rectangle() to draw general quadrilaterals.
  2 件のコメント
Mohammad Abu-Haifa
Mohammad Abu-Haifa 2020 年 10 月 28 日
There is an error appers (Unrecognized function or variable 'pgonCorners').
Mohammad Abu-Haifa
Mohammad Abu-Haifa 2020 年 10 月 28 日
can you please write the final code based on the information presented in my code in the question?

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

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by