views:

116

answers:

2

I've got a specific question and a related more general one... Why does imextendedmax() not give for example 9 in A(3,3) as a max? Generally... what is the best way for finding multiple maxes/peaks? The nice thing about imextended max is it allows a threshold where presumably everything under that threshold is not counted whereas imregionalmax and findpeaks are more general, less effective.

A=round(rand(5)*10)

A =

 1     5     4     8     3
 5     1     8     8     3
 9     3     9     1     2
 9     7     3     5     9
 6     3     5     6     8

B=imextendedmax(A,8)

B =

 1     1     1     1     1
 1     1     1     1     1
 1     1     1     1     1
 1     1     1     1     1
 1     1     1     1     1
A: 

From what I understand, imextendedmax(A,x) first suppresses all maxima that are x or less above their surroundings, and then it calls imregionalmax.

Thus, you want to call

imextendedmax(A,1)

ans =

     0     0     0     1     0
     0     0     1     1     0
     1     0     1     0     0
     1     0     0     0     1
     0     0     0     0     1

If you want to find all areas that are x or more in an image, you can also just call (for x=8)

x = 8;
A >= x
ans =

         0     0     0     1     0
         0     0     1     1     0
         1     0     1     0     0
         1     0     0     0     1
         0     0     0     0     1

Thus thresholding the image.

In the end it really comes down to what you want to do. If you consider your image as having peaks and valleys, do you want to find the location of the peaks? Then use imdilate for local maximum detection (see below). Do you want to know which parts of the peaks and valleys would stay dry if you fill everything to a level x with water? Then use A>x etc.


EDIT

Apologies about findpeaks. I assumed that you mentioned it because it worked for 2D and I didn't check. For local maximum detection, a very nice way is to use imdilate like this

locMaxMask = A > imdilate(A,[1,1,1;1,0,1;1,1,1]);

The call to imdilate replaces every pixel with the maximum of its surroundings. Thus, the comparison will yield all pixels that have a higher value than the 8 surrounding pixels.

About the noise: There has been a similar question to yours, so I link you to the answer I gave there.

Jonas
A: 

Thanks (sorry I'm posting an answer instead of commenting but I don't see a "comment" option). How do you use findpeaks() with a matrix i.e. 2d data? That is a little unclear to me. Also, I don't see how it will handle noise. Even if you have threshold it seems will still find apparent maxima but which are actually just changes in noise.

yasuhiro89
I have updated my answer. BTW:There should be an 'add comment'-link at the bottom of both your and my question.
Jonas