2010-05-06 144 views
1

我使用imtophat将过滤器应用于m x n阵列。然后我使用imextendedmax()找到本地最大值。除了在我期待的本地最大值的一般区域中的1之外,我大部分都是0。不过,奇怪的是,我不能得到一个本地最大值。相反,在这些地方,我得到许多元素与1的如Matlab中的扩展极大值变换

00011100000 
00111111000 
00000110000 

尚未值有接近但不等于所以我希望会有一个比所有其他的高。所以我想知道:

  1. 如果这是一个错误,我怎么可能会解决它
  2. ,你会如何选择选择这些的1的最高值的元素。

回答

2

a)这是一项功能。您使用两个输入参数调用imextendedmax。第二个输入是衡量不同像素距最大值的距离,并且仍然可以计算扩展最大值。

b)您可以使用组内像素max来选择具有最高值的元素。

%# for testing, create a mask with two groups and an image of corresponding size 
msk = repmat([00011100000;... 
00111111000;... 
00000110000],1,2); 

img = rand(size(msk)); 
imSize = size(img); 

%# to find groups of connected ones, apply connected component labeling 
cc = bwconncomp(msk); 

%# loop through all groups and find the location of the maximum intensity pixel 
%# You could do this without loop, but it would be much less readable 
maxCoordList = zeros(cc.NumObjects,2); 
for i = 1:cc.numObjects 
    %# read intensities corresponding to group 
    int = img(cc.PixelIdxList{i}); 

    %# find which pixel is brightest 
    [maxInt,maxIdx] = max(int); 

    %# maxIdx indexes into PixelIdxList, which indexes into the image. 
    %# convert to [x,y] 
    maxCoordList = ind2sub(imSize,cc.PixelIdxList{i}(maxIdx)); 
end 

%# confirm by plotting 
figure 
imshow(img,[]) 
hold on 
plot(maxCoordList(:,2),maxCoordList(:,1),'.r')