comparison examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsSPAMS.m @ 107:dab78a3598b6

changes to comments for couple of scripts
author Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk>
date Wed, 18 May 2011 11:50:12 +0100
parents cbf3521c25eb
children 8e660fd14774
comparison
equal deleted inserted replaced
85:fd1c32cda22c 107:dab78a3598b6
1 %% DICTIONARY LEARNING FOR IMAGE DENOISING 1 %% DICTIONARY LEARNING FOR IMAGE DENOISING
2 % 2
3 % Centre for Digital Music, Queen Mary, University of London.
4 % This file copyright 2009 Ivan Damnjanovic.
5 %
6 % This program is free software; you can redistribute it and/or
7 % modify it under the terms of the GNU General Public License as
8 % published by the Free Software Foundation; either version 2 of the
9 % License, or (at your option) any later version. See the file
10 % COPYING included with this distribution for more information.
11 % 3 %
12 % This file contains an example of how SMALLbox can be used to test different 4 % This file contains an example of how SMALLbox can be used to test different
13 % dictionary learning techniques in Image Denoising problem. 5 % dictionary learning techniques in Image Denoising problem.
14 % It calls generateImageDenoiseProblem that will let you to choose image, 6 % It calls generateImageDenoiseProblem that will let you to choose image,
15 % add noise and use noisy image to generate training set for dictionary 7 % add noise and use noisy image to generate training set for dictionary
23 % Report - CS, Technion, June 2009. 15 % Report - CS, Technion, June 2009.
24 % - SPAMS - J. Mairal, F. Bach, J. Ponce and G. Sapiro. Online 16 % - SPAMS - J. Mairal, F. Bach, J. Ponce and G. Sapiro. Online
25 % Dictionary Learning for Sparse Coding. International 17 % Dictionary Learning for Sparse Coding. International
26 % Conference on Machine Learning,Montreal, Canada, 2009 18 % Conference on Machine Learning,Montreal, Canada, 2009
27 % 19 %
20
21 %
22 % Centre for Digital Music, Queen Mary, University of London.
23 % This file copyright 2009 Ivan Damnjanovic.
24 %
25 % This program is free software; you can redistribute it and/or
26 % modify it under the terms of the GNU General Public License as
27 % published by the Free Software Foundation; either version 2 of the
28 % License, or (at your option) any later version. See the file
29 % COPYING included with this distribution for more information.
28 % 30 %
29 %% 31 %%
30 32
31 clear; 33 clear;
32 34
71 % every patch in the training set can be represented with target error in 73 % every patch in the training set can be represented with target error in
72 % L2-norm (EData) 74 % L2-norm (EData)
73 % Type help ksvd in MATLAB prompt for more options. 75 % Type help ksvd in MATLAB prompt for more options.
74 76
75 Edata=sqrt(prod(SMALL.Problem.blocksize)) * SMALL.Problem.sigma * SMALL.Problem.gain; 77 Edata=sqrt(prod(SMALL.Problem.blocksize)) * SMALL.Problem.sigma * SMALL.Problem.gain;
78 maxatoms = floor(prod(SMALL.Problem.blocksize)/2);
79
76 SMALL.DL(1).param=struct(... 80 SMALL.DL(1).param=struct(...
77 'Edata', Edata,... 81 'Edata', Edata,...
78 'initdict', SMALL.Problem.initdict,... 82 'initdict', SMALL.Problem.initdict,...
79 'dictsize', SMALL.Problem.p,... 83 'dictsize', SMALL.Problem.p,...
80 'iternum', 20,... 84 'iternum', 20,...
88 % (backward compatiblity with SPARCO: solver structure communicate 92 % (backward compatiblity with SPARCO: solver structure communicate
89 % only with Problem structure, ie no direct communication between DL and 93 % only with Problem structure, ie no direct communication between DL and
90 % solver structures) 94 % solver structures)
91 95
92 SMALL.Problem.A = SMALL.DL(1).D; 96 SMALL.Problem.A = SMALL.DL(1).D;
93 97 SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem);
94 98
95 %% 99 %%
96 % Initialising solver structure 100 % Initialising solver structure
97 % Setting solver structure fields (toolbox, name, param, solution, 101 % Setting solver structure fields (toolbox, name, param, solution,
98 % reconstructed and time) to zero values 102 % reconstructed and time) to zero values
100 SMALL.solver(1)=SMALL_init_solver; 104 SMALL.solver(1)=SMALL_init_solver;
101 105
102 % Defining the parameters needed for image denoising 106 % Defining the parameters needed for image denoising
103 107
104 SMALL.solver(1).toolbox='ompbox'; 108 SMALL.solver(1).toolbox='ompbox';
105 SMALL.solver(1).name='ompdenoise'; 109 SMALL.solver(1).name='omp2';
106 110 SMALL.solver(1).param=struct(...
107 % Denoising the image - SMALL_denoise function is similar to SMALL_solve, 111 'epsilon',Edata,...
108 % but backward compatible with KSVD definition of denoising 112 'maxatoms', maxatoms);
109 113
110 SMALL.solver(1)=SMALL_denoise(SMALL.Problem, SMALL.solver(1)); 114 % Denoising the image - find the sparse solution in the learned
115 % dictionary for all patches in the image and the end it uses
116 % reconstruction function to reconstruct the patches and put them into a
117 % denoised image
118
119 SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1));
120
121 % Show PSNR after reconstruction
122
123 SMALL.solver(1).reconstructed.psnr
111 124
112 %% 125 %%
113 % Use KSVDS Dictionary Learning Algorithm to denoise image 126 % Use KSVDS Dictionary Learning Algorithm to denoise image
114 127
115 % Initialising solver structure 128 % Initialising solver structure
154 167
155 SMALL.Problem.A = SMALL.DL(2).D; 168 SMALL.Problem.A = SMALL.DL(2).D;
156 SMALL.Problem.basedict{1} = SMALL.DL(2).param.basedict{1}; 169 SMALL.Problem.basedict{1} = SMALL.DL(2).param.basedict{1};
157 SMALL.Problem.basedict{2} = SMALL.DL(2).param.basedict{2}; 170 SMALL.Problem.basedict{2} = SMALL.DL(2).param.basedict{2};
158 171
159 %% 172 % Setting up reconstruction function
173
174 SparseDict=1;
175 SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem, SparseDict);
176
160 % Initialising solver structure 177 % Initialising solver structure
161 % Setting solver structure fields (toolbox, name, param, solution, 178 % Setting solver structure fields (toolbox, name, param, solution,
162 % reconstructed and time) to zero values 179 % reconstructed and time) to zero values
163 180
164 SMALL.solver(2)=SMALL_init_solver; 181 SMALL.solver(2)=SMALL_init_solver;
165 182
166 % Defining the parameters needed for image denoising 183 % Defining the parameters needed for image denoising
167 184
168 SMALL.solver(2).toolbox='ompsbox'; 185 SMALL.solver(2).toolbox='ompsbox';
169 SMALL.solver(2).name='ompsdenoise'; 186 SMALL.solver(2).name='omps2';
170 187 SMALL.solver(2).param=struct(...
171 % Denoising the image - SMALL_denoise function is similar to SMALL_solve, 188 'epsilon',Edata,...
172 % but backward compatible with KSVD definition of denoising 189 'maxatoms', maxatoms);
173 % Pay attention that since implicit base dictionary is used, denoising 190
174 % can be much faster then using explicit dictionary in KSVD example. 191 % Denoising the image - find the sparse solution in the learned
175 192 % dictionary for all patches in the image and the end it uses
176 SMALL.solver(2)=SMALL_denoise(SMALL.Problem, SMALL.solver(2)); 193 % reconstruction function to reconstruct the patches and put them into a
177 194 % denoised image
178 % %% 195
179 % % Use SPAMS Online Dictionary Learning Algorithm 196 SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2));
180 % % to Learn overcomplete dictionary (Julien Mairal 2009) 197
181 % % (If you have not installed SPAMS please comment the following two cells) 198 %%
182 % 199 % Use SPAMS Online Dictionary Learning Algorithm
183 % % Initialising Dictionary structure 200 % to Learn overcomplete dictionary (Julien Mairal 2009)
184 % % Setting Dictionary structure fields (toolbox, name, param, D and time) 201 % (If you have not installed SPAMS please comment the following two cells)
185 % % to zero values 202
186 % 203 % Initialising Dictionary structure
187 % SMALL.DL(3)=SMALL_init_DL(); 204 % Setting Dictionary structure fields (toolbox, name, param, D and time)
188 % 205 % to zero values
189 % % Defining fields needed for dictionary learning 206
190 % 207 SMALL.DL(3)=SMALL_init_DL();
191 % SMALL.DL(3).toolbox = 'SPAMS'; 208
192 % SMALL.DL(3).name = 'mexTrainDL'; 209 % Defining fields needed for dictionary learning
193 % 210
194 % % Type 'help mexTrainDL in MATLAB prompt for explanation of parameters. 211 SMALL.DL(3).toolbox = 'SPAMS';
195 % 212 SMALL.DL(3).name = 'mexTrainDL';
196 % SMALL.DL(3).param=struct(... 213
197 % 'D', SMALL.Problem.initdict,... 214 % Type 'help mexTrainDL in MATLAB prompt for explanation of parameters.
198 % 'K', SMALL.Problem.p,... 215
199 % 'lambda', 2,... 216 SMALL.DL(3).param=struct(...
200 % 'iter', 200,... 217 'D', SMALL.Problem.initdict,...
201 % 'mode', 3, ... 218 'K', SMALL.Problem.p,...
202 % 'modeD', 0); 219 'lambda', 2,...
203 % 220 'iter', 200,...
204 % % Learn the dictionary 221 'mode', 3, ...
205 % 222 'modeD', 0);
206 % SMALL.DL(3) = SMALL_learn(SMALL.Problem, SMALL.DL(3)); 223
207 % 224 % Learn the dictionary
208 % % Set SMALL.Problem.A dictionary 225
209 % % (backward compatiblity with SPARCO: solver structure communicate 226 SMALL.DL(3) = SMALL_learn(SMALL.Problem, SMALL.DL(3));
210 % % only with Problem structure, ie no direct communication between DL and 227
211 % % solver structures) 228 % Set SMALL.Problem.A dictionary
212 % 229 % (backward compatiblity with SPARCO: solver structure communicate
213 % SMALL.Problem.A = SMALL.DL(3).D; 230 % only with Problem structure, ie no direct communication between DL and
214 % 231 % solver structures)
215 % 232
216 % %% 233 SMALL.Problem.A = SMALL.DL(3).D;
217 % % Initialising solver structure 234
218 % % Setting solver structure fields (toolbox, name, param, solution, 235 % Setting up reconstruction function
219 % % reconstructed and time) to zero values 236
220 % 237 SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem);
221 % SMALL.solver(3)=SMALL_init_solver; 238
222 % 239 % Initialising solver structure
223 % % Defining the parameters needed for denoising 240 % Setting solver structure fields (toolbox, name, param, solution,
224 % 241 % reconstructed and time) to zero values
225 % SMALL.solver(3).toolbox='ompbox'; 242
226 % SMALL.solver(3).name='ompdenoise'; 243 SMALL.solver(3)=SMALL_init_solver;
227 % 244
228 % % Denoising the image - SMALL_denoise function is similar to SMALL_solve, 245 % Defining the parameters needed for image denoising
229 % % but backward compatible with KSVD definition of denoising 246
230 % 247 SMALL.solver(3).toolbox='ompbox';
231 % SMALL.solver(3)=SMALL_denoise(SMALL.Problem, SMALL.solver(3)); 248 SMALL.solver(3).name='omp2';
249 SMALL.solver(3).param=struct(...
250 'epsilon',Edata,...
251 'maxatoms', maxatoms);
252
253 % Denoising the image - find the sparse solution in the learned
254 % dictionary for all patches in the image and the end it uses
255 % reconstruction function to reconstruct the patches and put them into a
256 % denoised image
257
258 SMALL.solver(3)=SMALL_solve(SMALL.Problem, SMALL.solver(3));
232 259
233 %% 260 %%
234 % Plot results and save midi files 261 % Plot results and save midi files
235 262
236 % show results % 263 % show results %