Fondazione Bruno Kessler - Technologies of Vision

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.


PIC

Figure 2.7: A comparison of two Lanczos kernel with different sampling factors: the more dispersed one is the one to use for image smoothing when halving its resolution.


1 sampleimages <- file.path(system.file(package = "AnImAl"), "sampleimages/") 
2 face1        <- as.animage(getChannels(read.pnm( 
3 ...                 file.path(sampleimages, "sampleFace_01.pgm")))) 
4 A <- tm.normalizeFaceImage(face1,57,113,122,112,ee=22) 
5 B <- tm.normalizeFaceImage(face1,57,113,122,112,ee=22,smooth = FALSE) 
6 tm.plot("figures/normalized1", ia.show(A, main = "Smoothed")) 
7 tm.plot("figures/normalized2", ia.show(B, main = "Aliased"))


PIC PIC

Figure 2.8: An important example of image resampling: a face image is rotated, translated, and scaled so that the (centers of) the eyes of the subject are located at predefined positions. The two images illustrate the difference resulting from proper frequency conditioning via smoothing (left) and the direct use of the affine transform of Equation TM:2.76