forked from Chouffe/Computer-Vision
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Arthur Caillau
committed
Apr 10, 2013
1 parent
4297e7d
commit fbeb536
Showing
25 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.