-
Notifications
You must be signed in to change notification settings - Fork 0
/
removeSkinModal.m
63 lines (44 loc) · 1.33 KB
/
removeSkinModal.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function [mask] = removeSkinModal(RGB)
mask = ones(size(RGB,1),size(RGB,2));
CgImg = mask;
CrImg = mask;
for i = 1:size(RGB,1)
for j = 1:size(RGB,2)
RGBp = reshape(RGB(i,j,:),3,1);
[Cg,Cr] = ycgcrRotated(RGBp);
CgImg(i,j) = Cg;
CrImg(i,j) = Cr;
% if(Cg <= 140 && Cg >=125) && (Cr <=217 && Cr >=136)
% mask(i,j) = 0;
% end
end
end
CgMode = mode(reshape(CgImg,1,[]));
CrMode = mode(reshape(CrImg,1,[]));
CgModeP = CgMode;
CrModeP = CrMode;
while sqrt((CgMode-CgModeP)^2 + (CrMode-CrModeP)^2) < 0.1
for i = 1:size(RGB,1)
for j = 1:size(RGB,2)
if(CgImg(i,j) <= CgMode*1.07 && CgImg(i,j) >=CgMode*0.93) && (CrImg(i,j) <=CrMode*1.07 && CrImg(i,j) >=CrMode*0.93)
mask(i,j) = 0;
end
end
end
CgModeP = CgMode;
CrModeP = CrMode;
CgMode = mode(reshape(CgImg,1,[]).*reshape(mask,1,[]));
CrMode = mode(reshape(CrImg,1,[]).*reshape(mask,1,[]));
sqrt((CgMode-CgModeP)^2 + (CrMode-CrModeP)^2)
end
end
function [Cg,Cr] = ycgcrRotated(RGBp)
RGBp = double(RGBp);
yCgCr = [0.257,0.504,0.098;
-0.317,0.438,-0.121;
0.439,-0.368,-0.071];
bias = [16;128;128];
YCgCrp = yCgCr*RGBp+bias;
Cg = YCgCrp(2)*cos(deg2rad(30))+YCgCrp(3)*sin(deg2rad(30))-48;
Cr = -YCgCrp(2)*sin(deg2rad(30))+YCgCrp(3)*cos(deg2rad(30))+80;
end