From Height to Pixel, mouse coordinates

What are you trying to achieve?:
Translate mouse coordinates from height to pixel.

Description of the problem

I set the size of an image in pixel (550x550).

image_in = new visual.ImageStim({
win : psychoJS.window,
name : ‘image_in’, units : ‘pix’,
image : ‘EmojiGrid_inside.jpg’, mask : undefined,
ori : 0.0, pos : [0, 0], size : [550, 550],
color : new util.Color([1, 1, 1]), opacity : undefined,
flipHoriz : false, flipVert : false,
texRes : 128.0, interpolate : true, depth : -2.0

Participant have to click on the image, and I analyse mouse coordinates.

Mouse coordinates are calculate in heights.

What did you try to make it work?:
I want to calculate the coordinates in relation to the image, thus I want to translate height to pixel coordinates.

I have the screen resolution of each participant, then to convert the height to pixel,
I do :
height.x * (winSize.x/2) and height.y * (winSize.y/2)

Or should I calculate also the ratio (that maybe could differ between screens, eg. 16/10 vs 16/9) or add some other information?

What specifically went wrong when you tried that?:
Sometimes happens that the coordinates are outside the image (eg. +288, when being the image 550x550, its coordinates should be from +250 - 250),
but the output says that participant actually click that image.

How is it possible? Is there a solution for my issue?

Thank you in advance.

Ps. Unfortunately I realised later that I should have set image size differently.

The solution could be: height.x * (winSize.x/4) and height.y * (winSize.y/4) ?

The unit of “height” is calculated based on the height of the monitor. For a standard HD screen (1920×1080 resolution) the “height” value can vary for Y from -0.5 (-1080/2) to +0.5 (+1080/2), when added 1 = 1080. For Y the range is always [-0.5, +0.5], however, for X the “height” range can change depending on the aspect ratio of the monitor. For the example above (1920×1080 = 16:9) the left and right edges are at ±0.888889 (this is 1920/1080/2).

To convert from “height” to pixels you basically just multiply by the height of the window.

1 Like

Thank you!