matlab - how to find local maxima in image -
the question feature detection concept. i'm stuck after finding corner of image , want know how finding feature point within computed corners.
suppose have grayscale image have data this
a = [ 1 1 1 1 1 1 1 1; 1 3 3 3 1 1 4 1; 1 3 5 3 1 4 4 4; 1 3 3 3 1 4 4 4; 1 1 1 1 1 4 6 4; 1 1 1 1 1 4 4 4]
if use
b = imregionalmax(a);
the result this
b = [ 0 0 0 0 0 0 0 0; 0 1 1 1 0 0 1 0; 0 1 1 1 0 1 1 1; 0 1 1 1 0 1 1 1; 0 0 0 0 0 1 1 1; 0 0 0 0 0 1 1 1]
the question how pick highest peak inside max local region (in sample how did chose 5 3 , 6 4)?
my idea using b detect each region , use imregionalmax()
again i'm not @ coding , need advice or other ideas.
there couple of other easy ways implement 2d peak finder: ordfilt2
or imdilate
.
ordfilt2
the direct method use ordfilt2
, sorts values in local neighborhoods , picks n-th value. (the mathworks example demonstrates how implemented max filter.) can implement 3x3 peak finder ordfilt2
by, (1) using 3x3 domain does not include center pixel, (2) selecting largest (8th) value , (3) comparing center value:
>> mask = ones(3); mask(5) = 0 % 3x3 max mask = 1 1 1 1 0 1 1 1 1
there 8 values considered in mask, 8-th value max. 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
the trick compare a
, center value of each neighborhood:
>> peaks = > 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
image dilation done on binary images, grayscale image dilation max filter (see definitions section of imdilate
docs). same trick used ordfilt2
applies here: define neighborhood not include center neighborhood pixel, apply filter , compare unfiltered image:
b = imdilate(a, mask); peaks = > b;
note: these methods find single pixel peak. if neighbors have same value, not peak.
Comments
Post a Comment