comparison DL/two-step DL/SMALL_two_step_DL.m @ 153:af307f247ac7 ivand_dev

Example scripts for Two Step Dictionary Learning - Image Denoising experiments.
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Fri, 29 Jul 2011 12:35:52 +0100
parents 485747bf39e0
children a4d0977d4595 759313488e7b
comparison
equal deleted inserted replaced
152:485747bf39e0 153:af307f247ac7
83 decorrelate = 0; 83 decorrelate = 0;
84 end 84 end
85 85
86 % show dictonary every specified number of iterations 86 % show dictonary every specified number of iterations
87 87
88 if (isfield(DL.param,'show_dict')) 88 if isfield(DL.param,'show_dict')
89 show_dictionary=1; 89 show_dictionary=1;
90 show_iter=DL.param.show_dict; 90 show_iter=DL.param.show_dict;
91 else 91 else
92 show_dictionary=0; 92 show_dictionary=0;
93 show_iter=0; 93 show_iter=0;
98 % version of software we store the signal that needs to be represented 98 % version of software we store the signal that needs to be represented
99 % (for example the whole image) 99 % (for example the whole image)
100 100
101 tmpTraining = Problem.b1; 101 tmpTraining = Problem.b1;
102 Problem.b1 = sig; 102 Problem.b1 = sig;
103 Problem = rmfield(Problem, 'reconstruct'); 103 if isfield(Problem,'reconstruct')
104 Problem = rmfield(Problem, 'reconstruct');
105 end
104 solver.profile = 0; 106 solver.profile = 0;
105 107
106 % main loop % 108 % main loop %
107 109
108 for i = 1:iternum 110 for i = 1:iternum
111 Problem.A = dico;
109 solver = SMALL_solve(Problem, solver); 112 solver = SMALL_solve(Problem, solver);
110 [dico, solver.solution] = dico_update(dico, sig, solver.solution, ... 113 [dico, solver.solution] = dico_update(dico, sig, solver.solution, ...
111 typeUpdate, flow, learningRate); 114 typeUpdate, flow, learningRate);
112 if (decorrelate) 115 if (decorrelate)
113 dico = dico_decorr(dico, mu, solver.solution); 116 dico = dico_decorr(dico, mu, solver.solution);
114 end 117 end
115 Problem.A = dico; 118
116 if ((show_dictionary)&&(mod(i,show_iter)==0)) 119 if ((show_dictionary)&&(mod(i,show_iter)==0))
117 dictimg = SMALL_showdict(dico,[8 8],... 120 dictimg = SMALL_showdict(dico,[8 8],...
118 round(sqrt(size(dico,2))),round(sqrt(size(dico,2))),'lines','highcontrast'); 121 round(sqrt(size(dico,2))),round(sqrt(size(dico,2))),'lines','highcontrast');
119 figure(2); imagesc(dictimg);colormap(gray);axis off; axis image; 122 figure(2); imagesc(dictimg);colormap(gray);axis off; axis image;
120 pause(0.02); 123 pause(0.02);
123 126
124 Problem.b1 = tmpTraining; 127 Problem.b1 = tmpTraining;
125 DL.D = dico; 128 DL.D = dico;
126 129
127 end 130 end
131
132 function Y = colnorms_squared(X)
133
134 % compute in blocks to conserve memory
135 Y = zeros(1,size(X,2));
136 blocksize = 2000;
137 for i = 1:blocksize:size(X,2)
138 blockids = i : min(i+blocksize-1,size(X,2));
139 Y(blockids) = sum(X(:,blockids).^2);
140 end
141
142 end