ivan@161
|
1 function reconstructed=ImageDenoise_reconstruct(y, Problem, SparseDict)
|
ivan@161
|
2 %% Image Denoising Problem reconstruction function
|
ivan@161
|
3 %
|
ivan@161
|
4 % This reconstruction function is using sparse representation y
|
ivan@161
|
5 % in dictionary Problem.A to reconstruct the patches of the denoised
|
ivan@161
|
6 % image.
|
ivan@161
|
7
|
ivan@161
|
8 %
|
ivan@161
|
9 % Centre for Digital Music, Queen Mary, University of London.
|
ivan@161
|
10 % This file copyright 2009 Ivan Damnjanovic.
|
ivan@161
|
11 %
|
ivan@161
|
12 % This program is free software; you can redistribute it and/or
|
ivan@161
|
13 % modify it under the terms of the GNU General Public License as
|
ivan@161
|
14 % published by the Free Software Foundation; either version 2 of the
|
ivan@161
|
15 % License, or (at your option) any later version. See the file
|
ivan@161
|
16 % COPYING included with this distribution for more information.
|
ivan@161
|
17 %%
|
ivan@161
|
18
|
ivan@161
|
19
|
ivan@161
|
20 % stepsize %
|
ivan@161
|
21 if (isfield(Problem,'stepsize'))
|
ivan@161
|
22 stepsize = Problem.stepsize;
|
ivan@161
|
23 if (numel(stepsize)==1)
|
ivan@161
|
24 stepsize = ones(1,2)*stepsize;
|
ivan@161
|
25 end
|
ivan@161
|
26 else
|
ivan@161
|
27 stepsize = ones(1,2);
|
ivan@161
|
28 end
|
ivan@161
|
29 if (any(stepsize<1))
|
ivan@161
|
30 error('Invalid step size.');
|
ivan@161
|
31 end
|
ivan@161
|
32
|
ivan@161
|
33 % lambda %
|
ivan@161
|
34 if (isfield(Problem,'lambda'))
|
ivan@161
|
35 lambda = Problem.lambda;
|
ivan@161
|
36 else
|
ivan@161
|
37 lambda = Problem.maxval/(10*Problem.sigma);
|
ivan@161
|
38 end
|
ivan@161
|
39 if exist('SparseDict','var')&&(SparseDict==1)
|
ivan@161
|
40 if issparse(Problem.A)
|
ivan@161
|
41 A = Problem.A;
|
ivan@161
|
42 else
|
ivan@161
|
43 A = sparse(Problem.A);
|
ivan@161
|
44 end
|
ivan@161
|
45 cl_samp=add_dc(dictsep(Problem.basedict,A,y), Problem.b1dc,'columns');
|
ivan@161
|
46 else
|
ivan@161
|
47 cl_samp=add_dc(Problem.A*y, Problem.b1dc,'columns');
|
ivan@161
|
48 end
|
ivan@161
|
49 % combine the patches into reconstructed image
|
ivan@161
|
50 cl_im=col2imstep(cl_samp, size(Problem.Noisy), Problem.blocksize);
|
ivan@161
|
51
|
ivan@161
|
52 cnt = countcover(size(Problem.Noisy),Problem.blocksize,stepsize);
|
ivan@161
|
53
|
ivan@161
|
54 im = (cl_im+lambda*Problem.Noisy)./(cnt + lambda);
|
ivan@161
|
55 % y(y~=0)=1;
|
ivan@161
|
56 % numD=sum(y,2);
|
ivan@161
|
57 % nnzy=sum(y,1);
|
ivan@161
|
58 % figure(200);plot(sort(numD));
|
ivan@161
|
59 % figure(201);plot(sort(nnzy));
|
ivan@161
|
60 [v.RMSErn, v.RMSEcd, v.rn_im, v.cd_im]=SMALL_vmrse_type2(Problem.Original, Problem.Noisy, im);
|
ivan@161
|
61 %% output structure image+psnr %%
|
ivan@161
|
62 reconstructed.Image=im;
|
ivan@161
|
63 reconstructed.psnr = 20*log10(Problem.maxval * sqrt(numel(Problem.Original(:))) / norm(Problem.Original(:)-im(:)));
|
ivan@161
|
64 reconstructed.vmrse=v;
|
ivan@161
|
65 reconstructed.ssim=SMALL_ssim_index(Problem.Original, im);
|
ivan@161
|
66 end |