akhilc
akhilc

Reputation: 181

How imresize works when downsampling an image in MATLAB?

I don't clearly understand how imresize works, especially when we are downscaling an image (say from 4x4 to 2x2). When we're upscaling it's easier to understand. I mean we've to just find intermediate points by either seeing which known point is closer (method = 'nearest') or use linear averaging of 4 closest known points (method = 'bilinear') and so on. We do not need any filter for this right?

And my main doubt is when we downscale. I understand from signal processing classes that to avoid aliasing a smoothening low pass filter must be applied before we decimate intermediate values. But which filter is MATLAB using? They just say methods and I don't understand how we can use 'bilinear' or 'bicubic' as a kernel.

Thank you for reading.

Upvotes: 1

Views: 2410

Answers (1)

Daniel
Daniel

Reputation: 36710

The documentation for the function seems to be incomplete. Open the imresize.m (edit imresize) and take a look at the contributions-function.

There you can see, that matlab is not using a 2x2 neibourhood when using the bilinear or bicubic-method and downscaling. The kernel size is increased to avoid aliasing.


Some explanations about the Math behind imresize. To simplify, I will explain the 1D case only. When a scale <1 is used, the window size is increased. This means, the resulting value is no longer the weighted average of the 2 (2x2 for images) Neighbours. Instead a larger window size of w (wxw) is used.

Start with the standard method:

Std

The Image shows the common case, two known grid values averaged to a new one with the weights 1/5 and 4/5. Instead of the well known definition, the weights could also be defined drawing a triangle with the base w=2:

With triangle w=1

Now increasing the base of the triangle, we get the weights for a larger window size. A base of w=6 is drawn:

w=3

The new triangle defines the weight over 6 points.

Upvotes: 2

Related Questions