简体   繁体   中英

Matlab: How to convert image coordinate to array indices

I have a GUI which display 2D image. However, I am not able to recover data accurately by using mouse coordinates. This is because I am not able to convert image coordinates to array indices properly.

I use ginput to get mouse coordinates.

Any help would be appreciated. Regards Dushyant

When displaying an image in matlab, your origin(for image) sits at top left corner of the image, x-axis increase towards downwards and y-axis increase towards right, while with mouse you get co-ordinates with x-axis increasing towards right and y-axis towards up(so a rotation of +90 degrees with respect to image co-ordinates plus a translation),,, so you have to transform one of your co-ordinates to the other to get the right values, for example if your origin of figure window is at top left corner and image spans the whole frame then,,,

x_image = -y_mouse and
y_image = x_mouse.

Try that:

fig=figure, imshow(myfigure);
[x, y] = getpts(fig);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM