在二进制图像MATLAB中标记对象

时间:2014-03-24 19:28:48

标签: matlab image-processing binary label bounding-box

我正在尝试使用MATLAB在二进制图像中标记白色对象。基本上,我的目标是在空中地图图像中检测水体,然后将cimage转换为二进制,然后标记物体。这是检测到主体并转换为二进制后输出的图像示例。我现在怎样才能在白色物体周围创建一个创建矩形并用文本标记它们(使用连接的组件)?谢谢!

enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个 -

%%// Read in the image file
img = im2bw(imread(FILE));

%%// Get bounding box stats
stats = regionprops(bwlabel(img),'Area','Centroid','Perimeter','BoundingBox');
Boxes=cat(1,stats.BoundingBox);

%%// Placeholder to store the final result
maskm = false(size(img,1),size(img,2));

for k1 = 1:size(Boxes,1)

    %%// Initialize a mask representing each bounding box
    mask1 = false(size(img,1),size(img,2));

    %%// Get the coordinates of the boxes
    starty = round(Boxes(k1,1));
    stopy = starty+round(Boxes(k1,3))-1;
    startx = round(Boxes(k1,2));
    stopx = startx+round(Boxes(k1,4))-1;

    %%// Finaly create the mask
    mask1(startx:stopx,starty:stopy) = true;
    maskm = maskm + imdilate(edge(mask1,'sobel'),strel('disk',2));
end

%%// Get the boxes around the original blobs
maskm = maskm + img;
figure,imshow(maskm);

<强>输出

enter image description here

查看text如何标记方框。