comparison examples/Image Denoising/SMALL_ImgDenoise_DL_test_Training_size.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. 3
4 % This file copyright 20100 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 %
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
16 % learning. 8 % learning.
23 % Implementation of the K-SVD Algorithm using Batch Orthogonal 15 % Implementation of the K-SVD Algorithm using Batch Orthogonal
24 % Matching Pursuit", Technical Report - CS, Technion, April 2008. 16 % Matching Pursuit", Technical Report - CS, Technion, April 2008.
25 % - SPAMS - J. Mairal, F. Bach, J. Ponce and G. Sapiro. Online 17 % - SPAMS - J. Mairal, F. Bach, J. Ponce and G. Sapiro. Online
26 % Dictionary Learning for Sparse Coding. International 18 % Dictionary Learning for Sparse Coding. International
27 % Conference on Machine Learning,Montreal, Canada, 2009 19 % Conference on Machine Learning,Montreal, Canada, 2009
28 % 20
29 % 21 %
22 % Centre for Digital Music, Queen Mary, University of London.
23 % This file copyright 2010 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.%%
30 %% 30 %%
31 31
32 clear all; 32 clear all;
33 33
34 %% Load an image 34 %% Load an image
75 % every patch in the training set can be represented with target error in 75 % every patch in the training set can be represented with target error in
76 % L2-norm (EData) 76 % L2-norm (EData)
77 % Type help ksvd in MATLAB prompt for more options. 77 % Type help ksvd in MATLAB prompt for more options.
78 78
79 Edata=sqrt(prod(SMALL.Problem.blocksize)) * SMALL.Problem.sigma * SMALL.Problem.gain; 79 Edata=sqrt(prod(SMALL.Problem.blocksize)) * SMALL.Problem.sigma * SMALL.Problem.gain;
80 maxatoms = floor(prod(SMALL.Problem.blocksize)/2);
81
80 SMALL.DL(1).param=struct(... 82 SMALL.DL(1).param=struct(...
81 'Edata', Edata,... 83 'Edata', Edata,...
82 'initdict', SMALL.Problem.initdict,... 84 'initdict', SMALL.Problem.initdict,...
83 'dictsize', SMALL.Problem.p,... 85 'dictsize', SMALL.Problem.p,...
84 'iternum', 20); 86 'iternum', 20);
92 % (backward compatiblity with SPARCO: solver structure communicate 94 % (backward compatiblity with SPARCO: solver structure communicate
93 % only with Problem structure, ie no direct communication between DL and 95 % only with Problem structure, ie no direct communication between DL and
94 % solver structures) 96 % solver structures)
95 97
96 SMALL.Problem.A = SMALL.DL(1).D; 98 SMALL.Problem.A = SMALL.DL(1).D;
97 99 SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem);
98 100
99 %% 101 %%
100 % Initialising solver structure 102 % Initialising solver structure
101 % Setting solver structure fields (toolbox, name, param, solution, 103 % Setting solver structure fields (toolbox, name, param, solution,
102 % reconstructed and time) to zero values 104 % reconstructed and time) to zero values
105 SMALL.solver(1)=SMALL_init_solver; 107 SMALL.solver(1)=SMALL_init_solver;
106 108
107 % Defining the parameters needed for denoising 109 % Defining the parameters needed for denoising
108 110
109 SMALL.solver(1).toolbox='ompbox'; 111 SMALL.solver(1).toolbox='ompbox';
110 SMALL.solver(1).name='ompdenoise'; 112 SMALL.solver(1).name='omp2';
111 113
112 % Denoising the image - SMALL_denoise function is similar to SMALL_solve, 114 SMALL.solver(1).param=struct(...
113 % but backward compatible with KSVD definition of denoising 115 'epsilon',Edata,...
114 116 'maxatoms', maxatoms);
115 SMALL.solver(1)=SMALL_denoise(SMALL.Problem, SMALL.solver(1)); 117
118 % Denoising the image - find the sparse solution in the learned
119 % dictionary for all patches in the image and the end it uses
120 % reconstruction function to reconstruct the patches and put them into a
121 % denoised image
122
123 SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1));
124
125 % Show PSNR after reconstruction
126
127 SMALL.solver(1).reconstructed.psnr
128
116 129
117 %% 130 %%
118 % Use SPAMS Online Dictionary Learning Algorithm 131 % Use SPAMS Online Dictionary Learning Algorithm
119 % to Learn overcomplete dictionary (Julien Mairal 2009) 132 % to Learn overcomplete dictionary (Julien Mairal 2009)
120 % (If you have not installed SPAMS please comment the following two cells) 133 % (If you have not installed SPAMS please comment the following two cells)
148 % (backward compatiblity with SPARCO: solver structure communicate 161 % (backward compatiblity with SPARCO: solver structure communicate
149 % only with Problem structure, ie no direct communication between DL and 162 % only with Problem structure, ie no direct communication between DL and
150 % solver structures) 163 % solver structures)
151 164
152 SMALL.Problem.A = SMALL.DL(2).D; 165 SMALL.Problem.A = SMALL.DL(2).D;
153 166 SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem);
154 167
155 %% 168 %%
156 % Initialising solver structure 169 % Initialising solver structure
157 % Setting solver structure fields (toolbox, name, param, solution, 170 % Setting solver structure fields (toolbox, name, param, solution,
158 % reconstructed and time) to zero values 171 % reconstructed and time) to zero values
160 SMALL.solver(2)=SMALL_init_solver; 173 SMALL.solver(2)=SMALL_init_solver;
161 174
162 % Defining the parameters needed for denoising 175 % Defining the parameters needed for denoising
163 176
164 SMALL.solver(2).toolbox='ompbox'; 177 SMALL.solver(2).toolbox='ompbox';
165 SMALL.solver(2).name='ompdenoise'; 178 SMALL.solver(2).name='omp2';
166 179 SMALL.solver(2).param=struct(...
167 % Denoising the image - SMALL_denoise function is similar to SMALL_solve, 180 'epsilon',Edata,...
168 % but backward compatible with KSVD definition of denoising 181 'maxatoms', maxatoms);
169 182
170 SMALL.solver(2)=SMALL_denoise(SMALL.Problem, SMALL.solver(2)); 183 % Denoising the image - find the sparse solution in the learned
184 % dictionary for all patches in the image and the end it uses
185 % reconstruction function to reconstruct the patches and put them into a
186 % denoised image
187
188 SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2));
189
171 190
172 191
173 192
174 %% show results %% 193 %% show results %%
175 % This will show denoised images and dictionaries for all training sets. 194 % This will show denoised images and dictionaries for all training sets.