finding first and second maximum in an image/matrix

Hello,
I have a 360x180 matrix. It has the normalised energy values in dB representing the beam pattern of microphone array in (1:360)° azimuth versus (1:180)° elevation angles.
When I plot it as imagesc(), I have a mainlobe at certain azimuth and elevation surrounded by few sidelobes.
Now I want to find the ratio of maximum sidelobe to the mainlobe. How can I do it?
Please help.

Answers (1)

Since your peaks probably have some width to them you can't simply sort the values and find the greatest. You also probably can't just threshold the image since the separate peaks may have different heights. Therefore I recommend using imregionalmax() in the Image Processing Toolbox. Then you can binarize the image and label it and call regionprops. For each peak you can get the max. (Actually you can get that without even calling regionprops.) But you probably need regionprops to find the centroids of all the peaks so you can determine which blobs are main peaks and which blobs are sidelobes of that main peak (say, the side lobe centroids are within a certain distance of the centroid of the larger main peak). Upload your image to tinypic.com if you need any help. It can get a little tricky if you have multiple clusters of peaks & side lobes and all those have different heights

15 Comments

I understand your solution Sir. But unfortunately Iam not familiar with IPT. I deal mostly with Signal Processing. But this particular operation needs IPT.
In which format (.fig or .jpg) should I upload my plot[obtained via imagesc()] to tinypic.com?
Please guide me.
Upload a standard image file. It can be your image (that's best) or if you can't do that (use imwrite, that is), you can capture a screenshot and save that and upload the screenshot. Don't upload the fig file itself.
done. Here is the link:
http://i41.tinypic.com/11cd3dh.jpg
Note: This is not always the case. For different angles, I get different beam patterns(different locations of mainlobes and sidelobes). So, I need to find the ratio (max. sidelobe to mainlobe) for all the angles (360*180=64800) and plot them (azimuth vs elevation) to view at which range of angles the sidelobe is more dominant.
I see a bunch of peaks but I'm not sure which are sidelobes and which are main peaks. Once you identify the value of the main peak, it sounds like you can just divide that number by the image to get the ratio of that to the value of all the other pixels in the image.
The mainlobe is at (x,y)=(-20°,50°) [red spot with maximum intensity] and is surrounded by 6 dominant sidelobes (4 sidelobes on top of it,1 at top right and the other at bottom left of the image).
Out of these 6 dominant sidelobes, the one at (-70°,130°) seems to be the maximum sidelobe(i.e. higher the red intensity, stronger is the peak).
So, I need to find the ratio of this sidelobe at (-70°,130) to the mainlobe at (-20°,50°).
Did you try max(imageArray(:)) ./ imageArray like I suggested? That will give you the ratio everywhere.
Its not helping. first I need to find the location of 2nd maximum peak. And then find its location(elevation,azimuth).
How can I do it on my matrix (360x180)?
What are you doing first? Isn't the location it's elevation and azimuth, which you say you're doing second? It seems to me that if you find the location you find the elevation and azimuth so they're the same thing, not two separate things.
This would be SO much easier if you had the Image Processing Toolbox. Are you sure you don't want to obtain that? It's really hard to find two dimensional peaks if you can't use imregionalmax. You could maybe try region growing, the CLEAN algorithm, or something else to sequentially remove peaks, but it's harder than a one-liner call to imregionalmax()..
Sir, I have my matrix H(360x180).
I have used imregionalmax() of IPT as >>P=imregionalmax(H);
I got a binary matrix P with 1's representing the peaks. Now what am I suppose to do? How can I find its true value of dominant sidelobe from matrix H?
Please guide.
Call regionprops on P to find the PixelIdxList of each blob. Then find the max intensity of each blob. Then find the max of those blobs (the brightest blob's intensity). Then take the ratios of the dimmer blobs to the brightest blob. That's pretty much it. Let me know if you still need more help.
Post your original grayscale image (not the fig file, or the pseudocolored version or a screenshot, but the original image) to tinypic.com, and I'll see what I can do. You can look at my BlobsDemo if you want an example of how to find centroids. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
G=regionprops(P,'PixelIdxLis');
So, in 'G' I have a column matrix with 10 rows containing <1x1 struct>.
When I go inside each of them, I see the following, for example:
Field Value Min Max
PixelIdxList 37408 37408 37408
Every <1x1 struct> has different values (same min and max) as above ranging from 13333 to 47725.
How can I find the MaxIntensity? I have read matlab doc help but Iam unable to use it on struct().
Also, I would like to add that I need to only sort out the maximum and second maximum blobs from the above 10 structs. and find their ratio. All blobs which are dimmer than second maximum blob are not needed.
Also, I think I need to process the matrix H(360x180) itself instead of images. Since I need to loop this process around to find the above ratio for all 64800 angles(meaning 68400 images!!) and plot them together using imagesc() or surf().
Please guide.
I have done the following:
peaks=imregionalmax(H); %H is 360x180 matrix
G=regionprops(peaks,'PixelIdxLis');
figure
imagesc(ele,azi,peaks); % view max. peaks
r=struct2cell(G);
O=cell2mat(r);
v=O(end-1)./O(end);
Finally I have ratio of 2nd max to max peaks stored in v in conjecture with second sidelobe to mainlobe of beampattern.
Isit sufficient? Or do I have to find Intensities at each peak?

Sign in to comment.

Asked:

on 28 Jan 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!