我使用imtophat
将过滤器应用于m x n
数组。然后我使用imextendedmax()
找到本地最大值。除了在我期待本地最大值的一般区域中的1之外,我到处都是0。但奇怪的是,我不会只获得一个本地最大值。相反,在这些地方,我得到了许多带有1的元素,例如
00011100000
00111111000
00000110000
然而那里的价值接近但不相等所以我希望会有一个高于其他所有的价值。所以我想知道:
答案 0 :(得分:3)
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')