从图形原点计算图像的Y坐标 [英] Calculate Y coordinates of an image from graph point of origin
本文介绍了从图形原点计算图像的Y坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Matlab中,图像轴显示为行和列(矩阵样式),它们翻转/使Y轴从左上角开始。在下面的脚本中,我使用interparc
(File Exchange link)将轮廓分割为等距离点。
我希望转换/调整所选点的计算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);
图像翻转了两次,因此是竖直的。
在绘制数据或基于数据进行任何计算之前,应翻转数据。稍后在显示图像或绘制轮廓时,可以翻转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
这篇关于从图形原点计算图像的Y坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文