%% Skin Color Detection
%% Based on code given in:
%% From: http://www.ee.oulu.fi/~hadid/Machine_Vision/lab_exercises/lab2.pdf


im=double(imread('skin.jpg'));
R = im(:,:,1);
G = im(:,:,2);
B = im(:,:,3);

I = R+G+B; 
I(find(I==0))=Inf;
r = R./I;
g = G./I;
figure;plot(r,g,'b.');
xlabel('r');
ylabel('g');
axis ([0 1 0 1]);


% replace r_min and r_max by their values !
%r_range =[r_min r_max]; 

% replace g_min and g_max by their values !
%g_range=[g_min g_max]; 

r_range =[0.35 0.65]; 
g_range=[0.25 0.35]; 
detectSkin('Jim.jpg', r_range, g_range);



detectSkin('Alex1.jpg', r_range, g_range);

% Alex and Michael Jordan have the same skin color!
detectSkin('Jordan.jpg', r_range, g_range);

% Reduce the noise
r_range =[0.4 0.6]; 
g_range =[0.25 0.35]; 
detectSkin('Alex1.jpg', r_range, g_range);


detectSkin('Alex2.jpg', r_range, g_range);

% Reduce the noise
r_range =[0.36 0.44]; 
g_range =[0.25 0.35]; 
detectSkin('Alex2.jpg', r_range, g_range);
