在二进制图像的MATLAB标签对象 [英] Labeling object in a binary image MATLAB

查看:456
本文介绍了在二进制图像的MATLAB标签对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用MATLAB二值图像标记的白色物体。基本上,我的目的是检测在航拍地图图像水体然后转换到的CImage二进制和再标签的尸体。这里是我的输出检测机构和转换为二进制之后的图像例子。我怎么能现在有可能创建一个围绕着白色物体创建矩形,(使用连接组件)的文本标签呢?谢谢!

I am trying to label white objects in a binary image using MATLAB. Basically, my aim is to detect water bodies in a aerial map image and then convert the cimage to binary and then label the bodies. Here is an image example of my output after detecting the bodies and converting to binary. How can I now possibly create a create rectangle around the white objects and label them with text(using connected components)? Thank you!

推荐答案

试试这个 -

%%// 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);

输出

。看看关于如何标记盒文本

Look into text on how to label the boxes.

这篇关于在二进制图像的MATLAB标签对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