annotate examples/Pierre Villars/Pierre_Villars_Example.m @ 6:f72603404233

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