如何从 MATLAB 中的图像中的一条直线中提取 x 和 y 坐标?
How can I extract x and y coordinates from a line in an image in MATLAB?
我想从此图像中提取 x 和 y 坐标?
在 MATLAB 中可以吗?
一个解决方案可以使用 getpts
函数。此功能可帮助您使用鼠标从指定的图形中选择一些点。
[x, y] = getpts(fig)
lets you choose a set of points in the current axes of figure fig using the mouse. Coordinates of the selected points are returned in x and y.
更多内容见this documentation。
您可以通过编程方式执行此操作,因为您处理的是一条简单的线条和一张噪点很少的干净图像(在本例中为 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);
还有一行:
我想从此图像中提取 x 和 y 坐标?
在 MATLAB 中可以吗?
一个解决方案可以使用 getpts
函数。此功能可帮助您使用鼠标从指定的图形中选择一些点。
[x, y] = getpts(fig)
lets you choose a set of points in the current axes of figure fig using the mouse. Coordinates of the selected points are returned in x and y.
更多内容见this documentation。
您可以通过编程方式执行此操作,因为您处理的是一条简单的线条和一张噪点很少的干净图像(在本例中为 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);
还有一行: