annotate Problems/ImgDenoise_reconstruct.m @ 80:16df822019f1

Setup script removed Sparco's RWT from the path
author Ivan <ivan.damnjanovic@eecs.qmul.ac.uk>
date Mon, 28 Mar 2011 12:07:07 +0100
parents b9465d2bb3b0
children 5b34af39bf9a 5b2ae0af72f9
rev   line source
idamnjanovic@45 1 function reconstructed=ImgDenoise_reconstruct(y, Problem, SparseDict)
idamnjanovic@45 2 %%% Pierre Villars Example - reconstruction function
idamnjanovic@45 3 %
idamnjanovic@45 4 % Centre for Digital Music, Queen Mary, University of London.
idamnjanovic@45 5 % This file copyright 2009 Ivan Damnjanovic.
idamnjanovic@45 6 %
idamnjanovic@45 7 % This program is free software; you can redistribute it and/or
idamnjanovic@45 8 % modify it under the terms of the GNU General Public License as
idamnjanovic@45 9 % published by the Free Software Foundation; either version 2 of the
idamnjanovic@45 10 % License, or (at your option) any later version. See the file
idamnjanovic@45 11 % COPYING included with this distribution for more information.
idamnjanovic@45 12 %
idamnjanovic@45 13 % This example is based on the experiment suggested by Professor Pierre
idamnjanovic@45 14 % Vandergheynst on the SMALL meeting in Villars.
idamnjanovic@45 15
idamnjanovic@45 16 % using sparse representation y in dictionary Problem.A reconstruct the
idamnjanovic@45 17 % patches from the target image
idamnjanovic@45 18
idamnjanovic@45 19 % stepsize %
idamnjanovic@45 20 if (isfield(Problem,'stepsize'))
idamnjanovic@45 21 stepsize = Problem.stepsize;
idamnjanovic@45 22 if (numel(stepsize)==1)
idamnjanovic@45 23 stepsize = ones(1,2)*stepsize;
idamnjanovic@45 24 end
idamnjanovic@45 25 else
idamnjanovic@45 26 stepsize = ones(1,2);
idamnjanovic@45 27 end
idamnjanovic@45 28 if (any(stepsize<1))
idamnjanovic@45 29 error('Invalid step size.');
idamnjanovic@45 30 end
idamnjanovic@45 31
idamnjanovic@45 32 % lambda %
idamnjanovic@45 33 if (isfield(Problem,'lambda'))
idamnjanovic@45 34 lambda = Problem.lambda;
idamnjanovic@45 35 else
idamnjanovic@45 36 lambda = Problem.maxval/(10*Problem.sigma);
idamnjanovic@45 37 end
idamnjanovic@45 38 if exist('SparseDict','var')&&(SparseDict==1)
idamnjanovic@45 39 if issparse(Problem.A)
idamnjanovic@45 40 A = Problem.A;
idamnjanovic@45 41 else
idamnjanovic@45 42 A = sparse(Problem.A);
idamnjanovic@45 43 end
idamnjanovic@45 44 cl_samp=add_dc(dictsep(Problem.basedict,A,y), Problem.b1dc,'columns');
idamnjanovic@45 45 else
idamnjanovic@45 46 cl_samp=add_dc(Problem.A*y, Problem.b1dc,'columns');
idamnjanovic@45 47 end
idamnjanovic@45 48 % combine the patches into reconstructed image
idamnjanovic@45 49 cl_im=col2imstep(cl_samp, size(Problem.Noisy), Problem.blocksize);
idamnjanovic@45 50
idamnjanovic@45 51 cnt = countcover(size(Problem.Noisy),Problem.blocksize,stepsize);
idamnjanovic@45 52
idamnjanovic@45 53 im = (cl_im+lambda*Problem.Noisy)./(cnt + lambda);
idamnjanovic@45 54 % y(y~=0)=1;
idamnjanovic@45 55 % numD=sum(y,2);
idamnjanovic@45 56 % nnzy=sum(y,1);
idamnjanovic@45 57 % figure(200);plot(sort(numD));
idamnjanovic@45 58 % figure(201);plot(sort(nnzy));
idamnjanovic@45 59 [v.RMSErn, v.RMSEcd, v.rn_im, v.cd_im]=vmrse_type2(Problem.Original, Problem.Noisy, im);
idamnjanovic@45 60 %% output structure image+psnr %%
idamnjanovic@45 61 reconstructed.Image=im;
idamnjanovic@45 62 reconstructed.psnr = 20*log10(Problem.maxval * sqrt(numel(Problem.Original(:))) / norm(Problem.Original(:)-im(:)));
idamnjanovic@45 63 reconstructed.vmrse=v;
idamnjanovic@45 64 reconstructed.ssim=ssim_index(Problem.Original, im);
idamnjanovic@45 65 end