更新时间:2021-09-01 01:26:45
还有其他两种简单的方法可以实现2D峰查找器: imdilate
.
There are a couple of other easy ways to implement a 2D peak finder: ordfilt2
or imdilate
.
最直接的方法是使用ordfilt2
,它对本地邻域中的值进行排序并选择第n个值. ( MathWorks示例演示了如何实现最大过滤器).您还可以使用ordfilt2
来实现3x3峰值查找器,方法是:(1)使用不包括中心像素的3x3域,(2)选择最大的(第8个)值,然后( 3)与中心值比较:
The most direct method is to use ordfilt2
, which sorts values in local neighborhoods and picks the n-th value. (The MathWorks example demonstrates how to implemented a max filter.) You can also implement a 3x3 peak finder with ordfilt2
by, (1) using a 3x3 domain that does not include the center pixel, (2) selecting the largest (8th) value and (3) comparing to the center value:
>> mask = ones(3); mask(5) = 0 % 3x3 max
mask =
1 1 1
1 0 1
1 1 1
此掩码中考虑了8个值,因此第8个值是最大值.过滤器输出:
There are 8 values considered in this mask, so the 8-th value is the max. The filter output:
>> B = ordfilt2(A,8,mask)
B =
3 3 3 3 3 4 4 4
3 5 5 5 4 4 4 4
3 5 3 5 4 4 4 4
3 5 5 5 4 6 6 6
3 3 3 3 4 6 4 6
1 1 1 1 4 6 6 6
技巧是将其与每个邻域的中心值A
进行比较:
The trick is compare this to A
, the center value of each neighborhood:
>> peaks = A > B
peaks =
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0
imdilate
图像膨胀通常在二进制图像上完成,但是灰度图像膨胀只是一个最大滤镜(请参见). ordfilt2
使用的相同技巧也适用于此:定义不包含中心邻域像素的邻域,应用滤镜并将其与未滤镜的图像进行比较:
imdilate
Image dilation is usually done on binary images, but grayscale image dilation is simply a max filter (see Definitions section of imdilate
docs). The same trick used with ordfilt2
applies here: define a neighborhood that does not include the center neighborhood pixel, apply the filter and compare to the unfiltered image:
B = imdilate(A, mask);
peaks = A > B;
注意:这些方法只能找到一个像素峰值.如果任何一个邻居的值相同,那么它就不会是峰值.
NOTE: These methods only find a single pixel peak. If any neighbors have the same value, it will not be a peak.