Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我有大小为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); 更多&回答... |
![]() |
![]() |