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

6.1 Maximizing SNR over class samples

In this section we start to address the problems arising from intrinsic signal variability. We no longer limit ourselves to the the problem of detecting a single, deterministic signal corrupted by noise, and we move to the problem of detecting a class of signals in the presence of noise. The signals we will consider are images of faces, a class of patterns of significant practical and theoretical interest. The dataset we will be using comprises 800 different faces, equally distributed over four differents races and the two genders.

1 basepath    <- "../theFaceDbs/races"
2 racesImages <- scan(file.path(basepath, "racesImageNames"), list(""))[[1]]
3 N           <- length(racesImages)
5 d                  <- 21*25
6 raceSamples        <- c()
7 raceSamplesMatrix  <- array(0, dim=c(N,d))
8 for(i in 1:N) {
10 ...                                                   racesImages[[i]]))))
11 ...   img <- ia.get(img, m)
12 ...   raceSamples          <- c(img, raceSamples)
13 ...   raceSamplesMatrix[i,] <- as.real(img@data)
14 ... }

It is interesting to note the result of clustering the above data respectivel with 4 clusters, the number of races considered, and with 8 clusters the number of races times the number of genders:

1 kns <- list(2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32)
2 kcs <- ia.map(function(n) sort(clara(raceSamplesMatrix,  n)\$i.med), kns)
3 k32 <- raceSamplesMatrix[kcs[[16]],]

The default metrics used by function clara is the Euclidean norm (L2) discussed in a previous chapter. Samples are regularly (consecutively) organized in groups of 200 items, 100 males and 100 females. The above clustering procedure, of which we reported the indices identifying each computed cluster within the original data, assigns 1 cluster center to each race (or race and gender) group.

1 tm.dev("figures/fourClusters", width=6, height=2)
2 par(mfrow = c(1,4))
3 for(i in kcs[[2]]) {
4 ... ia.show(raceSamples[[i]])
5 ... }
6 dev.off()
7 tm.dev("figures/eightClusters", width=6, height=4)
8 par(mfcol = c(2,4))
9 for(i in kcs[[4]]) {
10 ... ia.show(raceSamples[[i]])
11 ... }
12 dev.off()

As detailed in Section TM:6.1, the optimal matched filter for the whole image set is given by the dominant eigenvector. Let us note that, in this case, the required covariance matrix is the not-centered one:

 (6.1)

where X is a matrix whose rows correspond to our face images, linearized as vectors:

1  var <- t(raceSamplesMatrix) %*% raceSamplesMatrix

The computation of the eigenvectors is straightforward:

1  evs <- eigen(var)
2  # and we de-linearize the most significant twos
3  # into an image
4  ev1 <- as.animage(x <- array(evs\$vectors[,1], dim=c(25,21)))
5  ev2 <- as.animage(x <- array(evs\$vectors[,2], dim=c(25,21)))
6 tm.dev("figures/evs", width=6, height=6)
7 par(mfcol = c(2,2))
8 ia.show(ev1)
9 ia.show(ia.scale(ia.mult(ev1, -1)))
10 ia.show(ev2)
11 ia.show(ia.scale(ia.mult(ev2, -1)))
12 dev.off()