finding coordinates of specific pixel using pixel value ?
Show older comments
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

Accepted Answer
More Answers (1)
Bjorn Gustavsson
on 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 Comments
Walter Roberson
on 29 Aug 2015
No, the value of green is (0,255,0)
find(A(:,:,1)==0&A(:,:,2)==255&A(:,:,3)==0)
Image Analyst
on 29 Aug 2015
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).
Dani
on 4 Sep 2015
Bjorn Gustavsson
on 5 Sep 2015
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
Image Analyst
on 5 Sep 2015
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?
Bjorn Gustavsson
on 7 Sep 2015
You were obviously right, good guessing!
Renuka
on 15 Sep 2017
Edited: Walter Roberson
on 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.
Walter Roberson
on 15 Sep 2017
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) )
Categories
Find more on Read, Write, and Modify Image in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!