diff 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
line wrap: on
line diff
--- a/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsSPAMS.m	Tue Apr 05 17:03:26 2011 +0100
+++ b/examples/Image Denoising/SMALL_ImgDenoise_DL_test_KSVDvsSPAMS.m	Wed May 18 11:50:12 2011 +0100
@@ -1,13 +1,5 @@
 %% DICTIONARY LEARNING FOR IMAGE DENOISING
-%
-%   Centre for Digital Music, Queen Mary, University of London.
-%   This file copyright 2009 Ivan Damnjanovic.
-%
-%   This program is free software; you can redistribute it and/or
-%   modify it under the terms of the GNU General Public License as
-%   published by the Free Software Foundation; either version 2 of the
-%   License, or (at your option) any later version.  See the file
-%   COPYING included with this distribution for more information.
+
 %   
 %   This file contains an example of how SMALLbox can be used to test different
 %   dictionary learning techniques in Image Denoising problem.
@@ -25,6 +17,16 @@
 %               Dictionary Learning for Sparse Coding. International
 %               Conference on Machine Learning,Montreal, Canada, 2009
 %
+
+%
+%   Centre for Digital Music, Queen Mary, University of London.
+%   This file copyright 2009 Ivan Damnjanovic.
+%
+%   This program is free software; you can redistribute it and/or
+%   modify it under the terms of the GNU General Public License as
+%   published by the Free Software Foundation; either version 2 of the
+%   License, or (at your option) any later version.  See the file
+%   COPYING included with this distribution for more information.
 %
 %%
 
@@ -73,6 +75,8 @@
 %   Type help ksvd in MATLAB prompt for more options.
 
 Edata=sqrt(prod(SMALL.Problem.blocksize)) * SMALL.Problem.sigma * SMALL.Problem.gain;
+maxatoms = floor(prod(SMALL.Problem.blocksize)/2);
+
 SMALL.DL(1).param=struct(...
     'Edata', Edata,...
     'initdict', SMALL.Problem.initdict,...
@@ -90,7 +94,7 @@
 %   solver structures)
 
 SMALL.Problem.A = SMALL.DL(1).D;
-
+SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem);
 
 %%
 %   Initialising solver structure
@@ -102,12 +106,21 @@
 % Defining the parameters needed for image denoising
 
 SMALL.solver(1).toolbox='ompbox';
-SMALL.solver(1).name='ompdenoise';
+SMALL.solver(1).name='omp2';
+SMALL.solver(1).param=struct(...
+    '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_denoise(SMALL.Problem, SMALL.solver(1));
+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
@@ -156,7 +169,11 @@
 SMALL.Problem.basedict{1} = SMALL.DL(2).param.basedict{1};
 SMALL.Problem.basedict{2} = SMALL.DL(2).param.basedict{2};
 
-%%
+%   Setting up reconstruction function
+
+SparseDict=1;
+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
@@ -166,69 +183,79 @@
 % Defining the parameters needed for image denoising
 
 SMALL.solver(2).toolbox='ompsbox';
-SMALL.solver(2).name='ompsdenoise';
+SMALL.solver(2).name='omps2';
+SMALL.solver(2).param=struct(...
+    '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_denoise(SMALL.Problem, SMALL.solver(2));
+SMALL.solver(2)=SMALL_solve(SMALL.Problem, SMALL.solver(2));
 
-% %%
-% %   Use SPAMS Online Dictionary Learning Algorithm
-% %   to Learn overcomplete dictionary (Julien Mairal 2009)
-% %   (If you have not installed SPAMS please comment the following two cells)
-% 
-% %   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 = 'SPAMS';
-% SMALL.DL(3).name = 'mexTrainDL';
-% 
-% %   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));
-% 
-% %   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)
-% 
-% SMALL.Problem.A = SMALL.DL(3).D;
-% 
-% 
-% %%
-% %   Initialising solver structure
-% %   Setting solver structure fields (toolbox, name, param, solution,
-% %   reconstructed and time) to zero values
-% 
-% SMALL.solver(3)=SMALL_init_solver;
-% 
-% % Defining the parameters needed for denoising
-% 
-% SMALL.solver(3).toolbox='ompbox';
-% SMALL.solver(3).name='ompdenoise';
-% 
-% %   Denoising the image - SMALL_denoise function is similar to SMALL_solve,
-% %   but backward compatible with KSVD definition of denoising
-% 
-% SMALL.solver(3)=SMALL_denoise(SMALL.Problem, SMALL.solver(3));
+%%
+%   Use SPAMS Online Dictionary Learning Algorithm
+%   to Learn overcomplete dictionary (Julien Mairal 2009)
+%   (If you have not installed SPAMS please comment the following two cells)
+
+%   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 = 'SPAMS';
+SMALL.DL(3).name = 'mexTrainDL';
+
+%   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));
+
+%   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)
+
+SMALL.Problem.A = SMALL.DL(3).D;
+
+%   Setting up reconstruction function
+
+SMALL.Problem.reconstruct = @(x) ImgDenoise_reconstruct(x, SMALL.Problem);
+
+%   Initialising solver structure
+%   Setting solver structure fields (toolbox, name, param, solution,
+%   reconstructed and time) to zero values
+
+SMALL.solver(3)=SMALL_init_solver;
+
+% Defining the parameters needed for image denoising
+
+SMALL.solver(3).toolbox='ompbox';
+SMALL.solver(3).name='omp2';
+SMALL.solver(3).param=struct(...
+    'epsilon',Edata,...
+    'maxatoms', maxatoms); 
+
+%   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(3)=SMALL_solve(SMALL.Problem, SMALL.solver(3));
 
 %%
 % Plot results and save midi files