簡體   English   中英

如何在MATLAB中從圖像的一行中提取x和y坐標?

[英]How can I extract x and y coordinates from a line in an image in MATLAB?

我想從這張圖片中提取x和y坐標嗎?

在此處輸入圖片說明

在MATLAB中可以嗎?

您可以通過編程方式執行此操作,因為您要處理的是簡單的線條和干凈的圖像而幾乎沒有噪聲(在這種情況下為灰度強度uint8圖像 )。 這是提取線的方法:

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);

和線:

在此處輸入圖片說明

解決方案可以使用getpts函數。 此功能可幫助您使用鼠標從指定的圖中選擇一些要點。

[x, y] = getpts(fig)

使您可以使用鼠標在無花果的當前軸上選擇一組點。 所選點的坐標以x和y返回。

請參閱本文檔中的更多內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM