Matlab 调整坐标

发布于 2024-09-10 18:02:20 字数 594 浏览 1 评论 0原文

我的图像尺寸为 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.


alt text http://img9.imageshack.us/img9/8836/e47184420f.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡写薰衣草的香 2024-09-17 18:02:20

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

%# 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选择点,因为该函数直接返回图像像素。


编辑

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

仅使用偏移量,上面的内容简化为

%# 定义一些参数
图像大小 = [600 600];
左上像素屏幕 = [200,100]; %# 图像左上角的位置(以屏幕像素为单位)

%# transform coordinates
oldX =[250,300,390,750];
oldY =[120,550,250,130,420];

newX = oldX - topLeftPixScreen(1);
newY = oldY - topLeftPixScreen(2);

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.

%# 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);

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

%# transform coordinates
oldX =[250,300,390,750];
oldY =[120,550,250,130,420];

newX = oldX - topLeftPixScreen(1);
newY = oldY - topLeftPixScreen(2);
離人涙 2024-09-17 18:02:20

看来只需按屏幕面积和图像大小的比例调整坐标即可:

newX = x.*(600/800)
newY = y.*(600/800)

It seems that just adjusting the coordinates by the ratio of the screen area and image size would do:

newX = x.*(600/800)
newY = y.*(600/800)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文