我希望能够获取一张RGB图片,在图片中找出白色像素点,并获取这些点在图片中的笛卡尔坐标。我已经完成了大部分工作,但是当我尝试绘制笛卡尔坐标时,我得到的是一个竖向平铺的图像(即重叠了5个正常应该看到的图像)。有人知道可能是什么原因吗?
代码:(JPG格式的输入图片为2448 x 3264 x 3 uint8)
代码:(JPG格式的输入图片为2448 x 3264 x 3 uint8)
I = imread('IMG_0245.JPG');
imshow(I); % display unaltered image
% Convert image to grayscale
I = rgb2gray(I);
% Convert image to binary (black/white)
I = im2bw(I, 0.9);
% Generate cartesian coordinates of image
imageSize = size(I);
[x, y] = meshgrid( 1:imageSize(1), 1:imageSize(2) );
PerspectiveImage = [x(:), y(:), I(:)];
% Get indices of white points only
whiteIndices = find(PerspectiveImage(:,3));
figure; plot( PerspectiveImage(whiteIndices, 1), PerspectiveImage(whiteIndices, 2),'.');
% Flip vertically to correct indexing vs. plotting issue
axis ij
export_fig
工具。这是将图形保存到磁盘的更好方法:http://www.mathworks.com/matlabcentral/fileexchange/23629-export-fig - 我已经使用它多年了! - rayryeng