% Standard Image  (Barbara)
clear;
I1=imread('Barbara.bmp');
figure(1)
imagesc(I1);

I1r=im2double(I1(:,:,1));
I1g=im2double(I1(:,:,2));
I1b=im2double(I1(:,:,3));
I1Y=(0.297*I1r+ 0.587*I1g+0.114*I1b)*255;
I1Cb=(-0.169*I1r-0.331*I1g+0.5*I1b)*255+128;
I1Cr=(0.5*I1r-0.419*I1g-0.081*I1b)*255+128;
imwrite(I1Y/255,'Barbara_Y.bmp');
imwrite(I1Cb/255,'Barbara_Cb.bmp');
imwrite(I1Cr/255,'Barbara_Cr.bmp');
% Skin color decision(100<=Cb<=115, 155<=Cr<=170)
for m=1:312
    for n=1:261
        if((I1Cb(n,m)<100 |I1Cb(n,m)>115) | (I1Cr(n,m)<155 | I1Cr(n,m)>170))
            I1Y(n,m)=16;
        else
            I1Y(n,m)=255;
        end
    end
end

figure(2)
imagesc(I1Y);colormap(gray)
imwrite(I1Y/255,'Barbara_face.bmp');
% Block Decision(Y_ave in 8x8 block >125)
for m=1:8:305
    for n=1:8:254
        A=sum(I1Y(n:n+7,m:m+7));
        if(sum(A)/64>125)
            I1Y(n:n+8,m:m+8)=255;
        else
            I1Y(n:n+8,m:m+8)=0;
        end
    end
end
figure(3)
imagesc(I1Y);colormap(gray)
imwrite(I1Y/255,'Barbara_block.bmp');
