views:

73

answers:

2

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

A: 

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)
Mau
Thanks you... I just wonder if the image (600*600) was placed not at the centre of the 800*800 image, does it works? e.g. if the 600*600 image was place at the starting point of x,y (200,100) in the 800*800 screen, can we still use the ratio?
Jessy
@Jessy: no, you need to subract the offset. Is that because the points were measured in screen coords and not image coords?
Mau
the image was measure in pixel coordinate of the 800*800.
Jessy
@Jessy: Then scaling should suffice.
Mau
@Mau: Thanks. But it seems the coordinate seems not right when I transferred to 600*600 image.
Jessy
Post an example. Click on pixel 3,3: what do you get?
Mau
@Mau: How can I get the offset?
Jessy
@Jessy: It's the coordinate of the top-left corner of the small image in the big image's coordinates.
Mau
@Mau: that is the coordinate of the small image in the big image.
Jessy
A: 

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);
Jonas
I only knew the top left coordinate of the image (600*600) e.g. x= -10, y=3
Jessy
@Jessy: bottomLeft/topRight assumes that [0,0] is at the bottom left of the screen. Also, do you know whether an image pixel is the same size as a screen pixel, i.e. whether the bottom right of the image would be [589,602]? If the image takes up more (or less) than 600x600 screen pixels, knowing only one corner is not enough information to make the transformation.
Jonas
@Jonas: I wonder if I can use the top left coordinate in which the image (600*600) placed on the screen (800*800) can be used to make the transformation?
Jessy
@Jessy: You can - as long as there has not been any scaling of the image. See my updated answer.
Jonas
@Jonas: Thank you. I have tried to do in that way, however the coordinate seems to out of the boundary of the smaller image.
Jessy
@Jonas: Is there any way that I can separate the smaller image from the bigger image with all the coordinate been normalize according to the smaller image? I really need to separate the smaller image from the bigger image
Jessy
@Jessy: If what you got is the image on the left, you can segment the image, i.e. create a new image that has 1's wherever the image was white, and 0's everywhere else. Then, you can identify the top left/bottom right corners of the white square.
Jonas

related questions