2011-06-11 29 views
2

我已经标记了一个图像(使用bwlabel),之后,我用regionprops来获得标记对象的偏心率。我现在想要做的是过滤每个标记的对象,其偏心率低于0.5。Matlab - 根据regionprops过滤标记的矩阵

到目前为止,我已经能够使用find来获得符合条件的区域的数量,但我不知道如何使用它们来过滤原始标记的图像。

例如:

labeledImage = bwlabel(originalImage); 
properties = regionprops(labeledImage, 'eccentricity'); 
eccentricities = cat(1, properties.Eccentricity); 

regions = find(eccentricities > 0.5); 
% now what? 

我试着用for循环来做到这一点,但它是缓慢的地狱,我敢肯定,必须有一个隐藏的MATLAB函数来做到这一点。

回答

4

如果你还在试图解决这个问题,请看下面的例子:

BW = imread('text.png'); 

CC = bwconncomp(BW); 
L = labelmatrix(CC); 

props = regionprops(CC, 'eccentricity'); 
idx = ([props.Eccentricity] > 0.6); 

BW2 = ismember(L,find(idx)); %# filter components with Eccentricity>0.6 
BW3 = ismember(L,find(~idx)); %# filter components with Eccentricity<0.6 

subplot(131), imshow(BW) 
subplot(132), imshow(BW2) 
subplot(133), imshow(BW3) 

enter image description here

0

好吧,看起来功能ismember做了伎俩,但我相信你们知道更好的方法。