annotate examples/Pierre Villars/Pierre_Villars_Example.m @ 30:dc6aaa255836

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