Skip to content

Commit

Permalink
Ex5 Done
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Caillau committed Apr 10, 2013
1 parent 4297e7d commit fbeb536
Show file tree
Hide file tree
Showing 25 changed files with 79 additions and 6 deletions.
Binary file added ex1/arthur/octave-core
Binary file not shown.
Binary file added ex4/.GaussLikelihood.m.swp
Binary file not shown.
Binary file added ex4/.GrabCenterPixels.m.swp
Binary file not shown.
Binary file added ex4/.SkinClassifier.m.swp
Binary file not shown.
Binary file added ex4/.TrainColourModel.m.swp
Binary file not shown.
3 changes: 2 additions & 1 deletion ex4/GaussLikelihood.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
detSigma = det(Sigma);
for i = 1:size(xs,1)
lvals(i) = exp(-0.5*(xs2(i,:)-mu)/Sigma*transpose(xs2(i,:)-mu))/((2*pi)^(size(xs2,2)/2)*sqrt(abs(detSigma)));
end
end
end
3 changes: 2 additions & 1 deletion ex4/GrabCenterPixels.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function cim = GrabCenterPixels(im_fname, p)
im = imread(im_fname);
[H, W, dummy] = size(im);
cim = im(floor(H*(1-p)/2)+1:floor(H*(1+p)/2), floor(W*(1-p)/2)+1:floor(W*(1+p)/2), :);
cim = im(floor(H*(1-p)/2)+1:floor(H*(1+p)/2), floor(W*(1-p)/2)+1:floor(W*(1+p)/2), :);
end
Binary file added ex4/HMW4_Arthur_Caillau.tar.gz
Binary file not shown.
Binary file added ex4/Result/Student1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ex4/Result/Student2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion ex4/SkinClassifier.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function bim = SkinClassifier(im, hsv)
% Skin Classifier returns the binary im of classified pixels
% hsv = 0 => rgb
% hsv = 1 => hsv

Expand All @@ -8,6 +9,7 @@
xs = rgb2hsv(xs);
xs = [cos(xs(:,1)), sin(xs(:,1)), xs(:,2:3)];
end

lvals = GaussLikelihood(xs, mu, sig);
prob = reshape(lvals, size(im,1), size(im,2), 1);

Expand All @@ -17,4 +19,6 @@

ratio = prob./prob_back;
bim = zeros(size(ratio));
bim(find(ratio > 1)) = 1;
bim(find(ratio > 1)) = 1;

end
9 changes: 6 additions & 3 deletions ex4/TrainColourModel.m
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
function [mu, Sigma] = TrainColourModel(DirName, p, n, m)
% Train the model bt reading the pictures located in DirName
% Compute mu and sigma as the trained parameters
% m = 0: RGB
% m = 1: HSV
ls = dir(strcat(DirName,'*.jpg'));

datas = [];
for i = 1:n
if i < size(ls,1)
cim = GrabCenterPixels(ls(i).name, p);
cim = GrabCenterPixels(strcat(DirName, ls(i).name), p);
rgb_data = reshape(cim, [size(cim,1)*size(cim,2), 3]);
datas = [datas; rgb_data];
size(datas);
end
end

% Use HSV
if m > 0
% Use HSV colour model
datas = rgb2hsv(datas);
datas = [cos(datas(:,1)), sin(datas(:,1)), datas(:,2:3)];
end

mu = sum(datas, 1)/size(datas,1);
Sigma = cov(double(datas));
Sigma = cov(double(datas));
end
9 changes: 9 additions & 0 deletions ex4/arthur/GaussLikelihood.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function lvals = GaussLikelihood(xs, mu, Sigma)
xs2 = double(xs);
lvals = zeros(size(xs,1),1);
iSigma = inv(Sigma);
detSigma = det(Sigma);
for i = 1:size(xs,1)
lvals(i) = exp(-0.5*(xs2(i,:)-mu)/Sigma*transpose(xs2(i,:)-mu))/((2*pi)^(size(xs2,2)/2)*sqrt(abs(detSigma)));
end
end
5 changes: 5 additions & 0 deletions ex4/arthur/GrabCenterPixels.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function cim = GrabCenterPixels(im_fname, p)
im = imread(im_fname);
[H, W, dummy] = size(im);
cim = im(floor(H*(1-p)/2)+1:floor(H*(1+p)/2), floor(W*(1-p)/2)+1:floor(W*(1+p)/2), :);
end
Binary file added ex4/arthur/Result/Student1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ex4/arthur/Result/Student2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions ex4/arthur/SkinClassifier.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function bim = SkinClassifier(im, hsv)
% Skin Classifier returns the binary im of classified pixels
% hsv = 0 => rgb
% hsv = 1 => hsv

[mu sig] = TrainColourModel('lfw/George_W_Bush/', 0.2, 20, hsv);
xs = reshape(im, size(im,1)*size(im,2), size(im,3));
if hsv > 0
xs = rgb2hsv(xs);
xs = [cos(xs(:,1)), sin(xs(:,1)), xs(:,2:3)];
end

lvals = GaussLikelihood(xs, mu, sig);
prob = reshape(lvals, size(im,1), size(im,2), 1);

[mu_back sig_back] = TrainColourModel('BackgroundImages/', 1, 22, hsv);
lvals = GaussLikelihood(xs, mu_back, sig_back);
prob_back = reshape(lvals, size(im,1), size(im,2), 1);

ratio = prob./prob_back;
bim = zeros(size(ratio));
bim(find(ratio > 1)) = 1;

end
26 changes: 26 additions & 0 deletions ex4/arthur/TrainColourModel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function [mu, Sigma] = TrainColourModel(DirName, p, n, m)
% Train the model bt reading the pictures located in DirName
% Compute mu and sigma as the trained parameters
% m = 0: RGB
% m = 1: HSV
ls = dir(strcat(DirName,'*.jpg'));

datas = [];
for i = 1:n
if i < size(ls,1)
cim = GrabCenterPixels(strcat(DirName, ls(i).name), p);
rgb_data = reshape(cim, [size(cim,1)*size(cim,2), 3]);
datas = [datas; rgb_data];
size(datas);
end
end

% Use HSV
if m > 0
datas = rgb2hsv(datas);
datas = [cos(datas(:,1)), sin(datas(:,1)), datas(:,2:3)];
end

mu = sum(datas, 1)/size(datas,1);
Sigma = cov(double(datas));
end
Binary file added ex5/HMW5_Arthur_Caillau.tar.gz
Binary file not shown.
Binary file added ex5/HMW5_Arthur_Caillau/IMG_1375.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ex5/HMW5_Arthur_Caillau/IMG_1376.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ex5/HMW5_Arthur_Caillau/IMG_1377.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ex5/IMG_1375.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ex5/IMG_1376.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ex5/IMG_1377.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fbeb536

Please sign in to comment.