# Best way to resample a signal (image)?

I have an original image $\ I(x_i,y_j)$ where

$\ x_i = i*\Delta x, 0<= i < n_i$

and

$\ y_j = j*\Delta y, 0<= j < n_j$

I am trying to implement a function that resamples the image to:

$\ I(x_k,y_l)$ where

$\ x_k = k*\Delta xx, 0<= k < n_k$

and

$\ y_l = l*\Delta yy, 0<= l < n_l$

The case when $\ \Delta xx <= \Delta x$ and $\ \Delta yy <= \Delta y$ : upsampling, is quite easy (?).

Linear interpolation between nearest neighbours should do a decent job?

Downsampling on the other hand is more tricky.

To make sure Nyquist is followed so that no aliasing occurs; I must lowpass filter before decimating.

How do I do this an good yet simple manner?

I was thinking maybe using the FFT to do both upsampling and downsampling:

1. take the FFT of the image
2. zero pad or truncate the FFT
3. inverse FFT

In the case of zero padding this amount to sinc interpolation (which is better than linear interpolation)?

In the case of truncation this amount to (ideal) lowpass filtering?

So this should be a both simple to implement and very good solution?

I guess one thing to look out for is edge effects.

How do I best avoid this?

I was thinking repeating the image twice in x and y and then circulary shifting it half the width and height of the image. That should make the padded image cyclical periodic.

• Why not to just use Gaussian blur? Or you can compute weighted sum around sampled pixel instead of blurring+sampling. – Libor Oct 30 '12 at 16:27
• Thanks Libor! Gaussian blur is simple to implement but how do I decide the size of the kernel? – Andy Oct 30 '12 at 16:32
• The larger the kernel, the more accurate the filter. I've seen a suggestion of $\lceil 3\sigma \rceil$ where $\sigma$ is proportional to scale factor, maybe you can use $\sigma=\sqrt{t}$ where $t$ is the scale factor. See Scale space article for more information. – Libor Oct 30 '12 at 18:57

You could also just do a FIR filter. If you upsample by a ratio of $\frac{p}{q}$ then you would want your anti-aliasing filter to have a normalized bandwidth of $\frac{q}{p}$. You could make the bandwidth a little smaller to get rid of more alias energy, as desired. If you downsample by a ratio of $\frac{p}{q}$ then you would want the filter bandwidth to also be about $\frac{p}{q}$. Again, you could make it a little smaller to get rid of more alias energy.
• If your FFT is $N$ samples long and you're resampling by a ratio of $\frac{p}{q}$, $N$ must be a multiple of $q$ because you want to end up with $\frac{Np}{q}$ samples. If $q$ doesn't divide evenly into $N$, then you will need to produce a "fractional sample", which is impossible. – Jim Clay Oct 31 '12 at 12:37