finding coordinates of specific pixel using pixel value ?

how to get (x,y)coordinates of an image in matlab using pixel value..for example if pixel value is 250 then find the x,y coordinates of all pixel having value 250

Weitere Antworten (1)

Bjorn Gustavsson
Bjorn Gustavsson am 28 Aug. 2015
Try:
help find
Then you should see that
[i1,i2] = find(I==250);
Or if your image is in some double precision format when you cant rely on finding exact equality of pixel values:
[i1,i2] = find(round(scalefactorofyourchoise*(I-250)==0);
HTH

9 Kommentare

Dani
Dani am 29 Aug. 2015
Bearbeitet: Dani am 29 Aug. 2015
image is in .png that means using RGB . i am trying to find xy coordinates of green points. the value of green is exactly 255
No, the value of green is (0,255,0)
find(A(:,:,1)==0&A(:,:,2)==255&A(:,:,3)==0)
Shouldn't you have the coordinates already? I mean, didn't you plot the green dots yourself?
Also be aware that find() returns (row, column) which is (y, x) NOT (x, y).
sorry for late....i plot the green dots by hand in photo shop,,,,I want to use these points in matlab,,,but i don't have these in matlab.
Well, you only need to use Walters comparison to get them:
[i1,i2] = find(A(:,:,1)<=10&A(:,:,2)>=245&A(:,:,3)<=10);
The only thing I changed here was to find all points where the read and blue layers of the image have values lower than 10, and the green layer are above 245. This would possibly give you slightly larger number of identified points. Only you can try this and see what points you'll actually want.
HTH
I think what she wants is not to find the green dots in an image annotated in Photoshop and then saved, but an algorithm to find the eyes and mouth from the original, un-annotated image. Is that correct?
You were obviously right, good guessing!
Renuka
Renuka am 15 Sep. 2017
Bearbeitet: Walter Roberson am 15 Sep. 2017
After doing the above:
[i1,i2] = find(I==250);
How do I get each of the (i1, i2) pair?
I need to set some value for each coordinate obtained from the above finding...
Please reply ASAP.
The K'th pair is I(i1(K), i2(K))
If you need to get all of them at once then easiest is
idx = find(I==250);
I(idx)
using only one index instead of a pair.
If you need the pair of indices for some reason then
[i1,i2] = find(I==250);
I( sub2ind(size(I), i1, i2) )

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Read, Write, and Modify Image finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by