What is the scale of translation in affine_grid

I’ve been using affine grid and grid sample to warp an image. However, when I use the affine matrix only to do the translation, I am not able to figure out the scale it is using. I’ve tried with 0.5 and 1 in both x and y directions. It is not on the basis of pixel count. Also does not look like on the basis of image ratio. notebook to recreate the error.

Thanks in advance!

I thinks that the image is scaled to [-1, 1] x [-1, 1] where (-1, 1) is the (0,0) pixel in the original image and (1, 1) is the (128, 128) pixel (in your case).

So if you want to translate x pixels you should out x / 128 for 128 x 128 images in your case.

Cheers.

Thank you @ivan-jgr. I would like to convert the translation values to the pixel. I’ve updated the notebook with y translation set to 20/128. However, the results do not seem to be correct. It is not translated by2 20 pixels. Also, how would this work for the composite affine matrix that contains rotation, scaling and shearing along with translation?

I see, you’re right.

Note that in the height in [-1, 1] is to, so if you want to move 20 pixels in y position you should take
2*(y/128)
This works for me (note where is the red line in the first image)

And in general for the other related transforms this work in the same way. Keep in mind that the coordinates are scaled to -1 to 1 in the transformation.

great this works. I guess for other transforms we do not need to scale the matrix since they are independent of the scale. Am I right?

yes I think that rotation, reflection, scale and shear work fine without scale modifications in the matrix.

Cheers,
Iván.