-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.m
116 lines (83 loc) · 2.28 KB
/
demo.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%
target = im2double(imread('6t.jpg'));
source = im2double(imread('6s.jpg'));
%%
%target = imadjust(target,[],[],0.2);
tic;
coor_Mouth = FindCoordinates(target,'Mouth');
toc;
tic;
coor_Eye = FindCoordinates(target,'EyePairBig');
toc;
tic;
toc;
x1 = coor_Eye(1); % sol göz
x2 = coor_Eye(1)+coor_Eye(3); % sað göz
x3 = coor_Mouth(1)+coor_Mouth(3); % aðýz solu
x4 = coor_Mouth(1); % aðýz saðý
y1 = coor_Eye(2);
y2 = coor_Eye(2);
y3 = coor_Mouth(2) + coor_Mouth(4);
y4 = coor_Mouth(2) + coor_Mouth(4);
centerX = round((x1 + x2 + x3 + x4) / 4);
centerY = round((y1 + y2 + y3 + y4) / 4);
tic;
width = x2-x1;
height = y4-y1;
[ImA,maskA3,centX,centY,cornerX,cornerY] = getMask(source,width,height,centerX,centerY,size(target));
ImA = imresize(ImA,[size(target,1) size(target,2)]);
maskA3 = imresize(maskA3,[size(target,1) size(target,2)]);
shiftx=int32(centerX-centX);
shifty=int32(centerY-centY);
shiftedIm=circshift(ImA,[shifty,shiftx]);
shiftedMask=circshift(maskA3,[shifty,shiftx]);
%%
toc;
result = shiftedIm.*shiftedMask + target.*(1-shiftedMask);
%%
% burada gradientleri alýrken sorun oluyor source resmi elimizdeki resimle
% ayný oranda deðil. boyutlarý ayný ama bizim elimizdeki surat daha büyük.
% öyle olunca surattan daha büyük yerleri alýyor. çözüm için resmi surat
% farkýnda büyüttükten kaydetmek lazým.
[Lh, Lv] = imgrad(target);
[Gh, Gv] = imgrad(ImA);
X = result;
Fh = Lh;
Fv = Lv;
w = width;
h = height;
LX = int32(x1);
LY = int32(y1);
isfind = 0;
for i=1:size(ImA,1)
for j=1:size(ImA,2)
if(maskA3(i,j,1) == 1)
GX = j;
GY = i;
isfind = 1;
break
end
end
if (isfind == 1)
break
end
end
% sorun burada +50 falan denemek için.
x = [x1 x2 x3 x4 x1];
y = [y1 y2 y3 y4 y1];
bw = poly2mask(x,y,size(target,1),size(target,2));
targetMask=repmat(bw,[1,1,3]);
Fh(LY:LY+h,LX:LX+w,:) = Gh(GY:GY+h,GX:GX+w,:);
Fv(LY:LY+h,LX:LX+w,:) = Gv(GY:GY+h,GX:GX+w,:);
imwrite(X,'X.png');
tic;
Y = PoissonJacobi(X, Fh, Fv, shiftedMask );
toc
figure,
imshow(Y);
imwrite(Y,'jacobi2y.png');
tic;
Y = PoissonGaussSeidel( X, Fh, Fv, shiftedMask );
toc
imwrite(Y,'gauss2y.png');