diff examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsRLSDLA.m @ 84:67aae1283973

comments to ksvd vs rls-dla
author Ivan <ivan.damnjanovic@eecs.qmul.ac.uk>
date Fri, 01 Apr 2011 14:27:44 +0100
parents 4302a91e6033
children fd1c32cda22c
line wrap: on
line diff
--- a/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsRLSDLA.m	Fri Apr 01 12:11:16 2011 +0100
+++ b/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsRLSDLA.m	Fri Apr 01 14:27:44 2011 +0100
@@ -54,6 +54,7 @@
 
 SMALL.Problem = generateImageDenoiseProblem(test_image(im_num).i, 40000, '',256, noise_level(noise_ind));
 SMALL.Problem.name=int2str(im_num);
+%   results structure is to store all results
 
 results(noise_ind,im_num).noisy_psnr=SMALL.Problem.noisy_psnr;
 
@@ -114,62 +115,32 @@
     'epsilon',Edata,...
     'maxatoms', maxatoms); 
 
-%   Denoising the image - SMALL_denoise function is similar to SMALL_solve,
-%   but backward compatible with KSVD definition of denoising
+%   Denoising the image - find the sparse solution in the learned
+%   dictionary for all patches in the image and the end it uses
+%   reconstruction function to reconstruct the patches and put them into a
+%   denoised image
 
 SMALL.solver(1)=SMALL_solve(SMALL.Problem, SMALL.solver(1));
+
+%   Show PSNR after reconstruction
+
 SMALL.solver(1).reconstructed.psnr
+
 %%
-% Use KSVDS Dictionary Learning Algorithm to denoise image
-
-%   Initialising solver structure
-%   Setting solver structure fields (toolbox, name, param, solution,
-%   reconstructed and time) to zero values
-% 
-% SMALL.DL(2)=SMALL_init_DL();
-% 
-% % Defining the parameters needed for dictionary learning
-% 
-% SMALL.DL(2).toolbox = 'KSVDS';
-% SMALL.DL(2).name = 'ksvds';
-% 
-% %   Defining the parameters for KSVDS
-% %   In this example we are learning 256 atoms in 20 iterations, so that
-% %   every patch in the training set can be represented with target error in
-% %   L2-norm (EDataS). We also impose "double sparsity" - dictionary itself
-% %   has to be sparse in the given base dictionary (Tdict - number of
-% %   nonzero elements per atom).
-% %   Type help ksvds in MATLAB prompt for more options.
-% 
-% 
-% SMALL.DL(2).param=struct(...
-%     'Edata', Edata, ...
-%     'Tdict', 6,...
-%     'stepsize', 1,...
-%     'dictsize', SMALL.Problem.p,...
-%     'iternum', 20,...
-%     'memusage', 'high');
-% SMALL.DL(2).param.initA = speye(SMALL.Problem.p);
-% SMALL.DL(2).param.basedict{1} = odctdict(8,16);
-% SMALL.DL(2).param.basedict{2} = odctdict(8,16);
-% 
-% % Learn the dictionary
-% 
-% SMALL.DL(2) = SMALL_learn(SMALL.Problem, SMALL.DL(2));
-
-%   Set SMALL.Problem.A dictionary and SMALL.Problem.basedictionary
-%   (backward compatiblity with SPARCO: solver structure communicate
-%   only with Problem structure, ie no direct communication between DL and
-%   solver structures)
+%   For comparison purposes we will denoise image with overcomplete DCT
+%   here
+%   Set SMALL.Problem.A dictionary to be oDCT (i.e. Problem.initdict -
+%   since initial dictionaruy is already set to be oDCT when generating the
+%   denoising problem
 
 SMALL.Problem.A = SMALL.Problem.initdict;
-% SMALL.Problem.basedict{1} = SMALL.DL(2).param.basedict{1};
-% SMALL.Problem.basedict{2} = SMALL.DL(2).param.basedict{2};
 SMALL.DL(2).D=SMALL.Problem.initdict;
+
+%   Setting up reconstruction function
+
 SparseDict=0;
 SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem, SparseDict);
 
-%%
 %   Initialising solver structure
 %   Setting solver structure fields (toolbox, name, param, solution,
 %   reconstructed and time) to zero values
@@ -184,15 +155,17 @@
     'epsilon',Edata,...
     'maxatoms', maxatoms); 
 
-%   Denoising the image - SMALL_denoise function is similar to SMALL_solve,
-%   but backward compatible with KSVD definition of denoising
-%   Pay attention that since implicit base dictionary is used, denoising
-%   can be much faster then using explicit dictionary in KSVD example.
+%   Denoising the image - find the sparse solution in the learned
+%   dictionary for all patches in the image and the end it uses
+%   reconstruction function to reconstruct the patches and put them into a
+%   denoised image
 
 SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2));
 %%
-
-for i =1:1
+% In the b1 field all patches from the image are stored. For RLS-DLA we
+% will first exclude all the patches that have l2 norm smaller then
+% threshold and then take min(40000, number_of_remaining_patches) in
+% ascending order as our training set (SMALL.Problem.b)
 
 X=SMALL.Problem.b1;
 X_norm=sqrt(sum(X.^2, 1));
@@ -209,6 +182,9 @@
 
 end
 
+%   Forgetting factor for RLS-DLA algorithm, in this case we are using
+%   fixed value
+
 lambda=0.9998
 
 %   Use Recursive Least Squares
@@ -231,118 +207,16 @@
     'forgettingMode', 'FIX',...
     'forgettingFactor', lambda);
 
