comparison examples/Image Denoising/SMALL_ImgDenoise_DL_test_SPAMS_lambda.m @ 6:f72603404233

(none)
author idamnjanovic
date Mon, 22 Mar 2010 10:45:01 +0000
parents
children cbf3521c25eb
comparison
equal deleted inserted replaced
5:f44689e95ea4 6:f72603404233
1 %% DICTIONARY LEARNING FOR IMAGE DENOISING
2 % This file contains an example of how SMALLbox can be used to test different
3 % dictionary learning techniques in Image Denoising problem.
4 % This example can be used to test SPAMS for different values of
5 % parameter lambda. In no way it represents extensive testing of image
6 % denoising. It should only give an idea how SMALL structure can be used
7 % for testing.
8 %
9 % Ivan Damnjanovic 2010
10 %%
11
12 clear all;
13
14 %% Load an image
15 TMPpath=pwd;
16 FS=filesep;
17 [pathstr1, name, ext, versn] = fileparts(which('SMALLboxSetup.m'));
18 cd([pathstr1,FS,'data',FS,'images']);
19 [filename,pathname] = uigetfile({'*.png;'},'Select a file containin pre-calculated notes');
20 [pathstr, name, ext, versn] = fileparts(filename);
21 test_image = imread(filename);
22 test_image = double(test_image);
23 cd(TMPpath);
24 %%
25
26 % number of different values we want to test
27
28 n =4;
29
30 lambda=zeros(1,n);
31 time = zeros(2,n);
32 psnr = zeros(2,n);
33
34 for i=1:n
35
36 % Here we want to test time spent and quality of denoising for
37 % different lambda parameters.
38
39 lambda(i)=1+i*0.5;
40
41 % Defining Image Denoising Problem as Dictionary Learning Problem.
42
43 SMALL.Problem = generateImageDenoiseProblem(test_image);
44 SMALL.Problem.name=name;
45 %%
46 % Use SPAMS Online Dictionary Learning Algorithm
47 % to Learn overcomplete dictionary (Julien Mairal 2009)
48
49 % Initialising Dictionary structure
50 % Setting Dictionary structure fields (toolbox, name, param, D and time)
51 % to zero values
52
53 SMALL.DL(1)=SMALL_init_DL();
54
55 % Defining fields needed for dictionary learning
56
57 SMALL.DL(1).toolbox = 'SPAMS';
58 SMALL.DL(1).name = 'mexTrainDL';
59
60 % Type 'help mexTrainDL in MATLAB prompt for explanation of parameters.
61
62 SMALL.DL(1).param=struct(...
63 'D', SMALL.Problem.initdict,...
64 'K', SMALL.Problem.p,...
65 'lambda', lambda(i),...
66 'iter', 200,...
67 'mode', 3,...
68 'modeD', 0);
69
70 % Learn the dictionary
71
72 SMALL.DL(1) = SMALL_learn(SMALL.Problem, SMALL.DL(1));
73
74 % Set SMALL.Problem.A dictionary
75 % (backward compatiblity with SPARCO: solver structure communicate
76 % only with Problem structure, ie no direct communication between DL and
77 % solver structures)
78
79 SMALL.Problem.A = SMALL.DL(1).D;
80
81
82 %%
83 % Initialising solver structure
84 % Setting solver structure fields (toolbox, name, param, solution,
85 % reconstructed and time) to zero values
86
87 SMALL.solver(1)=SMALL_init_solver;
88
89 % Defining the parameters needed for sparse representation
90
91 SMALL.solver(1).toolbox='ompbox';
92 SMALL.solver(1).name='ompdenoise';
93
94 % Denoising the image - SMALL_denoise function is similar to SMALL_solve,
95 % but backward compatible with KSVD definition of denoising
96
97 SMALL.solver(1)=SMALL_denoise(SMALL.Problem, SMALL.solver(1));
98
99
100 %% show results %%
101 % This will show denoised image and dictionary for all lambdas. If you
102 % are not interested to see it and do not want clutter your screen
103 % comment following line
104
105 SMALL_ImgDeNoiseResult(SMALL);
106
107
108 time(1,i) = SMALL.DL(1).time;
109 psnr(1,i) = SMALL.solver(1).reconstructed.psnr;
110
111 clear SMALL
112 end
113
114 %% show time and psnr %%
115 figure('Name', 'SPAMS LAMBDA TEST');
116
117 subplot(1,2,1); plot(lambda, time(1,:), 'ro-');
118 title('time vs lambda');
119 subplot(1,2,2); plot(lambda, psnr(1,:), 'b*-');
120 title('PSNR vs lambda');
121