簡體   English   中英

從圖形原點計算圖像的 Y 坐標

[英]Calculate Y coordinates of an image from graph point of origin

在 Matlab 中,圖像軸顯示為行和列(矩陣樣式),它們翻轉/導致 Y 軸從左上角開始。 在下面的腳本中,我使用interparc文件交換鏈接)將輪廓划分為等距離的點。

我希望轉換/調整所選點的計算 Y 坐標,以便它們從“圖形原點”(0,0;左下角)開始,但不翻轉圖像。 知道如何進行坐標轉換嗎?

代碼:

clc;
clear;
close all;

readNumPoints = 8  
numPoints = readNumPoints+1
url='https://icons.iconarchive.com/icons/thesquid.ink/free-flat-sample/512/owl-icon.png';

I = imread(url);
I = rgb2gray(I);
imshow(I);
 
BW = imbinarize(I);
BW = imfill(BW,'holes');
hold on;
[B,L] = bwboundaries(BW,'noholes');

k=1;
stat = regionprops(I,'Centroid');
b = B{k};
c = stat(k).Centroid;
y = b(:,2);
x = b(:,1);

plot(y, x, 'r', 'linewidth', 2);

pt = interparc(numPoints,x,y,'spline');
py = pt(:,2);
px = pt(:,1);
 
sz = 150;
scatter(py,px,sz,'d')
 
str =1:(numPoints-1);
plot(py, px, 'g', 'linewidth', 2);
text(py(1:(numPoints-1))+10,px(1:(numPoints-1))+10,string(str), 'Color', 'b');
pointList = table(py,px)
pointList(end,:) = [] 

您將需要翻轉 y 軸的顯示方向(如評論中建議的 @If_You_Say_So)。

set(gca,'YDir','normal')

Y 軸現在指向上方,但圖像顯示顛倒。 所以我們也翻轉圖像的 y 數據。

I=flipud(I);

圖像被翻轉兩次,因此是直立的。

數據應該在你 plot 之前翻轉或基於它進行任何計算。 當您顯示圖像或 plot 輪廓時,可以稍后翻轉 y 軸的方向。

url='https://icons.iconarchive.com/icons/thesquid.ink/free-flat-sample/512/owl-icon.png';

I = imread(url);
I = rgb2gray(I);

% Flip the data before `imshow`
I=flipud(I);

imshow(I);

% Flip the y-axis display
set(gca,'YDir','normal')
pointList =

  py        px  
______    ______

     1       109
149.02    17.356
362.37     20.77
   512    113.26
413.99    270.84
368.89    505.99
 141.7       508
98.986    266.62

暫無
暫無

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

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