-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSynth.m
52 lines (38 loc) · 1.53 KB
/
Synth.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
% Copyright (C) 2017 Omry Sendik
% All rights reserved.
%
% This file is part of the Deep Correlations for Texture Synthesis code and is made available under
% the terms of the BSD license (see the COPYING file).
clc;
clear all;
close all;
%%
FirstTime = 0;
if(FirstTime) %% Change this flag to 1 if this is the first time you run the code and need to compile it
DCor_compile();
end
DCor_addpaths();
%% Load the images and the net
origSrcImg = imread(strrep('.\Data\Texture13.png','\',filesep));
params = GetSynthParams();
net = GenNet(params.lastLayerNum);
params.netImgSz = [225 225 3];
params.OutString = strrep('.\Data\Output\Texture13_Result','\',filesep);
params.USFac = 1; %% Upscaling factor
SrcImg = ImNorm(imresize(origSrcImg,params.netImgSz(1:2)),net.meta.normalization.averageImage);
%% Toroidal Expansion
% SrcImg = ImExpand(SrcImg,params);
% params.USFac = 1; %% For the toroidal expansion only
%% Synthesis
Verify(params);
initNoise = 0.1*randn(round(params.USFac*size(SrcImg,1)),round(params.USFac*size(SrcImg,2)),size(SrcImg,3));
curTgtImg = initNoise;
clear errorLoss;
errorLoss = [inf];
SrcMats = GetSRCMats(SrcImg,initNoise,net,params);
funloss = @(x) (GetLossFromImg(net,x,SrcImg,SrcMats,params));
fungrad = @(x) (GetGrad(net,x,SrcImg,SrcMats,params));
fun = @(x)fminunc_wrapper( x, funloss, fungrad);
tgtImg = lbfgsb_mywrapper(curTgtImg,initNoise,fun,net,params);
%% Save outputs
WriteResults(tgtImg,ImDenorm(SrcImg,net.meta.normalization.averageImage),params);