Code covered by the BSD License  

Highlights from
Morphological Shared-Weight Neural Network for Face Recognition

image thumbnail

Morphological Shared-Weight Neural Network for Face Recognition

by

 

31 Dec 2004 (Updated )

MSNN has the ability to learn feature extraction and perform classification at the same time.

convolution(I,selectedeye)
function [M,ltx,lty,rbx,rby] = convolution(I,selectedeye)
% USAGE: this function performs convolution search on I
% and outputs M (i.e. the TAP (Target Aim Point) on the detected eye area)
% "selectedeye" is used as a mask/kernel to search for eyes in I

% Declare filter masks (vertical and horizontal)
horiz = [-1 -2 -1; 0 0 0; 1 2 1];
vert = [-1 0 1; -2 0 2; -1 0 1];

% Number of possible eyes in the image. We set 2 to make sure.
noofeyes = 2;   
ratio = 0.89;

% Set search limits
[height, width] = size(I);
mineyesize = width / 4.6;
if(mineyesize<20)
   mineyesize = 20;
end;
maxeyesize = width/1.8;

% Filter and construct template from cropped eye
eyetemplate = double(selectedeye);
eyetempx = abs(conv2(eyetemplate, horiz, 'valid'));
eyetempy = abs(conv2(eyetemplate, vert, 'valid'));
eyetempx = eyetempx .* 255 ./ max(max(eyetempx));
eyetempy = eyetempy .* 255 ./ max(max(eyetempy));

eyesize = mineyesize;
rez = 20/mineyesize;
from = 1;

% Detection
while(eyesize<=maxeyesize) & (eyesize<31)
   fprintf(1, 'Detect Eye Size: %d\n', floor(eyesize) );
   rez_image = imresize(I, rez);
   tracex = abs(conv2(rez_image, horiz, 'valid'));
   normalizex = tracex .* 255 ./ max(max(tracex));
   tracey = abs(conv2(rez_image, vert, 'valid'));
   normalizey = tracey .* 255 ./ max(max(tracey));
   convo_x = conv2(normalizex, eyetempx, 'same');
   convo_y = conv2(normalizey, eyetempy, 'same');
   outpixels = convo_x + convo_y;
   to = from + noofeyes - 1;
   [values(from:to), yvalue(from:to), xvalue(from:to)] = maxposition(outpixels, noofeyes, 0);
   yvalue(from:to) = yvalue(from:to) / rez;
   xvalue(from:to) = xvalue(from:to) / rez;
   isize(from:to) = eyesize;
   from = to + 1;
   
   rez = rez * ratio;
   eyesize = 20/rez;
end;

[value, y, x] = maxposition(values, noofeyes, 0);

k = 1;
for i=1:noofeyes
   center_col = xvalue(x(i));
   center_row = yvalue(x(i));
   splitwidth = isize(x(i)) / 2;
   splitheight = splitwidth * 1.2;
   ltx(k) = floor(center_col - splitwidth);
   lty(k) = floor(center_row - splitheight);
   rbx(k) = floor(center_col + splitwidth);
   rby(k) = floor(center_row + splitheight);
   if( ltx(k) < 1 | lty(k) < 1 | rbx(k) > width | rby(k) > height )
      ltx(k) = [];
      lty(k) = [];
      rbx(k) = [];
      rby(k) = [];
   else
      k = k+1;
   end
end

M = imrect(I,ltx,lty,rbx,rby);

save J;

Contact us