What is the scale of translation in affine_grid

pgp: <p>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. <a href="https://github.com/prameshgautam/recreate_affine_error/blob/master/affine_2d_pytorch.ipynb" rel="noopener nofollow ugc">notebook</a> to recreate the error.</p>
<p>Thanks in advance!</p>

ivan-jgr: <p>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).</p>
<p>So if you want to translate <code>x</code> pixels you should out <code>x / 128</code> for 128 x 128 images in your case.</p>
<p>Cheers.</p>

pgp: <p>Thank you <a class="mention" href="/u/ivan-jgr">@ivan-jgr</a>. 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?</p>

ivan-jgr: <p>I see, you’re right.</p>
<p>Note that in the height in [-1, 1] is to, so if you want to move 20 pixels in y position you should take<br>
<code>2*(y/128)</code><br>
This works for me (note where is the red line in the first image)<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/c/ac6caaf75b4e943c1ebdf8ca0b84da01c402c837.png" data-download-href="https://discuss.pytorch.org/uploads/default/ac6caaf75b4e943c1ebdf8ca0b84da01c402c837" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/a/c/ac6caaf75b4e943c1ebdf8ca0b84da01c402c837_2_484x500.png" alt="image" data-base62-sha1="oBkWzmDEDsIsDXJyYKlz3YTRZIj" width="484" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/a/c/ac6caaf75b4e943c1ebdf8ca0b84da01c402c837_2_484x500.png, https://discuss.pytorch.org/uploads/default/original/3X/a/c/ac6caaf75b4e943c1ebdf8ca0b84da01c402c837.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/a/c/ac6caaf75b4e943c1ebdf8ca0b84da01c402c837.png 2x" data-dominant-color="E2E1E1"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">709×732 46.3 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>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.</p>

pgp: <p>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?</p>

ivan-jgr: <p>yes I think that rotation, reflection, scale and shear work fine without scale modifications in the matrix.</p>
<p>Cheers,<br>
Iván.</p>