我想获取一个RGB图像,找到图像中白色的点,并获取图像中这些点的笛卡尔坐标。我已经完成了大部分工作,但是当我尝试绘制笛卡尔坐标时,会得到一个垂直平铺的图像(即应该看到的5个重叠副本)。有人知道是什么原因造成的吗?
,
代码:(JPG格式为2448 x x3264 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
很简单。您是在声明meshgrid
错误。它应该是:
[x, y] = meshgrid( 1:imageSize(2), 1:imageSize(1) );
第一个参数表示2D网格的水平范围,因此您要使它随您拥有的列数而变化。同样,第二个参数表示2D网格的垂直范围,因此您要尽可能多地使用它。
我必须对您的某些图像进行预处理才能获得良好的效果,因为原始图像的图像周围有大的白色边框。我必须通过删除所有纯白色像素来删除此边框。我还直接从StackOverflow中读取了图像:
I = imread('http://s7.postimg.org/ovb53w4ff/Track_example.jpg');
mask = all(I == 255, 3);
I = bsxfun(@times, I, uint8(~mask));
这是经过预处理后得到的图像:
一旦执行此操作并更改您的meshgrid
电话,就会收到以下消息:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句