How can I read an image from a file into two vectors?
1 view (last 30 days)
Show older comments
I would like to read a black and white image from a file. For this, I use A = imread('img.jpg'); And then I would like to put the coordinates of the black parts of the image into x and y vectors, so that I would be able to use plot(x,y,'.b'). And I do not want to use imshow. Thank you very much.
2 Comments
Image Analyst
on 25 Jun 2015
Post your image. If you have a lot of black pixels, then your plot will look like a mess and there is no reason to plot it. Just say what you really want to do, and I don't think plotting should really be part of it.
Accepted Answer
Jan
on 25 Jun 2015
Edited: Jan
on 25 Jun 2015
This is possible by a simple find command:
if ndims(A) == 2 % grayscale image
[x,y] = find(A == 0);
else
[x,y] = find(~any(A, 3));
end
2 Comments
Image Analyst
on 25 Jun 2015
Be careful - you're using "reverse" definitions of x and y. Your x is rows (vertical) rather than the customary horizontal columns coordinate. I'd recommend one of these
[rows, columns] = find(A == 0);
[y, x] = find(A == 0);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!