annotate examples/Pierre Villars/Pierre_Villars_Example.m @ 217:8b3c71bb44eb luisf_dev

Removed "clear all" from example scripts (subs by "clear" instead)
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Thu, 22 Mar 2012 14:41:04 +0000
parents f42aa8bcb82f
children
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
luis@217 22 clear;
idamnjanovic@6 23
idamnjanovic@6 24 % Defining the Problem structure
idamnjanovic@6 25
ivan@161 26 SMALL.Problem = generatePierreProblem();
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 % Set reconstruction function
idamnjanovic@6 48
idamnjanovic@6 49 SMALL.Problem.reconstruct=@(x) Pierre_reconstruct(x, SMALL.Problem);
idamnjanovic@6 50
idamnjanovic@6 51 % Defining the parameters sparse representation
idamnjanovic@30 52 SMALL.solver(i)=SMALL_init_solver;
idamnjanovic@6 53 SMALL.solver(i).toolbox='SMALL';
idamnjanovic@6 54 SMALL.solver(i).name='SMALL_MP';
idamnjanovic@6 55
idamnjanovic@6 56 % Parameters needed for matching pursuit (max number of atoms is 3
idamnjanovic@30 57 % and residual error goal is 1e-14
idamnjanovic@6 58
idamnjanovic@6 59 SMALL.solver(i).param=sprintf('%d, 1e-14',3);
idamnjanovic@6 60
idamnjanovic@6 61 % Represent the image using the source image patches as dictionary
idamnjanovic@6 62
idamnjanovic@6 63 SMALL.solver(i)=SMALL_solve(SMALL.Problem, SMALL.solver(i));
idamnjanovic@6 64
idamnjanovic@6 65
idamnjanovic@6 66 dictsize(1,i) = size(SMALL.Problem.A,2);
idamnjanovic@6 67 time(1,i) = SMALL.solver(i).time;
idamnjanovic@6 68 psnr(1,i) = SMALL.solver(i).reconstructed.psnr;
idamnjanovic@6 69
idamnjanovic@6 70 % Set new SMALL.Problem.A dictionary taking every second patch from
idamnjanovic@6 71 % previous dictionary
idamnjanovic@6 72
idamnjanovic@6 73 SMALL.Problem.A=SMALL.Problem.A(:,1:2:dictsize(1,i));
idamnjanovic@6 74
idamnjanovic@6 75
idamnjanovic@6 76 %% show reconstructed image %%
idamnjanovic@6 77 figure('Name', sprintf('dictsize=%d', dictsize(1,i)));
idamnjanovic@6 78
ivan@124 79 imagesc(SMALL.solver(i).reconstructed.image/SMALL.Problem.maxval);
idamnjanovic@6 80 title(sprintf('Reconstructed image, PSNR: %.2f dB in %.2f s',...
idamnjanovic@6 81 SMALL.solver(i).reconstructed.psnr, SMALL.solver(i).time ));
ivan@124 82 colormap(gray);axis off; axis image;
idamnjanovic@6 83
idamnjanovic@6 84 end
idamnjanovic@6 85
idamnjanovic@6 86 %% plot time and psnr given dictionary size %%
idamnjanovic@6 87 figure('Name', 'time and psnr');
idamnjanovic@6 88
idamnjanovic@6 89 subplot(1,2,1); plot(dictsize(1,:), time(1,:), 'ro-');
idamnjanovic@6 90 title('Time vs number of source image patches used');
idamnjanovic@6 91 subplot(1,2,2); plot(dictsize(1,:), psnr(1,:), 'b*-');
idamnjanovic@6 92 title('PSNR vs number of source image patches used');