我创建了一个matlab代码,用于计算图像中所有矩形的长度和宽度 结果出现在命令窗口中。
但是我希望结果应该出现在图像本身中,每个矩形旁边都有长度和宽度。
我的代码是
I = imread('F:\h.png');
info = imfinfo('F:\h.png');
I1 = ~im2bw(I);
I2 = bwlabel(I1);
S = regionprops(I2, {'BoundingBox'});
[m,n] = size(S);
for a=1:m
for b=1:n
width = S(a,b).BoundingBox(3);
height = S(a,b).BoundingBox(4);
if width==height
display('square');
else
display('rectangle');
end
display(width);
display(height);
pause(2)
end
end
答案 0 :(得分:0)
答案 1 :(得分:0)
I = imread('F:\h.png');
info = imfinfo('F:\h.png');
I1 = ~im2bw(I);
I2 = bwlabel(I1);
S = regionprops(I2, {'BoundingBox'});
[m,n] = size(S);
for a=1:m
for b=1:n
width = S(a,b).BoundingBox(3);
height = S(a,b).BoundingBox(4);
if width==height
display('square');
text(S(a,b).Centroid, 'square')
else
display('rectangle');
text(S(a,b).Centroid, 'rectangle')
end
display(width);
display(height);
pause(2)
end
end