0

我创建了一个 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
4

2 回答 2

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
于 2014-09-22T14:11:34.020 回答
0

使用文本(x,y,'字符串')

带引号的字符串到图像上点 (x,y) 指定的位置。

例子 : text(width/2,height/2,'square');

于 2013-08-03T16:36:48.123 回答