contains material from
Template Matching Techniques in Computer Vision: Theory and Practice
Roberto Brunelli © 2009 John Wiley & Sons, Ltd

### 2.5 Image resampling

Image processing algorithms, template matching techniques included, often require image scaling and rotation. These operations are a subset of the linear transformations described by Equation TM:2.74. As an illustrative example let us consider geometric normalization of a face image: a combined rotation, scaling, and translation operation fixing the origin of the image coordinate system at the midpoint of the segment joining the eyes, at the same time making the eye to eye axis horizontal with eyes at a predefined distance from the new origin.

Image transformations of the type considered usually require image values at positions different from those of the original sampling. The computation of the new values can be performed correctly if the requirements of the sampling theorem are satisfied, sometimes requiring a preliminary smoothing step in order to reduce image frequency content, e.g. when reducing image size. The actual resampling operation can then be performed relying on Lanczos interpolation.

The frequency conditioning step can be performed applying a Gaussian smoothing kernel or a Lanczos kernel. Let us consider halving image resolution. As the Gaussian filter is approximately band limited with critical spacing σ and corresponding bad-limit σ-12, it is appropriate to smooth the image with a σ = 2 Gaussian kernel (as we want to halve its resolution. If we use a Lanczos kernel we can rely on Equations TM:2.77-78 and sample the original kernel (twice) more densely. A function is available for computing the kernel, tm.lanczosKernel: the sampling density of the kernel is controlled by parameter factor.

1 lk12 <- tm.lanczosKernel(factor = 1, support = 2, trim = 5)
2 lk22 <- tm.lanczosKernel(factor = 2, support = 2, trim = 5)
3 tm.plot("figures/lanczosKernels",
4 ...            matplot(-5:5,cbind(t(lk12),t(lk22)),type="b",col=c("black"),
5 ...                    pch = 2:3, lty=1:2, xlab="x", ylab="",
6 ...                    main="Lanczos kernels"),
7 ...            legend(-5,0.9, c("factor=1,support=2", "factor=2,support=2"),
8 ...                   pch=2:3, lty=1:2, col=c("black"))
9 ...            )

If trim is omitted (or set to TRUE) the size of the kernel is appropriately computed to cover its support. Kernel lk22 is the one to use in preconditioning image frequency content prior to subsampling.

1 sampleimages <- file.path(system.file(package = "AnImAl"), "sampleimages/")