Advanced Image Processing - Introduction
Template Matching
Image self-similarity
Toute image naturelle contient des information redondantes (ciels, murs, …).
Objectifs : Utiliser ces redondances pour restaurer ou pour pleins d’autres usages
Problématiques :
- Comment detecter une similarité ? comment mesurer cette similarité ?
- Comment on trouve deux patch similaires ?
- Qu’en fait on ?
Similarity Metrics
Cross Correlation :
Soit P1 et P2 patches carrés independants. La cross-correlation se calcule de la maniere suivante :
$$ CC(P _1, P_2) = \sum _{k = 1} ^w \sum _{l = 1} ^w P _1 (k,l) P _2 (k,l) $$
Plus CC est grand plus les patch \(P _1\) et \(P _2\) sont similaires. Mais si on as des pixel très clair dans \(P _1\) ou \(P _2\) alors on tends ver le maximum
Zero-mean Normalized Cross-correlation
Pour gérer les changements d’intensité, on normalise les patch.
- Zero-mean :
- Standard unit equal to 1 :
Donne un résultat entre -1 (aucune similitude) à 1 (similitude totale).
Recall : Norm in \(l _p\) space
$$ \Vert x \Vert _p = (\vert x _1 \vert ^p + \vert x _2 \vert ^p + \dots + \vert x _n \vert ^p) ^{\frac{1}{p}} $$
Sum of Square Differences (SSD)
$$ SSD(P _1, P _2) = \sum _{(k,l)} (P _1 (k,l) - P _2 (k,l))^2 $$
Metrique la plus populaire.
Gaussian weigthed SSD
$$ SSDG(P _1, P _2) = \sum _{(k,l)} w(k,l) (P _1 (k,l) - P _2 (k,l))^2$$
Sum of absolute differences SAD
$$ SAD(P _1, P _2) = \sum _{(k,l)} \vert P _1 (k,l) - P _2 (k,l) \vert ^2 $$
Many others
Utilisation de SSD ou SAD sur des couleurs.
D’autres possibilités :
- sur les gradients : \(SAD(\nabla P _1, \nabla P _2)\)
- sur les histogrames
- over Histograms of Oriented Gradients (HoG), SIFT ou SURF
Aplications (ajouter des images)
- Synthese de texture
- Inpainting
- Colorisation
- Super-Resolution
- Style-transfer
- Stereo
- Denoising
Practice
- Study Matlab Tutorial or Mex Tutorials if you prefer programming in C
- Template Matching :
- Extract randomly 4 small square templates (size 9x9 for instance) from the two texture images provided. Save these windows.
- Compute the similarity between these templates using different metrics (SSD, ZNCC, SAD). Analyze the results. Note : in matlab you should avoid as most as possible using loops in your code.
% Matlab function for SSD metric
function result = ssd( w_first, w_second )
result = sum(sum(sum((w_first - w_second).^2,1), 2), 3);
end
% Matlab function for ZNCC metric
function result = zncc ( w_first, w_second )
end
% Matlab function for SAD metric
function result = sad ( w_first, w_second )
result = sum(sum(sum(norm(w_first(:,:) - w_second(:,:)),1), 2), 3);
end