## Matlab

Moderators: None (Apply to moderate this forum)
Number of threads: 1494
Number of posts: 2174

This Forum Only

Image coordinates problem Posted by lee_mylo on 8 Apr 2009 at 3:06 AM
Hi to all!

I have written these lines to calculate the maximum intensity of an image from the histogram h

i = find(h);
iend = i(end);
max1 = max(h(50:iend));

How can I calculate the x,y of the image where the intensity equals the maximum intensity?

Thank you in advance!
Re: Image coordinates problem Posted by giug on 8 Apr 2009 at 3:10 AM
[x y]=find(Image==max1);

But... why do you search the maximum intensity form the histogram and not directly from the image? Like:

max1=max(Image(:));
Re: Image coordinates problem Posted by lee_mylo on 8 Apr 2009 at 3:27 AM
thank you for your quick response!
I have tried it but it returns many values for x,y whereas I want only the value where the intensity equals the maximum intensity.With the histogram I can check the bin where the maximum is.
Re: Image coordinates problem Posted by giug on 8 Apr 2009 at 3:43 AM
The problem is that your code doesn't find the maximum intensity of your image but the maximum of the histogram. So max1 is the heigth of the bin and so it corresponds to the number of the most frequent intensity values.

If you want the maximum intensity the code is this:

max_int=max(Image(:))

And if you want the x y positions of the pixels with the maximum intensities:

[x y]= find(Image==max_int)

if the outputs are two vectors it means that there are more than one pixel with the maximum intensity in the image.
Re: Image coordinates problem Posted by lee_mylo on 8 Apr 2009 at 3:57 AM
thank you!so if I want a line to pass through x,y where the intensity is maximum how can I write it? I have written the code below as an example and I want x to take the value of the maximum x but also be in the range 1 to 256

b=50;
for a = -50:50
for x = ?
y(a,x) = a*x + b
end
end

Re: Image coordinates problem Posted by giug on 8 Apr 2009 at 5:44 AM
There is a problem. I try to explain:
through the point x,y pass infinite rows. If you want to leave a as a parameter, you have to force a contition to b, and this condition depends on the fact that the rows have to pass through the point x,y.
For example, the first row has to pass to x,y and has a=50. x,y are fixed, so you have to compute b as:
b = y-a*x

THEN you can find the line whith x=1:256.

Do you understand?
Re: Image coordinates problem Posted by lee_mylo on 8 Apr 2009 at 5:54 AM
yes thank you!

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic