annotate examples/Pierre Villars/Pierre_Villars_Example.m @ 124:436e6c044099 sup_158_IMG_Processing_toolbox_

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