Why does an affine translation before and after a rotation shift the image incorrectly?

224 Views Asked by At

Given an image I of four pixels:

I = [[0, 0], [1, 0],
     [0, 1], [1, 1]]

Translate so that origin is at the centre of the image (subtract -1 from x and y):

I = [[-1, -1], [0, -1],
     [-1, 0], [0, 0]]

Rotate the image by 90 degrees:

I = [[-1, 1], [-1, 0],
     [0, 1], [0, 0]]

Translate back (by adding back 1):

I = [[0, 2], [0, 1],
     [1, 2], [1, 1]]

Note that all Y points are shifted up by 1. The image should instead be:

I = [[0, 1], [0, 0],
     [1, 1], [1, 0]]

Is there a reason this is happening? I am unable to rotate images about their centre without incuring this shift in the y direction. Is it something wrong with the translations? I've spent considerable time on this, and I am unsure of what I am doing wrong.

Edit it appears the amount I was translating by was incorrect, it should be 0.5:

enter image description here

enter image description here

enter image description here