Here is just a simple implementation, which is very similar to histogram reverse projection.
The book says, "the advantage is theoretically, and it is difficult to develop a satisfactory template matching technology ".
Code:
Clear all; close all1_clc1_img1_imread('lena.jpg '); imshow (IMG); IMG = double (IMG); mask = double (imcrop (); [m n] = size (IMG ); [h w] = size (mask); If Mod (H, 2 )~ = 1 h = H + 1; endif Mod (W, 2 )~ = 1 W = W + 1; endmask = imresize (mask, [H w]); HH = floor (H/2); ww = floor (W/2 ); imgn = zeros (m + 2 * hh + 1, n + 2 * ww + 1); imgn (HH + 1: m + HH, WW + 1: N + ww) = IMG; imgn (1: hh, WW + 1: N + ww) = IMG (1: hh, 1: N); imgn (1: m + HH, N + WW + 1: n + 2 * ww + 1) = imgn (1: m + HH, N: N + ww); imgn (m + HH + 1: m + 2 * hh + 1, WW + 1: n + 2 * ww + 1) = imgn (M: m + HH, WW + 1: n + 2 * ww + 1); imgn (1: m + 2 * hh + 1, 1: ww) = imgn (1: m + 2 * hh + 1, WW + * ww); Re = imgn; for I = HH + 1: m + HH for J = WW + 1: N + ww tmp = imgn (I-hh: I + HH, J-ww: J + ww); Re (I, j) = sum (TMP-mask ). ^ 2); % least square difference endendfigure; Re = mat2gray (RE (HH + 1: m + HH, WW + 1: N + ww )); imshow (1-Re );
Source image
Template
Result
The brightest point is the position of the eye.