Mercurial > hg > smallbox
comparison examples/Image Denoising/SMALL_ImgDenoise_DL_test_TwoStep_KSVD_MOD_OLS_Mailhe.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 | |
children | f42aa8bcb82f |
comparison
equal
deleted
inserted
replaced
152:485747bf39e0 | 153:af307f247ac7 |
---|---|
1 %% Dictionary Learning for Image Denoising - KSVD vs Recursive Least Squares | |
2 % | |
3 % This file contains an example of how SMALLbox can be used to test different | |
4 % dictionary learning techniques in Image Denoising problem. | |
5 % It calls generateImageDenoiseProblem that will let you to choose image, | |
6 % add noise and use noisy image to generate training set for dictionary | |
7 % learning. | |
8 % Two dictionary learning techniques were compared: | |
9 % - KSVD - M. Elad, R. Rubinstein, and M. Zibulevsky, "Efficient | |
10 % Implementation of the K-SVD Algorithm using Batch Orthogonal | |
11 % Matching Pursuit", Technical Report - CS, Technion, April 2008. | |
12 % - RLS-DLA - Skretting, K.; Engan, K.; , "Recursive Least Squares | |
13 % Dictionary Learning Algorithm," Signal Processing, IEEE Transactions on, | |
14 % vol.58, no.4, pp.2121-2130, April 2010 | |
15 % | |
16 | |
17 | |
18 % Centre for Digital Music, Queen Mary, University of London. | |
19 % This file copyright 2011 Ivan Damnjanovic. | |
20 % | |
21 % This program is free software; you can redistribute it and/or | |
22 % modify it under the terms of the GNU General Public License as | |
23 % published by the Free Software Foundation; either version 2 of the | |
24 % License, or (at your option) any later version. See the file | |
25 % COPYING included with this distribution for more information. | |
26 % | |
27 %% | |
28 | |
29 | |
30 | |
31 % If you want to load the image outside of generateImageDenoiseProblem | |
32 % function uncomment following lines. This can be useful if you want to | |
33 % denoise more then one image for example. | |
34 % Here we are loading test_image.mat that contains structure with 5 images : lena, | |
35 % barbara,boat, house and peppers. | |
36 clear; | |
37 TMPpath=pwd; | |
38 FS=filesep; | |
39 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m')); | |
40 cd([pathstr1,FS,'data',FS,'images']); | |
41 load('test_image.mat'); | |
42 cd(TMPpath); | |
43 | |
44 % Deffining the noise levels that we want to test | |
45 | |
46 noise_level=[10 20 25 50 100]; | |
47 | |
48 % Here we loop through different noise levels and images | |
49 | |
50 for noise_ind=2:2 | |
51 for im_num=2:2 | |
52 | |
53 % Defining Image Denoising Problem as Dictionary Learning | |
54 % Problem. As an input we set the number of training patches. | |
55 | |
56 SMALL.Problem = generateImageDenoiseProblem(test_image(im_num).i, 40000, '',256, noise_level(noise_ind)); | |
57 SMALL.Problem.name=int2str(im_num); | |
58 | |
59 Edata=sqrt(prod(SMALL.Problem.blocksize)) * SMALL.Problem.sigma * SMALL.Problem.gain; | |
60 maxatoms = floor(prod(SMALL.Problem.blocksize)/2); | |
61 | |
62 | |
63 %% | |
64 % Use KSVD Dictionary Learning Algorithm to Learn overcomplete dictionary | |
65 % Boris Mailhe ksvd update implentation omp is the same as with Rubinstein | |
66 % implementation | |
67 | |
68 | |
69 % Initialising solver structure | |
70 % Setting solver structure fields (toolbox, name, param, solution, | |
71 % reconstructed and time) to zero values | |
72 | |
73 SMALL.solver(1)=SMALL_init_solver; | |
74 | |
75 % Defining the parameters needed for image denoising | |
76 | |
77 SMALL.solver(1).toolbox='ompbox'; | |
78 SMALL.solver(1).name='omp2'; | |
79 SMALL.solver(1).param=struct(... | |
80 'epsilon',Edata,... | |
81 'maxatoms', maxatoms); | |
82 | |
83 % Initialising Dictionary structure | |
84 % Setting Dictionary structure fields (toolbox, name, param, D and time) | |
85 % to zero values | |
86 | |
87 SMALL.DL(1)=SMALL_init_DL('TwoStepDL', 'KSVD', '', 1); | |
88 | |
89 | |
90 % Defining the parameters for KSVD | |
91 % In this example we are learning 256 atoms in 20 iterations, so that | |
92 % every patch in the training set can be represented with target error in | |
93 % L2-norm (EData) | |
94 % Type help ksvd in MATLAB prompt for more options. | |
95 | |
96 | |
97 SMALL.DL(1).param=struct(... | |
98 'solver', SMALL.solver(1),... | |
99 'initdict', SMALL.Problem.initdict,... | |
100 'dictsize', SMALL.Problem.p,... | |
101 'iternum', 20,... | |
102 'show_dict', 1); | |
103 | |
104 % Learn the dictionary | |
105 | |
106 SMALL.DL(1) = SMALL_learn(SMALL.Problem, SMALL.DL(1)); | |
107 | |
108 % Set SMALL.Problem.A dictionary | |
109 % (backward compatiblity with SPARCO: solver structure communicate | |
110 % only with Problem structure, ie no direct communication between DL and | |
111 % solver structures) | |
112 | |
113 SMALL.Problem.A = SMALL.DL(1).D; | |
114 SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); | |
115 | |
116 % Denoising the image - find the sparse solution in the learned | |
117 % dictionary for all patches in the image and the end it uses | |
118 % reconstruction function to reconstruct the patches and put them into a | |
119 % denoised image | |
120 | |
121 SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1)); | |
122 | |
123 %% | |
124 % Use MOD Dictionary Learning Algorithm to Learn overcomplete dictionary | |
125 % Boris Mailhe MOD update implentation omp is the Ron Rubinstein | |
126 % implementation | |
127 | |
128 | |
129 % Initialising solver structure | |
130 % Setting solver structure fields (toolbox, name, param, solution, | |
131 % reconstructed and time) to zero values | |
132 | |
133 SMALL.solver(2)=SMALL_init_solver; | |
134 | |
135 % Defining the parameters needed for image denoising | |
136 | |
137 SMALL.solver(2).toolbox='ompbox'; | |
138 SMALL.solver(2).name='omp2'; | |
139 SMALL.solver(2).param=struct(... | |
140 'epsilon',Edata,... | |
141 'maxatoms', maxatoms); | |
142 | |
143 % Initialising Dictionary structure | |
144 % Setting Dictionary structure fields (toolbox, name, param, D and time) | |
145 % to zero values | |
146 | |
147 SMALL.DL(2)=SMALL_init_DL('TwoStepDL', 'MOD', '', 1); | |
148 | |
149 | |
150 % Defining the parameters for MOD | |
151 % In this example we are learning 256 atoms in 20 iterations, so that | |
152 % every patch in the training set can be represented with target error in | |
153 % L2-norm (EData) | |
154 % Type help ksvd in MATLAB prompt for more options | |
155 | |
156 SMALL.DL(2).param=struct(... | |
157 'solver', SMALL.solver(2),... | |
158 'initdict', SMALL.Problem.initdict,... | |
159 'dictsize', SMALL.Problem.p,... | |
160 'iternum', 20,... | |
161 'show_dict', 1); | |
162 | |
163 % Learn the dictionary | |
164 | |
165 SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2)); | |
166 | |
167 % Set SMALL.Problem.A dictionary | |
168 % (backward compatiblity with SPARCO: solver structure communicate | |
169 % only with Problem structure, ie no direct communication between DL and | |
170 % solver structures) | |
171 | |
172 SMALL.Problem.A = SMALL.DL(2).D; | |
173 SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); | |
174 | |
175 % Denoising the image - find the sparse solution in the learned | |
176 % dictionary for all patches in the image and the end it uses | |
177 % reconstruction function to reconstruct the patches and put them into a | |
178 % denoised image | |
179 | |
180 SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2)); | |
181 %% | |
182 % Use OLS Dictionary Learning Algorithm to Learn overcomplete dictionary | |
183 % Boris Mailhe ksvd update implentation omp is the Ron Rubinstein | |
184 % implementation | |
185 | |
186 | |
187 % Initialising solver structure | |
188 % Setting solver structure fields (toolbox, name, param, solution, | |
189 % reconstructed and time) to zero values | |
190 | |
191 SMALL.solver(3)=SMALL_init_solver; | |
192 | |
193 % Defining the parameters needed for image denoising | |
194 | |
195 SMALL.solver(3).toolbox='ompbox'; | |
196 SMALL.solver(3).name='omp2'; | |
197 SMALL.solver(3).param=struct(... | |
198 'epsilon',Edata,... | |
199 'maxatoms', maxatoms); | |
200 | |
201 % Initialising Dictionary structure | |
202 % Setting Dictionary structure fields (toolbox, name, param, D and time) | |
203 % to zero values | |
204 | |
205 SMALL.DL(3)=SMALL_init_DL('TwoStepDL', 'ols', '', 1); | |
206 | |
207 | |
208 % Defining the parameters for KSVD | |
209 % In this example we are learning 256 atoms in 20 iterations, so that | |
210 % every patch in the training set can be represented with target error in | |
211 % L2-norm (EData) | |
212 % Type help ksvd in MATLAB prompt for more options. | |
213 | |
214 | |
215 SMALL.DL(3).param=struct(... | |
216 'solver', SMALL.solver(3),... | |
217 'initdict', SMALL.Problem.initdict,... | |
218 'dictsize', SMALL.Problem.p,... | |
219 'iternum', 20,... | |
220 'learningRate', 0.1,... | |
221 'show_dict', 1); | |
222 | |
223 % Learn the dictionary | |
224 | |
225 SMALL.DL(3) = SMALL_learn(SMALL.Problem, SMALL.DL(3)); | |
226 | |
227 % Set SMALL.Problem.A dictionary | |
228 % (backward compatiblity with SPARCO: solver structure communicate | |
229 % only with Problem structure, ie no direct communication between DL and | |
230 % solver structures) | |
231 | |
232 SMALL.Problem.A = SMALL.DL(3).D; | |
233 SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); | |
234 | |
235 % Denoising the image - find the sparse solution in the learned | |
236 % dictionary for all patches in the image and the end it uses | |
237 % reconstruction function to reconstruct the patches and put them into a | |
238 % denoised image | |
239 | |
240 SMALL.solver(3)=SMALL_solve(SMALL.Problem, SMALL.solver(3)); | |
241 %% | |
242 % Use Mailhe Dictionary Learning Algorithm to Learn overcomplete dictionary | |
243 % Boris Mailhe ksvd update implentation omp is the Ron Rubinstein | |
244 % implementation | |
245 | |
246 | |
247 % Initialising solver structure | |
248 % Setting solver structure fields (toolbox, name, param, solution, | |
249 % reconstructed and time) to zero values | |
250 | |
251 SMALL.solver(4)=SMALL_init_solver; | |
252 | |
253 % Defining the parameters needed for image denoising | |
254 | |
255 SMALL.solver(4).toolbox='ompbox'; | |
256 SMALL.solver(4).name='omp2'; | |
257 SMALL.solver(4).param=struct(... | |
258 'epsilon',Edata,... | |
259 'maxatoms', maxatoms); | |
260 | |
261 % Initialising Dictionary structure | |
262 % Setting Dictionary structure fields (toolbox, name, param, D and time) | |
263 % to zero values | |
264 | |
265 SMALL.DL(4)=SMALL_init_DL('TwoStepDL', 'mailhe', '', 1); | |
266 | |
267 | |
268 % Defining the parameters for KSVD | |
269 % In this example we are learning 256 atoms in 20 iterations, so that | |
270 % every patch in the training set can be represented with target error in | |
271 % L2-norm (EData) | |
272 % Type help ksvd in MATLAB prompt for more options. | |
273 | |
274 | |
275 SMALL.DL(4).param=struct(... | |
276 'solver', SMALL.solver(4),... | |
277 'initdict', SMALL.Problem.initdict,... | |
278 'dictsize', SMALL.Problem.p,... | |
279 'iternum', 20,... | |
280 'learningRate', 2,... | |
281 'show_dict', 1); | |
282 | |
283 % Learn the dictionary | |
284 | |
285 SMALL.DL(4) = SMALL_learn(SMALL.Problem, SMALL.DL(4)); | |
286 | |
287 % Set SMALL.Problem.A dictionary | |
288 % (backward compatiblity with SPARCO: solver structure communicate | |
289 % only with Problem structure, ie no direct communication between DL and | |
290 % solver structures) | |
291 | |
292 SMALL.Problem.A = SMALL.DL(4).D; | |
293 SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem); | |
294 | |
295 % Denoising the image - find the sparse solution in the learned | |
296 % dictionary for all patches in the image and the end it uses | |
297 % reconstruction function to reconstruct the patches and put them into a | |
298 % denoised image | |
299 | |
300 SMALL.solver(4)=SMALL_solve(SMALL.Problem, SMALL.solver(4)); | |
301 | |
302 %% show results %% | |
303 | |
304 SMALL_ImgDeNoiseResult(SMALL); | |
305 | |
306 %clear SMALL; | |
307 end | |
308 end | |
309 |