How can I read an image from a file into two vectors?

1 view (last 30 days)
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
Jan
Jan on 25 Jun 2015
Is it a grayscale JPEG or a true-color one? What is the dimension of A?
Image Analyst
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.

Sign in to comment.

Accepted Answer

Jan
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
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);

Sign in to comment.

More Answers (0)

Categories

Find more on Images 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!