6
$\begingroup$

When scaling an image down it is common to first convolve the image with a Gaussian filter. Given a scale factor $0 < s < 1,$ what is an appropriate $\sigma$ to use?

For example, if $s = 0.5$ (halving the width of the image) it seems reasonable to choose $\sigma = 1$ since it will weight a value in the middle by 40%, the two neighbors by 25% each, and their neighbors by 5% each, i.e. 1-D filter looks like this approximately:

 [0.05, 0.25, 0.40, 0.25, 0.05]

This seems reasonable since you will choose every other value when you subsample and the the neighboring values will have about 50% influence.

If $s = 0.25$ (a quarter of the width) it makes sense to use $\sigma = 2$ which yields a 1-D filter that looks like the following (weight 22% for center pixel):

 [0.03, 0.07, 0.13, 0.19, 0.22, 0.19, 0.13, 0.07, 0.03]

Thus the filter's radial influence seems appropriate when choosing every 4th value when downsampling.

So my intuitive rule of thumb is $\sigma = 1/(2s).$

Following this, if $s = 0.75$ then $\sigma = 2/3$ and my filter looks like this

 [0.007, 0.194, 0.598, 0.194, 0.007]

This was purely an intuitive approach to choosing filter parameters. I couldn't find a more theoretical choice (I am sure it will involve Fourier Transforms). What is a good "rule" for picking $\sigma$ given $s?$

$\endgroup$

1 Answer 1

5
$\begingroup$

Before downsampling, we need to first remove spatial frequencies in the image that cannot be represented by the new sampling grid, they would alias to a different frequency. When downsampling with a scale factor $s$, with $0 < s < 1$, then the new sampling frequency will be $s$ times the old one, and the new Nyquist frequency will be $s$ times the old one. If we take the old sampling frequency to be 1, the new one will be $s$. Thus we need to remove all frequencies at and above $s/2$ from the image.

A Gaussian filter is an effective low-pass filter. It is not an ideal one, but it offers an optimal compromise between compactness in the spatial domain and in the frequency domain. That is, it is the best low-pass filter you can make given its support. Of course a Gaussian is infinite in size, both in the spatial and in the frequency domain. The compactness referenced above is because the Gaussian goes to zero very quickly, and we can truncate it with very little loss. In the frequency domain, where the Gaussian reaches nearly zero, the frequencies will be suppressed sufficiently that we won't notice them when they alias. We can calculate at what point this happens, for any given suppression strength. Some fairly simple computations shows that (I these in my MSc thesis: Cris L. Luengo Hendriks - Improved Resolution in Infrared Imaging Using Randomly Shifted Images a long time ago):

A Gaussian filter defined by $\sigma$ reduces all frequencies above $2/\sigma$ by a factor of 100 or more.

This is an arbitrary definition of the cutoff, but it is a usable definition.

By this definition, we need to set $\sigma=1/s$. This definition avoids visible aliasing artefacts, but it also blurs the image too much. In practice, one can get away with a smaller Gaussian filter. $\sigma=1/2s$ (as suggested by OP) is a reasonable compromise in my experience.

For example, here is a test image with very high frequency content (top left). The top-right image is the first image downsampled by a factor 2 ($s=0.5$), without filtering first. On the bottom row, we use a Gaussian filter with $\sigma=1$ (left) and $\sigma=2$ (right). The bottom-right image follows the rule above, and nicely suppresses all frequencies that cannot be represented properly in the downsampled image. The bottom-left image uses $\sigma=1/2s$, leading to some aliasing. Nonetheless, this result is good, and the aliasing will likely not be very visible in natural images where the many frequency components of the image overlap spatially.

demonstration

$\endgroup$
2
  • $\begingroup$ Excellent answer and example. When using something like Lanczos downsampling, does it even makes sense to filter the image first with a Gaussian? $\endgroup$
    – wcochran
    Jun 26, 2021 at 21:56
  • $\begingroup$ @wcochran: That depends on how the Lanczos filter is implemented. You can use it as a pure interpolator to obtain sample values at the output locations (in this case, as you do with upsampling, the kernel is scaled according to the input grid). Or you can use it as a low-pass filter + interpolator (scaling the kernel to the output grid). In the latter case, of course, you don’t want to do any low-pass filtering first. $\endgroup$ Jun 26, 2021 at 22:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.