Skin-based Face Detection: An Implementation 2011/Lec5.… · Skin-based Face Detection: An...
Transcript of Skin-based Face Detection: An Implementation 2011/Lec5.… · Skin-based Face Detection: An...
1/27/2011 ECE 523: Introduction to Biometrics 2
Outline
• Face Detection Framework
• Live Class Example
1/27/2011 ECE 523: Introduction to Biometrics 3
Generic Framework for Face Detection
Skin
Detection
Morphological
Processing
Template
Matching
Face
Selection
1/27/2011 ECE 523: Introduction to Biometrics 4
Methods of Skin Detection
• Pixel-Based Methods
– Classify each pixel as skin or non-skin individually, independently from its neighbors.
– Color Based Methods fall in this category
• Region Based Methods
– Try to take the spatial arrangement of skin pixels into account during the detection stage to enhance the methods performance.
– Additional knowledge (in terms of texture … etc) are required
1/27/2011 ECE 523: Introduction to Biometrics 5
Different Color Models
• RGB
• Normalized RGB
• HIS, HSV, HSL
• TSL
• YCrCb
• Perceptually uniform colors
• Others
1/27/2011 ECE 523: Introduction to Biometrics 6
Bayes Decision Rule
• N-class case
Given a feature vector x, assign it to class wj if:
• Likelihood Ratio: 2-class case
Likelihood ratio Threshold
An Example1
1 Ciarán Ó Conaire, Computer Vision Source Code, Skin Detection, http://clickdamage.com/sourcecode/index.html
fn = 'IMG_1762.jpg';
im = double(imread(fn));
1/27/2011 ECE 523: Introduction to Biometrics 8
An Example
• Non-parametric histogram-based models were trained using manually annotated skin and non-skin pixels.
• A total of 14,985,845 skin pixels and 304,844,751 non-skin pixels were used.
• Created an RGB histogram for "skin pixels" and another one for "non-skin pixels" (they
are 32x32x32 in size)
• For a particular bin (i.e. pixel color), the log likelihood of it being skin is
where H refers to the skin histogram and h refers to non-skin histogram.
1/27/2011 ECE 523: Introduction to Biometrics 9
An Example
% Compute the skin likelihood for each pixel
skinprob = computeSkinProbability(im);
function skinprob = computeSkinProbability(im)
persistent smodel;
if (isempty(smodel))
% load skin model
skinmodfn = 'skinmodel.bin';
fid = fopen(skinmodfn, 'rb');
tmp = fread(fid, inf, 'real*4');
fclose(fid);
K = 32;
smodel = zeros(K,K,K);
smodel(:) = tmp(:);
clear tmp
end
Part I
1/27/2011 ECE 523: Introduction to Biometrics 10
An Example
if (size(im,3) ~= 3)
warning('Input image does not have 3 bands. RGB image
required.');
skinprob = [];
return
end
im = double(im);
im2 = 1 +
floor(im(:,:,1)/8)+floor(im(:,:,2)/8)*32+floor(im(:,:,3)/8)*
32*32; % 32 bins
skinprob = smodel(im2);
function skinprob = computeSkinProbability(im)
… Part II
1/27/2011 ECE 523: Introduction to Biometrics 11
An Example
% compute and display a binary skin map using a threshold of 0
figure, image((skinprob>0)*64);
colormap('gray');
title('Likelihood thresholded at zero');
Likelihood thresholded at zero
50 100 150 200 250 300 350 400 450 500 550
50
100
150
200
250
300
350
1/27/2011 ECE 523: Introduction to Biometrics 12
Live Class Example
(a) Divide data into training and testing sets
(b) Work on training data – skin and non-skin (c) RGB -> YCbCr (important to LP filter Cb, Cr to remove noise) (d) Scatter plot two classes (e) Get 2D mean, covariance for both skin/non-skin (f) Apply Bayes classifier (with equal priors) to testing set (g) Apply Bayes classifier with priors trained from training data
1/27/2011 ECE 523: Introduction to Biometrics 13
Skin Detection Results
(Input) (Output)
1 – Detected skin pixels (white) 0 – Non-skin (black)
1/27/2011 ECE 523: Introduction to Biometrics 14
Generic Framework for Face Detection
Skin
Detection
Morphological
Processing
Template
Matching
Face
Selection
1/27/2011 ECE 523: Introduction to Biometrics 15
Morphological Processing
• Morphological closing – closing fills up any narrow black regions in the image
I = double(I);
filledBW = imfill(I,'holes');
1/27/2011 ECE 523: Introduction to Biometrics 16
Morphological Processing • Morphological erosion – removes pixels on object boundaries
se2 = strel('disk',10); % Structuring element
erodedBW = imerode(filledBW,se2);
1/27/2011 ECE 523: Introduction to Biometrics 17
Morphological Processing • Morphological dilation – adds pixels to the boundaries of objects in an image
se1 = strel('disk',8);
dilateBW = imdilate(erodedBW,se1);
1/27/2011 ECE 523: Introduction to Biometrics 18
Morphological Processing
• Dilated binary image is multiplied with binary image from the segmentation process to maintain the holes.
x
dilateBW = immultiply(dilateBW,I);
1/27/2011 ECE 523: Introduction to Biometrics 19
Morphological Processing
• Region labeling – each clustered group of pixels can be identified at a single region; each region can be analyzed further if it’s a face or not
[labelBW,num] = bwlabel(dilateBW,8);
color_regions= label2rgb(labelBW, 'hsv', 'black', 'shuffle');
figure, imshow(color_regions)
1/27/2011 ECE 523: Introduction to Biometrics 20
Morphological Processing
• Euler number – the total number of objects in the image minus the number of holes in those objects
• Consider only objects with at least one hole
eulerBW = euler_test(labelBW);
1/27/2011 ECE 523: Introduction to Biometrics 21
Morphological Processing
• Aspect ratio test – any region with aspect ratio unlikely to be a face is rejected
aspectBW = aspect_test(eulerBW)
1/27/2011 ECE 523: Introduction to Biometrics 22
Template Matching • width, height, orientation and centroid of binary region under consideration has to
be computed using regionprops()
• template face image is resized, rotated and its centroid placed on the centroid of the region in original grayscale image with only one region
Template
original grayscale image with only one region
Rotated template
• crosscorrelation is calculated, threshold of 0.6 is set by experiment and the regions which has less crosscorrelation value is rejected.
1/27/2011 ECE 523: Introduction to Biometrics 23
Final Detection
Template Matching
Final Detected Face
1/27/2011 ECE 523: Introduction to Biometrics 25
References
Ciarán Ó Conaire, Computer Vision Source Code, Skin Detection, http://clickdamage.com/sourcecode/index.html Jie Yang and Alex Waibel, "A Real-Time Face Tracker", CMU CS Technical Report. J. Cai & A. Goshtasby & C. Yu, "Detecting Human Faces in Color Images", Wright State University, U. of Illinois. G. Wyszecki and W.S. Styles. Color Science: Concepts and Methods, Quantitative Data and Formulae, second edition, John Wiley & Sons, New York 1982. Y. Gong and M. Sakauchi, "Detection of regions matching specified chromatic features", Computer Vision and Image Understanding, vol. 61, no. 2, 1995, pp 263 – 269 R. Ramesh, Kasturi R. and Schunck B., Machine Vision, pp 31 - 51, McGraw Hill, New York 1995. Henry Chang and Ulises Robles, Face Detection, http://www-cs-students.stanford.edu/~robles/ee368/source.html