如何选择面积最大的对象? [英] how to select the object with the largest area?

查看:118
本文介绍了如何选择面积最大的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 bwconvhull 来检测图像的某个部分,正如您在图像中看到的那样,有多个具有某些质心的对象。我想要做的是检测具有最大区域的对象(左起第一个大)并忽略其他对象。我应该遵循哪种方法?

I have used bwconvhull to detect a certain part of the image, as you can see in the image there are number of objects with certain centroids. What I want to do is to detect the object with the largest area (1st big one from the left) and neglect the others. Which method should I follow?

我将非常感谢你的帮助。以下是代码(它非常粗略地写好,因为我还在处理它。抱歉给您带来任何不便)

I will will be very thankful for your help. Following is the code (it's very roughly written as i am still working on it. Sorry for any inconvenience in advance)

CH_objects = bwconvhull(c,'objects');
imshow(CH_objects);
title('Objects Convex Hull');
bwarea(CH_objects)
Ilabel = bwlabel(CH_objects,8);
stat = regionprops(Ilabel,'centroid');
imshow(CH_objects);
hold on;
for x = 1:numel(stat)
    plot(stat(x).Centroid(1),stat(x).Centroid(2),'ro');
end

这里是图像。

推荐答案

使用 regionprops中的Area PixelIdxList ,这意味着编辑到以下行:

use Area and PixelIdxList in regionprops, this means to edit the to the following line:

stat = regionprops(Ilabel,'Centroid','Area','PixelIdxList');

最大面积及其结构索引由

The maximum area and it's struct index is given by

[maxValue,index] = max([stat.Area]);

每个区域的像素线性索引由`stat.PixelIdxList'给出,你可以使用它们删除该给定区域(我假设这意味着为它分配零)

The linear index of pixels of each area is given by `stat.PixelIdxList', you can use them to delete that given area (I assume this means to assign zeros to it)

YourImage(stat(index).PixelIdxList)=0;

这篇关于如何选择面积最大的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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