如何在MATLAB中从图像中的一行中提取x和y坐标?

时间:2017-11-08 20:40:22

标签: matlab coordinates extract feature-extraction

我想从这张图片中提取x和y坐标?

enter image description here

在MATLAB中可以吗?

2 个答案:

答案 0 :(得分:4)

您可以通过编程方式执行此操作,因为您处理的是简单的线条和干净的图像,噪音很小(在这种情况下为a grayscale intensity uint8 image)。以下是如何提取您的行:

img = imread('1ebO0.png');  % Load image
mask = (img < 128);         % Threshold to get a matrix of 0 and 1 (ones where your
                            % line is, zeroes elsewhere)
[~, index] = max(flipud(mask), [], 1);  % Gives you the index of the first row from
                                        % the bottom of the image where a 1 occurs
x = find(any(mask, 1));  % Find indices of columns that have at least one 1 to get x
y = index(x);            % Trim row indices based on the above to get y
plot(x, y);

这一行:

enter image description here

答案 1 :(得分:0)

解决方案可以使用getpts功能。此功能可帮助您使用指定图中的鼠标选择来获取一些点。

[x, y] = getpts(fig)
  

允许您使用鼠标在图形图的当前轴中选择一组点。所选点的坐标以x和y返回。

this documentation中查看更多内容。