1
function [out, bin] = skinmap(img_orig)
3
% The function reads an image file given by the input parameter string
4
% filename, read by the MATLAB function 'imread'.
5
% out - contains the skinmap overlayed onto the image with skin pixels
7
% bin - contains the binary skinmap, with skin pixels as '1'.
9
if nargin > 1 || nargin < 1
10
error('usage: generate_skinmap(image)');
13
%Read the image, and capture the dimensions
14
height = size(img_orig,1);
15
width = size(img_orig,2);
17
%Initialize the output images
19
bin = zeros(height,width);
22
%Apply Grayworld Algorithm for illumination compensation
24
% figure(); imshow(img_orig); title('Èñõîäíîå ôîòî');
25
% A_lin = rgb2lin(img_orig);
27
% illuminant = illumgray(A_lin,percentiles);
28
% B_lin = chromadapt(A_lin,illuminant,'ColorSpace','linear-rgb');
29
% img = lin2rgb(B_lin);
30
% figure(); imshow(img); title('Îáðàáîòàííîå ôîòî');
32
%Convert the image from RGB to YCbCr
33
img_ycbcr = rgb2ycbcr(img);
34
Cb = img_ycbcr(:,:,2);
35
Cr = img_ycbcr(:,:,3);
38
[hue,~,~] = rgb2hsv(img);
41
[r,c,~] = find(Cb>=98 & Cb<=142 & Cr>=135 & Cr<=177 & hue<=0.1 & 0.01<=hue);
46
out(r(i),c(i),:) = [0 0 255];