% How to

clear all;

%% Basic
a =zeros(3,4);
%-- 12/2/10  3:22 PM --%
a
size(a)
[r, c] = size(a)
a(1,1) = 1
a(:,4) = 1
a(2:3,3) = 2
a(6) = 3
a(5:6) = 3
find(a == 1)
length(find(a==1))
a(find(a==1)) = 5
a == 5
a(a == 5) = 6

%% Real image
img = imread('../../Images/covert.jpg');
imtool(img);
mask = ones(size(img, 1), size(img, 2));
% bgIdx = find(img(:,:,3) > 140);
bgIdx = find(img(:,:,1) < 130 & ...
    img(:,:,2) > 110 & img(:,:,2) < 160 & ...
    img(:,:,3) > 140);

mask(bgIdx) = 0;
imtool(mask);
imwrite(mask, 'raw_mask.png');

%% 
% clear mask;
% mask = img(:,:,1) < 130 & ...
%     img(:,:,2) > 110 & img(:,:,2) < 160 & ...
%     img(:,:,3) > 140;
% mask = ~mask;

% mask3D = zeros(size(img));
% for i = 1:3
%     mask3D(:,:,i) = mask;
% end

% face = mask .* img; not right type
% face = mask .* double(img); not right size
face = repmat(mask, [1,1,3]) .* double(img);
imtool(face) % not right type
imtool(uint8(face))
imwrite(uint8(face), 'applied_mask.png');
