# How do I resample an image to a rotated grid?

I have an image, I, sampled on a uniform grid:

$\ x_i = i*\Delta x, y_j = j*\Delta y,$

I need to resample this image to a grid rotated counterclockwise by an angle $\ \theta$ around $\ (x_0,y_0)$:

$\ u_i = i*\Delta u, v_j = j*\Delta v$

$\ x(u_i,v_j) = x_0 + cos(\theta)*u_i - v_j*sin(\theta)$

$\ y(u_i,v_j) = y_0 + sin(\theta)*u_i + v_j*cos(\theta)$

How do I best do this?

I understand that I can e.g. do bilinear interpolation to find I from the 4 (x,y) corners around each $\ (u_i,v_j)$.

However I am not free to choose $\ \Delta u$ and $\ \Delta v$ as I wish.

What is the Nyquist criterion for this rotated grid?

Am I right in assuming that it will be?:

$\ \Delta u = cos(\theta)*\Delta x + sin(\theta)*\Delta y$

$\ \Delta v = -sin(\theta)*\Delta x + cos(\theta)*\Delta y$

• Am I correct in thinking that this would be an equivalent operation to image rotation? – Jason R Oct 26 '12 at 12:03

You should read about image transformations. Anyhow, the idea is quite simple:

1. Compute the inverse transform $T(x,y)$.
2. For each point $(x,y)$ on the re-sampled grid:

• Calculate $T(x,y)$, and find the 4 closest points on the original grid.
• Apply interpolation technique (For example, bi-linear) on the neighbors, and put the value in the re-sampled grid.

Some references:

• There's also a nice discussion of 2d interpolation in Numerical Recipes. – nibot Oct 27 '12 at 16:02
• @ Andrey: thank you for your help. You gave me 1/2 of the solution. The other 1/2 consist of deciding the sampling in the rotated coordinate system. – Andy Oct 30 '12 at 12:51
• @Andy, I don't understand. Please elaborate – Andrey Rubshtein Oct 30 '12 at 14:10
• @Andrey: If I choose to large Delta u and Delta v this may cause aliasing. Choosing to small Delta u and Delta v on the other hand is not a problem. The upper limit on Delta u and Delta v is given by Nyquist. – Andy Oct 30 '12 at 14:43