Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 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图不在图像中( 如下图所示 ),因为坐标大于图像的最大尺寸(600 * 600)。

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

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

谢谢。

替代文字http://img9.imageshack.us/img9/8836/e47184420f.jpg



回答:

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

%# 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); 话虽如此,我建议使用ginput通过Matlab选择点,因为该函数直接返回图像像素。

编辑

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

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

%#定义一些参数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);

更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 21:18


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