Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Finding peak value in 2d array (image)

1,879 views
Skip to first unread message

Gregory

unread,
Nov 23, 2009, 10:30:20 AM11/23/09
to
I'm new to Matlab...
I need to find the peak value stored in a 2d array which is actually an image (640x480). I need to know the row,column, and pixel value of the peak. Ideally I'd like something along the lines of [r,c,p] = findPeak(I).
I've been stumbling around trying to find a solution to what I know is probably a trivial problem. I thought max might do the trick, but I've not been successful.
Thanks

Carlos Adrian Vargas Aguilera

unread,
Nov 23, 2009, 10:55:19 AM11/23/09
to

Bruno Luong

unread,
Nov 23, 2009, 11:48:05 AM11/23/09
to
If you need faster code, you might be interested in using a min/max filter on FEX (mex installation required).

z = peaks(500);
% on FEX http://www.mathworks.com/matlabcentral/fileexchange/24705
maxz = minmaxfilt(z,[],'max','same');
[i j] = find(maxz==z);

% Check
surf(z);
hold on;
zmax = z(sub2ind(size(z),i,j));
plot3(j,i,zmax,'vr','MarkerSize',20);

Bruno

ImageAnalyst

unread,
Nov 23, 2009, 2:53:49 PM11/23/09
to
For multiple local 2D max of different values, you can use
imregionalmax() if you have the Image Processing Toolbox. For a
global max, you can use the find() function like Bruno showed you. Or
do something like
[rows cols] = find(imageArray == max(max(imageArray)));

Bruno Luong

unread,
Nov 23, 2009, 2:59:19 PM11/23/09
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <dafe86c7-8e9f-4dc4...@e20g2000vbb.googlegroups.com>...

> For a
> global max, you can use the find() function like Bruno showed you.

Accept that my code looks for all *local* maxima (including a global one).

Bruno

Message has been deleted

nate271...@gmail.com

unread,
Jul 24, 2012, 12:41:43 AM7/24/12
to Gregory
On Monday, November 23, 2009 7:30:20 AM UTC-8, Gregory wrote:
> I&#39;m new to Matlab...
> I need to find the peak value stored in a 2d array which is actually an image (640x480). I need to know the row,column, and pixel value of the peak. Ideally I&#39;d like something along the lines of [r,c,p] = findPeak(I).
> I&#39;ve been stumbling around trying to find a solution to what I know is probably a trivial problem. I thought max might do the trick, but I&#39;ve not been successful.
> Thanks
try this one,
http://www.mathworks.com/matlabcentral/fileexchange/37388-fast-2d-peak-finder

nate271...@gmail.com

unread,
Jul 24, 2012, 12:40:50 AM7/24/12
to Gregory
On Monday, November 23, 2009 7:30:20 AM UTC-8, Gregory wrote:
> I&#39;m new to Matlab...
> I need to find the peak value stored in a 2d array which is actually an image (640x480). I need to know the row,column, and pixel value of the peak. Ideally I&#39;d like something along the lines of [r,c,p] = findPeak(I).
> I&#39;ve been stumbling around trying to find a solution to what I know is probably a trivial problem. I thought max might do the trick, but I&#39;ve not been successful.
> Thanks

you can try this peak finder:
http://www.mathworks.com/matlabcentral/fileexchange/37388-fast-2d-peak-finder
0 new messages