Mercurial > hg > smallbox
comparison examples/MajorizationMinimization tests/SMALL_ImgDenoise_DL_test_KSVDvsMajorizationMinimization.m @ 164:4205744092e6 release_1.9
Merge from branch "ivand_dev"
author | Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk> |
---|---|
date | Wed, 07 Sep 2011 14:17:30 +0100 |
parents | f42aa8bcb82f |
children | 9c418bea7f6a |
comparison
equal
deleted
inserted
replaced
151:af5abc34a5e1 | 164:4205744092e6 |
---|---|
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 % | |
10 % - KSVD - M. Elad, R. Rubinstein, and M. Zibulevsky, "Efficient | |
11 % Implementation of the K-SVD Algorithm using Batch Orthogonal | |
12 % Matching Pursuit", Technical Report - CS, Technion, April 2008. | |
13 % | |
14 % - MMDL - M. Yaghoobi, T. Blumensath and M. Davies, "Dictionary Learning | |
15 % for Sparse Approximations with the Majorization Method", IEEE | |
16 % Trans. on Signal Processing, Vol. 57, No. 6, pp 2178-2191, 2009. | |
17 | |
18 | |
19 % Centre for Digital Music, Queen Mary, University of London. | |
20 % This file copyright 2011 Ivan Damnjanovic. | |
21 % | |
22 % This program is free software; you can redistribute it and/or | |
23 % modify it under the terms of the GNU General Public License as | |
24 % published by the Free Software Foundation; either version 2 of the | |
25 % License, or (at your option) any later version. See the file | |
26 % COPYING included with this distribution for more information. | |
27 % | |
28 %% | |
29 | |
30 | |
31 | |
32 % If you want to load the image outside of generateImageDenoiseProblem | |
33 % function uncomment following lines. This can be useful if you want to | |
34 % denoise more then one image for example. | |
35 % Here we are loading test_image.mat that contains structure with 5 images : lena, | |
36 % barbara,boat, house and peppers. | |
37 clear; | |
38 TMPpath=pwd; | |
39 FS=filesep; | |
40 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m')); | |
41 cd([pathstr1,FS,'data',FS,'images']); | |
42 load('test_image.mat'); | |
43 cd(TMPpath); | |
44 | |
45 % Deffining the noise levels that we want to test | |
46 | |
47 noise_level=[10 20 25 50 100]; | |
48 | |
49 % Here we loop through different noise levels and images | |
50 | |
51 for noise_ind=2:2 | |
52 for im_num=1:1 | |
53 | |
54 % Defining Image Denoising Problem as Dictionary Learning | |
55 % Problem. As an input we set the number of training patches. | |
56 | |
57 SMALL.Problem = generateImageDenoiseProblem(test_image(im_num).i, 40000, '',256, noise_level(noise_ind)); | |
58 SMALL.Problem.name=int2str(im_num); | |
59 | |
60 Edata=sqrt(prod(SMALL.Problem.blocksize)) * SMALL.Problem.sigma * SMALL.Problem.gain; | |
61 maxatoms = floor(prod(SMALL.Problem.blocksize)/2); | |
62 | |
63 % results structure is to store all results | |
64 | |
65 results(noise_ind,im_num).noisy_psnr=SMALL.Problem.noisy_psnr; | |
66 | |
67 %% | |
68 % Use KSVD Dictionary Learning Algorithm to Learn overcomplete dictionary | |
69 | |
70 % Initialising Dictionary structure | |
71 % Setting Dictionary structure fields (toolbox, name, param, D and time) | |
72 % to zero values | |
73 | |
74 SMALL.DL(1)=SMALL_init_DL(); | |
75 | |
76 % Defining the parameters needed for dictionary learning | |
77 | |
78 SMALL.DL(1).toolbox = 'KSVD'; | |
79 SMALL.DL(1).name = 'ksvd'; | |
80 | |
81 % Defining the parameters for KSVD | |
82 % In this example we are learning 256 atoms in 20 iterations, so that | |
83 % every patch in the training set can be represented with target error in | |
84 % L2-norm (Edata) | |
85 % Type help ksvd in MATLAB prompt for more options. | |
86 | |
87 | |
88 SMALL.DL(1).param=struct(... | |
89 'Edata', Edata,... | |
90 'initdict', SMALL.Problem.initdict,... | |
91 'dictsize', SMALL.Problem.p,... | |
92 'exact', 1, ... | |
93 'iternum', 20,... | |
94 'memusage', 'high'); | |
95 | |
96 % Learn the dictionary | |
97 | |
98 SMALL.DL(1) = SMALL_learn(SMALL.Problem, SMALL.DL(1)); | |
99 | |
100 % Set SMALL.Problem.A dictionary | |
101 % (backward compatiblity with SPARCO: solver structure communicate | |
102 % only with Problem structure, ie no direct communication between DL and | |
103 % solver structures) | |
104 | |
105 SMALL.Problem.A = SMALL.DL(1).D; | |
106 SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); | |
107 | |
108 %% | |
109 % Initialising solver structure | |
110 % Setting solver structure fields (toolbox, name, param, solution, | |
111 % reconstructed and time) to zero values | |
112 | |
113 SMALL.solver(1)=SMALL_init_solver; | |
114 | |
115 % Defining the parameters needed for image denoising | |
116 | |
117 SMALL.solver(1).toolbox='ompbox'; | |
118 SMALL.solver(1).name='omp2'; | |
119 SMALL.solver(1).param=struct(... | |
120 'epsilon',Edata,... | |
121 'maxatoms', maxatoms); | |
122 | |
123 % Denoising the image - find the sparse solution in the learned | |
124 % dictionary for all patches in the image and the end it uses | |
125 % reconstruction function to reconstruct the patches and put them into a | |
126 % denoised image | |
127 | |
128 SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1)); | |
129 | |
130 % Show PSNR after reconstruction | |
131 | |
132 SMALL.solver(1).reconstructed.psnr | |
133 | |
134 %% | |
135 % For comparison purposes we will denoise image with Majorization | |
136 % Minimization method | |
137 % | |
138 | |
139 % Initialising solver structure | |
140 % Setting solver structure fields (toolbox, name, param, solution, | |
141 % reconstructed and time) to zero values | |
142 | |
143 SMALL.solver(2)=SMALL_init_solver; | |
144 | |
145 % Defining the parameters needed for image denoising | |
146 | |
147 SMALL.solver(2).toolbox='ompbox'; | |
148 SMALL.solver(2).name='omp2'; | |
149 SMALL.solver(2).param=struct(... | |
150 'epsilon',Edata,... | |
151 'maxatoms', maxatoms); | |
152 | |
153 % Initialising Dictionary structure | |
154 % Setting Dictionary structure fields (toolbox, name, param, D and time) | |
155 % to zero values | |
156 | |
157 SMALL.DL(2)=SMALL_init_DL('MMbox', 'MM_cn', '', 1); | |
158 | |
159 | |
160 % Defining the parameters for MOD | |
161 % In this example we are learning 256 atoms in 20 iterations, so that | |
162 % every patch in the training set can be represented with target error in | |
163 % L2-norm (EData) | |
164 % Type help ksvd in MATLAB prompt for more options. | |
165 | |
166 | |
167 SMALL.DL(2).param=struct(... | |
168 'solver', SMALL.solver(2),... | |
169 'initdict', SMALL.Problem.initdict,... | |
170 'dictsize', SMALL.Problem.p,... | |
171 'iternum', 20,... | |
172 'iterDictUpdate', 1000,... | |
173 'epsDictUpdate', 1e-7,... | |
174 'cvset',0,... | |
175 'show_dict', 0); | |
176 | |
177 % Learn the dictionary | |
178 | |
179 SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2)); | |
180 | |
181 % Set SMALL.Problem.A dictionary | |
182 % (backward compatiblity with SPARCO: solver structure communicate | |
183 % only with Problem structure, ie no direct communication between DL and | |
184 % solver structures) | |
185 | |
186 SMALL.Problem.A = SMALL.DL(2).D; | |
187 SMALL.Problem.reconstruct = @(x) ImageDenoise_reconstruct(x, SMALL.Problem); | |
188 | |
189 % Denoising the image - find the sparse solution in the learned | |
190 % dictionary for all patches in the image and the end it uses | |
191 % reconstruction function to reconstruct the patches and put them into a | |
192 % denoised image | |
193 | |
194 SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2)); | |
195 | |
196 | |
197 | |
198 % show results % | |
199 | |
200 SMALL_ImgDeNoiseResult(SMALL); | |
201 | |
202 results(noise_ind,im_num).psnr.ksvd=SMALL.solver(1).reconstructed.psnr; | |
203 results(noise_ind,im_num).psnr.odct=SMALL.solver(2).reconstructed.psnr; | |
204 results(noise_ind,im_num).vmrse.ksvd=SMALL.solver(1).reconstructed.vmrse; | |
205 results(noise_ind,im_num).vmrse.odct=SMALL.solver(2).reconstructed.vmrse; | |
206 results(noise_ind,im_num).ssim.ksvd=SMALL.solver(1).reconstructed.ssim; | |
207 results(noise_ind,im_num).ssim.odct=SMALL.solver(2).reconstructed.ssim; | |
208 | |
209 | |
210 results(noise_ind,im_num).time.ksvd=SMALL.solver(1).time+SMALL.DL(1).time; | |
211 | |
212 %clear SMALL; | |
213 end | |
214 end | |
215 % save results.mat results |