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

### 4.3 L1 similarity measures

While the robustness achievable with tm.robustifiedCorrelation is remarkable, there are two related problems:

1. it requires a substantial amount of computation;
2. it can be, paradoxically, too robust: it looses discrimination efficiency.

Both problems can be solved using the similarity estimators based on the L1 norm as described in Section TM:4.3.

1 tm.noiseSimilarityImpact <- function(img, cRange=c(0,0.2)) {
2 ...  c0  <- cRange[1]
3 ...  c1  <- cRange[2]
4 ...  cs  <- seq(c0,c1,(c1-c0)/10)
5 ...  n   <- length(cs)
6 ...  #
7 ...  img <- ia.scale(img)
8 ...  res <- array(0, dim=c(n, 5))
9 ...  #
10 ...  i   <- 0
11 ...  X   <- tm.normalizeImage(img)
12 ...  for(c in seq(c0,c1,(c1-c0)/10)) {
13 ...    i <- i + 1
14 ...    res[i,1] <- c
15 ...    #
16 ...    Y <- tm.addNoise(img, noiseType="saltpepper", scale = 1, percent=c)
17 ...    Y <- tm.normalizeImage(Y)
18 ...    #
19 ...    res[i,2] <- tm.robustifiedCorrelation(X, Y, "p")
20 ...    res[i,3] <- tm.robustifiedCorrelation(X, Y, "O")
21 ...    res[i,4] <- max(ia.correlation(X,Y, type="G")[[1]]@data)/100
22 ...    res[i,5] <- max(ia.correlation(X,Y, type="L")[[1]]@data)/100
23 ...  }
24 ...  #
25 ...  res
26 ... }