How to choose sigma/kernel size when downsampling image

asked 2019-11-27 03:51:37 -0600

Dianan137 gravatar image

updated 2019-11-27 03:54:30 -0600

Hello!

I simply want to downscale an image using cv2.resize() and I read that to avoid visual distortion, a blur should be applied before resizing. Therefore I opted for the Gaussian Blur. However, I couldn't find how the downscale factor relates to the either the sigma for the blur nor the kernel size of the gaussian.

On the wikipedia page for gaussian filtering I found the equation linking the cut off frequency to the sigma: image description

Which means for a cutoff frequency of 1/(2*M) (with M being the downsample factor, and the cutoff frequency chosen to at least reach the Nyquist frequency - from the wikipedia page on anti-aliasing), the formula should be sigma = downscale/pi. This somewhat roughly matches with what skimage uses to calculate the sigma from the downsample factor sigma = 2 * downscale / 6.0 (source)

My question is: is this correct? I was surprised not to be able to find any tutorials or forum posts/discussions on this.

edit retag flag offensive close merge delete

Comments

Lack of posts may mean that is is old folklore and totally unnecessary unless perhaps a nearest neighbour algorithm is used and not a more sophisticated one. I've never seen anyone do it.

mvuori gravatar imagemvuori ( 2019-11-27 09:13:23 -0600 )edit

see the documentation

To shrink an image, it will generally look best with INTER_AREA interpolation, whereas to enlarge an image, it will generally look best with c::INTER_CUBIC (slow) or INTER_LINEAR (faster but still looks OK).

sturkmen gravatar imagesturkmen ( 2019-11-27 11:01:31 -0600 )edit