comparison examples/Pierre Villars/Pierre_Villars_Example.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 %% Pierre Villars Example
2 % This example is based on the experiment suggested by Professor Pierre
3 % Vandergheynst on the SMALL meeting in Villars.
4 % The idea behind is to use patches from source image as a dictonary in
5 % which we represent target image using matching pursuit algorithm.
6 % Calling Pierre_Problem function to get src image to be used as dictionary
7 % and target image to be represented using MP with 3 paches from source image
8 %
9 %
10 % Ivan Damnjanovic 2010
11 %%
12
13 clear all;
14
15 % Defining the Problem structure
16
17 SMALL.Problem = Pierre_Problem();
18
19 % Show original image and image that is used as a dictionary
20 figure('Name', 'Original and Dictionary Image');
21
22 subplot(1,2,1); imshow(SMALL.Problem.imageTrg/SMALL.Problem.maxval);
23 title('Original Image');
24 subplot(1,2,2); imshow(SMALL.Problem.imageSrc/SMALL.Problem.maxval);
25 title('Dictionary image:');
26
27 % Using ten different dictionary sizes. First dictionary will contain all
28 % patches from the source image and last one will have only
29 % num_src_patches/2^9 atoms representing equidistant patches taken from
30 % the source image.
31
32 n =10;
33 dictsize=zeros(1,n);
34 time = zeros(1,n);
35 psnr = zeros(1,n);
36
37 for i=1:n
38
39
40 % Set reconstruction function
41
42 SMALL.Problem.reconstruct=@(x) Pierre_reconstruct(x, SMALL.Problem);
43
44 SMALL.solver(i)=SMALL_init_solver;
45
46 % Defining the parameters sparse representation
47
48 SMALL.solver(i).toolbox='SMALL';
49 SMALL.solver(i).name='SMALL_MP';
50
51 % Parameters needed for matching pursuit (max number of atoms is 3
52 % and residual error goal is 1e14
53
54 SMALL.solver(i).param=sprintf('%d, 1e-14',3);
55
56 % Represent the image using the source image patches as dictionary
57
58 SMALL.solver(i)=SMALL_solve(SMALL.Problem, SMALL.solver(i));
59
60
61 dictsize(1,i) = size(SMALL.Problem.A,2);
62 time(1,i) = SMALL.solver(i).time;
63 psnr(1,i) = SMALL.solver(i).reconstructed.psnr;
64
65 % Set new SMALL.Problem.A dictionary taking every second patch from
66 % previous dictionary
67
68 SMALL.Problem.A=SMALL.Problem.A(:,1:2:dictsize(1,i));
69
70
71 %% show reconstructed image %%
72 figure('Name', sprintf('dictsize=%d', dictsize(1,i)));
73
74 imshow(SMALL.solver(i).reconstructed.image/SMALL.Problem.maxval);
75 title(sprintf('Reconstructed image, PSNR: %.2f dB in %.2f s',...
76 SMALL.solver(i).reconstructed.psnr, SMALL.solver(i).time ));
77
78
79 end
80
81 %% plot time and psnr given dictionary size %%
82 figure('Name', 'time and psnr');
83
84 subplot(1,2,1); plot(dictsize(1,:), time(1,:), 'ro-');
85 title('Time vs number of source image patches used');
86 subplot(1,2,2); plot(dictsize(1,:), psnr(1,:), 'b*-');
87 title('PSNR vs number of source image patches used');