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

发布于 2014-03-24 19:54:37
试试这个-
%%// 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);输出

查看如何为这些框贴上标签的文本。
https://stackoverflow.com/questions/22618824
复制相似问题