2010-05-06 146 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')