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< /a>
I have image which size was 600 * 600 and it was displayed on 800 * 800 pixel screen.
The x,y coordinate in which the user look on screen was recorded in an array:
x =[250,300,390,750,760];
y =[120,550,250,130,420];
In other program, I want to plot the x,y coordinate on the 600 * 600 image. The problem is that some of the x,y plot were out of the image (as shown on the picture below) since the coordinate was more that the maximum size of the image (600 * 600).
EDITED:
How to transform/adjust the coordinate of the bigger image (800*800) into the smaller image (600*600) so all x,y coordinate are inside the smaller image (600*600)?
Lets say for example, the coordinate of top left image of the 600*600 inside the image of the 800*800 image is e.g. x = -10, y = 3.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获取图像坐标中的像素,您需要知道图像的左下角和右上角在屏幕上的位置。由此您可以计算图像的偏移和缩放。
话虽如此,我建议使用 ginput使用Matlab选择点,因为该函数直接返回图像像素。
编辑
如果你只有左上角,你必须希望没有任何缩放 - 否则,你无法变换这些点。
仅使用偏移量,上面的内容简化为
%# 定义一些参数
图像大小 = [600 600];
左上像素屏幕 = [200,100]; %# 图像左上角的位置(以屏幕像素为单位)
To get the pixels in image coordinates, you need to know where the bottom left and top right corners of your image were placed on the screen. From that you can both calculate offset and zoom of the image.
Having said that, I'd suggest using ginput to select the points with Matlab, since this function directly returns image pixels.
EDIT
If you only have the top left corner, you have to hope that there has not been any scaling - otherwise, there is no way you can transform the points.
With offset only, the above simplifies to
%# define some parameters
imageSize = [600 600];
topLeftPixScreen = [200,100]; %# position of the top left image corner in screen pixels
看来只需按屏幕面积和图像大小的比例调整坐标即可:
It seems that just adjusting the coordinates by the ratio of the screen area and image size would do: