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

1 次查看(过去 30 天)
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 个评论
Jan
Jan 2015-6-25
Is it a grayscale JPEG or a true-color one? What is the dimension of A?
Image Analyst
Image Analyst 2015-6-25
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.

请先登录,再进行评论。

采纳的回答

Jan
Jan 2015-6-25
编辑:Jan 2015-6-25
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 个评论
Image Analyst
Image Analyst 2015-6-25
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by