-% %   Type 'help mexTrainDL in MATLAB prompt for explanation of parameters.
-% 
-% SMALL.DL(3).param=struct(...
-%     'D', SMALL.Problem.initdict,...
-%     'K', SMALL.Problem.p,...
-%     'lambda', 2,...
-%     'iter', 200,...
-%     'mode', 3, ...
-%     'modeD', 0);
-
-%   Learn the dictionary
 
 SMALL.DL(3) = SMALL_learn(SMALL.Problem, SMALL.DL(3));
-%SMALL.DL(3).D(:,1)=SMALL.DL(1).D(:,1);
-% 
-% %   Set SMALL.Problem.A dictionary
-% %   (backward compatiblity with SPARCO: solver structure communicate
-% %   only with Problem structure, ie no direct communication between DL and
-% %   solver structures)
-% 
-% 
-% 
-% %%
-% %   Initialising solver structure
-% %   Setting solver structure fields (toolbox, name, param, solution,
-% %   reconstructed and time) to zero values
-% SMALL.Problem.A = SMALL.DL(1).D;
-% SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem);
-% maxatoms=5;
-% SMALL.solver(3)=SMALL_init_solver;
-% 
-% % Defining the parameters needed for denoising
-% 
-% % SMALL.solver(3).toolbox='SPAMS';
-% % SMALL.solver(3).name='mexLasso';
-% % SMALL.solver(3).param=struct(...
-% %     'mode', 1, ...
-% %     'lambda',Edata*Edata,...
-% %     'L', maxatoms); 
-% % %   Denoising the image - SMALL_denoise function is similar to SMALL_solve,
-% % %   but backward compatible with KSVD definition of denoising
-% % 
-% % SMALL.solver(3)=SMALL_solve(SMALL.Problem, SMALL.solver(3));
-% SMALL.solver(3).toolbox='SMALL';
-% SMALL.solver(3).name='SMALL_cgp';
-% SMALL.solver(3).param=sprintf('%d, %.2f', maxatoms, sqrt(Edata));
-% %   Denoising the image - SMALL_denoise function is similar to SMALL_solve,
-% %   but backward compatible with KSVD definition of denoising
-% 
-% SMALL.solver(3)=SMALL_solve(SMALL.Problem, SMALL.solver(3));
-
-% %%
-% %   Use RLS-DLA 
-% 
-% %   Initialising Dictionary structure
-% %   Setting Dictionary structure fields (toolbox, name, param, D and time)
-% %   to zero values
-% 
-% SMALL.DL(3)=SMALL_init_DL();
-% 
-% %   Defining fields needed for dictionary learning
-% 
-% SMALL.DL(3).toolbox = 'mpv2';
-% SMALL.DL(3).name = 'rlsdla';
-% 
-% %   Type 'help mexTrainDL in MATLAB prompt for explanation of parameters.
-% 
-% SMALL.DL(3).param=struct(...
-%     'D', SMALL.Problem.initdict,...
-%     'K', SMALL.Problem.p,...
-%     'abs', Edata*Edata,...
-%     'lambda', 0.995,...
-%     'iternum',1);
-% 
-% %   Learn the dictionary
-% 
-% SMALL.DL(3) = SMALL_learn(SMALL.Problem, SMALL.DL(3));
-% 
-% %   Set SMALL.Problem.A dictionary
-% %   (backward compatiblity with SPARCO: solver structure communicate
-% %   only with Problem structure, ie no direct communication between DL and
-% %   solver structures)
-% 
-% 
-
-%%
-%   Initialising solver structure
-%   Setting solver structure fields (toolbox, name, param, solution,
-%   reconstructed and time) to zero values
-%SMALL.DL(3).D(:,225:256)=0;
-SMALL.Problem.A = SMALL.DL(3).D;
-SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem);
-%maxatoms=32;
-SMALL.solver(3)=SMALL_init_solver;
-
-% Defining the parameters needed for denoising
-
-% SMALL.solver(3).toolbox='SPAMS';
-% SMALL.solver(3).name='mexLasso';
-% SMALL.solver(3).param=struct(...
-%     'mode', 1, ...
-%     'lambda',Edata*Edata,...
-%     'L', maxatoms); 
-% %   Denoising the image - SMALL_denoise function is similar to SMALL_solve,
-% %   but backward compatible with KSVD definition of denoising
-% 
-% SMALL.solver(3)=SMALL_solve(SMALL.Problem, SMALL.solver(3));
 
 %   Initialising solver structure
 %   Setting solver structure fields (toolbox, name, param, solution,
 %   reconstructed and time) to zero values
 
+SMALL.Problem.A = SMALL.DL(3).D;
+SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem);
+
 SMALL.solver(3)=SMALL_init_solver;
 
 % Defining the parameters needed for image denoising
@@ -352,23 +226,17 @@
 SMALL.solver(3).param=struct(...
     'epsilon',Edata,...
     'maxatoms', maxatoms); 
-% SMALL.solver(3).toolbox='SPAMS';
-% SMALL.solver(3).name='mexLasso';
-% SMALL.solver(3).param=struct(...
-%     'mode', 2, ...
-%     'lambda',40,...
-%     'L', maxatoms); 
 
-%   Denoising the image - SMALL_denoise function is similar to SMALL_solve,
-%   but backward compatible with KSVD definition of denoising
 
 SMALL.solver(3)=SMALL_solve(SMALL.Problem, SMALL.solver(3));
-% Plot results and save midi files
+
 SMALL.solver(3).reconstructed.psnr
+
+
 % show results %
 
 SMALL_ImgDeNoiseResult(SMALL);
-end
+
 results(noise_ind,im_num).psnr.ksvd=SMALL.solver(1).reconstructed.psnr;
 results(noise_ind,im_num).psnr.odct=SMALL.solver(2).reconstructed.psnr;
 results(noise_ind,im_num).psnr.rlsdla=SMALL.solver(3).reconstructed.psnr;