首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >二值图像MATLAB中的标记对象

二值图像MATLAB中的标记对象
EN

Stack Overflow用户
提问于 2014-03-24 19:28:47
回答 1查看 3.6K关注 0票数 1

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-24 19:54:37

试试这个-

代码语言:javascript
复制
%%// 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);

输出

查看如何为这些框贴上标签的文本

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22618824

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档