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 个评论
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
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!