-
Notifications
You must be signed in to change notification settings - Fork 3
/
skinmap.m
48 lines (40 loc) · 1.46 KB
/
skinmap.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function [out bin] = skinmap(img_orig)
%GENERATE_SKINMAP Produce a skinmap of a given image. Highlights patches of
%"skin" like pixels. Can be used in face detection, gesture recognition,
%and other HCI applications.
% The function reads an image file given by the input parameter string
% filename, read by the MATLAB function 'imread'.
% out - contains the skinmap overlayed onto the image with skin pixels
% marked in blue color.
% bin - contains the binary skinmap, with skin pixels as '1'.
%
% Example usage:
% [out bin] = generate_skinmap('nadal.jpg');
% generate_skinmap('nadal.jpg');
%
% Gaurav Jain, 2010.
if nargin > 1 | nargin < 1
error('usage: generate_skinmap(image)');
end;
%Read the image, and capture the dimensions
%img_orig = imread(filename);
height = size(img_orig,1);
width = size(img_orig,2);
%Initialize the output images
out = img_orig;
bin = zeros(height,width);
%Apply Grayworld Algorithm for illumination compensation
img = img_orig;%grayworld(img_orig);
%Convert the image from RGB to YCbCr
img_ycbcr = rgb2ycbcr(img);
Cb = img_ycbcr(:,:,2);
Cr = img_ycbcr(:,:,3);
%Detect Skin
[r,c,v] = find(Cb>=98 & Cb<=142 & Cr>=133 & Cr<=177);
numind = size(r,1);
%Mark Skin Pixels
for i=1:numind
out(r(i),c(i),:) = [0 0 255];
bin(r(i),c(i)) = 1;
end
end