idamnjanovic@6: %% Pierre Villars Example idamnjanovic@6: % This example is based on the experiment suggested by Professor Pierre idamnjanovic@6: % Vandergheynst on the SMALL meeting in Villars. idamnjanovic@6: % The idea behind is to use patches from source image as a dictonary in idamnjanovic@6: % which we represent target image using matching pursuit algorithm. idamnjanovic@6: % Calling Pierre_Problem function to get src image to be used as dictionary idamnjanovic@6: % and target image to be represented using MP with 3 paches from source image idamnjanovic@6: % idamnjanovic@6: % idamnjanovic@6: % Ivan Damnjanovic 2010 idamnjanovic@6: %% idamnjanovic@6: idamnjanovic@6: clear all; idamnjanovic@6: idamnjanovic@6: % Defining the Problem structure idamnjanovic@6: idamnjanovic@6: SMALL.Problem = Pierre_Problem(); idamnjanovic@6: idamnjanovic@6: % Show original image and image that is used as a dictionary idamnjanovic@6: figure('Name', 'Original and Dictionary Image'); idamnjanovic@6: idamnjanovic@6: subplot(1,2,1); imshow(SMALL.Problem.imageTrg/SMALL.Problem.maxval); idamnjanovic@6: title('Original Image'); idamnjanovic@6: subplot(1,2,2); imshow(SMALL.Problem.imageSrc/SMALL.Problem.maxval); idamnjanovic@6: title('Dictionary image:'); idamnjanovic@6: idamnjanovic@6: % Using ten different dictionary sizes. First dictionary will contain all idamnjanovic@6: % patches from the source image and last one will have only idamnjanovic@6: % num_src_patches/2^9 atoms representing equidistant patches taken from idamnjanovic@6: % the source image. idamnjanovic@6: idamnjanovic@6: n =10; idamnjanovic@6: dictsize=zeros(1,n); idamnjanovic@6: time = zeros(1,n); idamnjanovic@6: psnr = zeros(1,n); idamnjanovic@6: idamnjanovic@6: for i=1:n idamnjanovic@6: idamnjanovic@6: idamnjanovic@6: % Set reconstruction function idamnjanovic@6: idamnjanovic@6: SMALL.Problem.reconstruct=@(x) Pierre_reconstruct(x, SMALL.Problem); idamnjanovic@6: idamnjanovic@6: SMALL.solver(i)=SMALL_init_solver; idamnjanovic@6: idamnjanovic@6: % Defining the parameters sparse representation idamnjanovic@6: idamnjanovic@6: SMALL.solver(i).toolbox='SMALL'; idamnjanovic@6: SMALL.solver(i).name='SMALL_MP'; idamnjanovic@6: idamnjanovic@6: % Parameters needed for matching pursuit (max number of atoms is 3 idamnjanovic@6: % and residual error goal is 1e14 idamnjanovic@6: idamnjanovic@6: SMALL.solver(i).param=sprintf('%d, 1e-14',3); idamnjanovic@6: idamnjanovic@6: % Represent the image using the source image patches as dictionary idamnjanovic@6: idamnjanovic@6: SMALL.solver(i)=SMALL_solve(SMALL.Problem, SMALL.solver(i)); idamnjanovic@6: idamnjanovic@6: idamnjanovic@6: dictsize(1,i) = size(SMALL.Problem.A,2); idamnjanovic@6: time(1,i) = SMALL.solver(i).time; idamnjanovic@6: psnr(1,i) = SMALL.solver(i).reconstructed.psnr; idamnjanovic@6: idamnjanovic@6: % Set new SMALL.Problem.A dictionary taking every second patch from idamnjanovic@6: % previous dictionary idamnjanovic@6: idamnjanovic@6: SMALL.Problem.A=SMALL.Problem.A(:,1:2:dictsize(1,i)); idamnjanovic@6: idamnjanovic@6: idamnjanovic@6: %% show reconstructed image %% idamnjanovic@6: figure('Name', sprintf('dictsize=%d', dictsize(1,i))); idamnjanovic@6: idamnjanovic@6: imshow(SMALL.solver(i).reconstructed.image/SMALL.Problem.maxval); idamnjanovic@6: title(sprintf('Reconstructed image, PSNR: %.2f dB in %.2f s',... idamnjanovic@6: SMALL.solver(i).reconstructed.psnr, SMALL.solver(i).time )); idamnjanovic@6: idamnjanovic@6: idamnjanovic@6: end idamnjanovic@6: idamnjanovic@6: %% plot time and psnr given dictionary size %% idamnjanovic@6: figure('Name', 'time and psnr'); idamnjanovic@6: idamnjanovic@6: subplot(1,2,1); plot(dictsize(1,:), time(1,:), 'ro-'); idamnjanovic@6: title('Time vs number of source image patches used'); idamnjanovic@6: subplot(1,2,2); plot(dictsize(1,:), psnr(1,:), 'b*-'); idamnjanovic@6: title('PSNR vs number of source image patches used');