如何选择面积最大的物体? [英] how to select the object with the largest area?
问题描述
我使用了 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.
我应该遵循哪种方法?
我将非常感谢您的帮助.下面是代码(写的很粗略,我还在做,不便之处请见谅)
I will be very thankful for your help. The 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屋!