How do i find the coordinates of point given its intensity ??

16 views (last 30 days)
Hello, I'm working on my senior design project with image processing , but i have an issue that i have an image and i want to find the pixel that have maximum intensity ... i already did that but i don't know how to find the coordinate of this maximum intensity pixel... also is there other way to find pixel that have maximum intensity and its coordinates ??
thanks in advance

Accepted Answer

Rik
Rik on 16 Sep 2018
Edited: Rik on 16 Sep 2018
The second output of max returns a linear index, which you can convert to subscripts with ind2sub.
[maxval,maxind]=max(IM(:));
[r,c]=ind2sub(size(IM),maxind);
You can also use the fact that max normally operates on 1 dimension:
[vec,r_vec]=max(IM,[],1);
[maxval,c]=max(vec,[],2);
r=r_vec(c);

More Answers (1)

Image Analyst
Image Analyst on 16 Sep 2018
Edited: Image Analyst on 16 Sep 2018
Use find(), not max():
v = randi(10, 5, 30) % Create small image.
[maxValue, indexes] = max(v(:)) % Does not show ALL maxima locations.
[rows, columns] = find(v == max(v(:))) % Shows ALL maxima locations.
So, find() works. The horrendous help for max says:
[M,I] = max(_) finds the indices of the maximum values of A and returns them in output vector I, using any of the input arguments in the previous syntaxes. If the maximum value occurs more than once, then max returns the index corresponding to the first occurrence.
So what the first sentence promised, the second sentence takes away. It does not return all maxima locations, only the first one per column.
Alternatively, you can also get the max locations as a binary image
binaryImage = grayImage == max(grayImage(:));

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!