maxIntensity of image/matrix and ratio

I have a matrix H(360x180). My final goal is to find the ratio of second max peak to max peak in the matrix.
I have done the following:
peaks=imregionalmax(H);
[label n]=bwlabel(peaks);
peaks = imdilate(peaks,strel('disk',1));
G=regionprops(label,'PixelIdxList');
I have G < 15x1 struct > How can I find the max intesity from each field in G, and take the ratio of second max intesity to max intensity from the set of all maximums/peaks?
Please help.

 Accepted Answer

You need to put into a loop from 1 to n and get the max value for each region, something like (untested)
for blob = 1 : n
% Get pixel intensities of this particular blob.
thisBlob = H(G(blob).PixelIdxList);
% Find the max intensity out of those pixel intensities.
maxForThisBlob(blob) = max(thisBlob(:));
end
% Sort them in descending order.
sortedMaxes = sort(maxForThisBlob, 'descend');
% Get ratios of all peaks heights to the first peak height.
ratios = sortedMaxes / sortedMaxes(1);
That's just off the top of my head. If it doesn't work and you can't figure it out, write back.

3 Comments

Note: the arrayfun() in my answer does the same thing as I.A.'s loop.
thank you @image analyst and @walter.
I have 1 more query.
In matrix H, I have the values in dB scale with maximum (main lobe) at 0dB. I need to find the 3dB beamwidth of mainlobe(in degrees across elevation and azimuth).
How can I do it? any function or short syntax shall be helpful.
@image analyst: got it Sir.

Sign in to comment.

More Answers (1)

firstmax = arrayfun( @(S) max(H(S.PixelIdxList)), G);
Second max depends on how you want to handle the possibility of duplicate values. If two locations have the same intensity, are those the first and second max? Or should the second max be the next unique value down?
almostlast = @(V) V(end-1);
secondmax = arrayfun( @(S) almostlast(unique(H(S.PixelIdList))), G);

5 Comments

I am not sure now that I understood the second max properly.
Perhaps it should be
t = unique(firstmax);
ratio = double(t(end-1)) ./ double(t(end));
It might help if you remembered his image he first posted in his near-duplicate post: http://www.mathworks.com/matlabcentral/answers/27332-finding-first-and-second-maximum-in-an-image-matrix There's some context that's missing from this post since he didn't post the image.
The image: http://i41.tinypic.com/11cd3dh.jpg
thank you Sir.
Also, how can I plot the blobs onto my imagesc() plot (by holding it on) to view them simultaneously?
Atleast I want to label the blobs with their respective PixelIdxList or intensity so that I see which blob has max. intensity and which has second max and so on in a figure/plot?
PS: I deal with matrix H but not images. I generate plot using imagesc() from H, just to view the beam-pattern (maximas and minimas).
Please help.
G = regionprops(label,'PixelIdxList','Centroid','MaxIntensity');
numblobs = length(G);
sortedMaxes = sort([G.MaxIntensity], 'descend');
ratio = double(sortedMaxes(2)) ./ double(sortedMaxes(1));
Hc = zeros(size(H));
cents = zeros(numblobs,3);
for K = 1 : numblobs
cents(K,:) = [G(K).Centroid, G(K).MaxIntensity];
thesepixels = G(K).PixelIDList;
Hc(thesepixels) = H(thesepixels);
end
imagesc(Hc);
for K = 1 : numblobs
text(cents(K,1), cents(K,2), num2str(cents(K,3)))
end
But perhaps I did not understand what you meant about plotting the blobs on your imagesc() plot. If you have an existing image and want to draw a border around each blobs, then matters get a bit more complicated in order to trace the boundary... and I think it is about time to head home for supper.
got it done..thanx @Walter

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!