-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbestexemplar.m
51 lines (37 loc) · 1.29 KB
/
bestexemplar.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
function Hq = bestexemplar(img,Ip,toFill,sourceRegion,rows,cols)
% Scans over the entire image (with a sliding window)
% for the exemplar with the lowest error.
m=size(Ip,1);
mm=size(img,1);
n=size(Ip,2);
nn=size(img,2);
%rows cols indexes of patch with maximum priority
% mn=m*n;
% mmnn=mm*nn;
patchErr=0.0;
% err=0.0;
bestErr=1000000000.0;
best = zeros(1,4);%1x4 vector that will contain the coordinates of the most similar patch Iq
%foreach patch
N=nn-n+1;%300-9+1
M=mm-m+1;%300-9+1
Ip = rgb2lab(Ip);
img = rgb2lab(img);
%sliding window over the image
for j = 1:M %1:282 ROWS
J=j+m-1;
for i = 1:N %1:282 COLS
I = i+n-1;
%check that sliding window is inside source region and outside Ip
if(inSourceRegion(j,J,i,I,sourceRegion) && outsideIp(rows,cols,j,J,i,I))
patchErr = ssd(Ip,img(j:J,i:I,:),toFill);
if (patchErr <= bestErr) %Update
bestErr = patchErr;
best(1,1) = j; best(1,2) = J;
best(1,3) = i; best(1,4) = I;
end
end
end
end
Hq = sub2ndx(best(1):best(2),(best(3):best(4))',mm);
return;