MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   Matlab调整坐标 (https://www.labfans.com/bbs/showthread.php?t=23719)

poster 2019-12-10 20:48

Matlab调整坐标
 
我有大小为600 * 600的图像,并在800 * 800像素的屏幕上显示。用户在屏幕上看到的x,y坐标记录在一个数组中:

x =[250,300,390,750,760]; y =[120,550,250,130,420]; 在其他程序中,我想在600 * 600图像上绘制x,y坐标。问题在于某些x,y图不在图像中( [B]如下图所示[/B] ),因为坐标大于图像的最大尺寸(600 * 600)。

编辑:如何将较大图像(800 * 800)的坐标转换/调整为较小图像(600 * 600),以便所有x,y坐标都[B]在[/B]较小图像(600 * 600)内?

例如,假设800 * 800图像的图像内600 * 600左上图像的坐标为x = -10,y = 3。

谢谢。

[URL="http://img9.imageshack.us/img9/8836/e47184420f.jpg"]替代文字http://img9.imageshack.us/img9/8836/e47184420f.jpg[/URL]



[B]回答:[/B]

要获取图像坐标中的像素,您需要知道图像在屏幕左下角和右上角的位置。据此,您可以计算图像的偏移量和缩放比例。

%# define some parameters imageSize = [600 600]; topLeftPixScreen = [200,100]; %# position of the top left image corner in screen pixels bottomRightPixScreen = [800,750]; %# position of the bottom right image corner in screen pixels %# transform coordinates oldX =[250,300,390,750]; oldY =[120,550,250,130,420]; newX = (oldX - topLeftPixScreen(1))/(bottomRightPixScreen(1) - topLeftPixScreen(1) + 1); newY = (oldY - topLeftPixScreen(2))/(bottomRightPixScreen(2) - topLeftPixScreen(2) + 1); 话虽如此,我建议使用[URL="http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ginput.html"]ginput[/URL]通过Matlab选择点,因为该函数直接返回图像像素。

[B]编辑[/B]

如果只有左上角,则必须希望没有任何缩放比例-否则,将无法变换这些点。

仅使用偏移量,以上简化为

%#定义一些参数imageSize = [600 600]; topLeftPixScreen = [200,100];屏幕左上角图像的左上角%#位置

%# transform coordinates oldX =[250,300,390,750]; oldY =[120,550,250,130,420]; newX = oldX - topLeftPixScreen(1); newY = oldY - topLeftPixScreen(2);

[url=https://stackoverflow.com/questions/3288982]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:04

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.