% Demo of fast nonconvex nonsmooth minimization methods clear close all format compact % Choose numerical scheme % 1. Numerical scheme based on fitting to f (Algorithm 1) % 2. Numerical scheme based on fitting to Df (Algorithm 2) % Otherwise both of the schemes algorithm = 3; % Read the original image I = imread('TwoCircles.tif'); I = double(I)/255; [m m1] = size(I); % Degradation parameters kernel_type = 'gaussian'; kernel_size = 7; kernel_std = 1.5; noise_std = 0.05; % Generate the observed image with blur and noise h = fspecial(kernel_type, kernel_size, kernel_std); Htf = imfilter(I, h, 'circular', 'same', 'conv'); noise = normrnd(0, noise_std, size(I)); g = Htf + noise; % Restoration parameters alpha_ep = 0.5; beta = 0.015; % Run the algorithm tOur = cputime; if algorithm == 1 final_sol = FNNMM1(g, h, alpha_ep, beta); elseif algorithm == 2 final_sol = FNNMM2(g, h, alpha_ep, beta); else tOur1 = cputime; final_sol1 = FNNMM1(g, h, alpha_ep, beta); tOur1 = cputime-tOur1; tOur2 = cputime; final_sol2 = FNNMM2(g, h, alpha_ep, beta); tOur2 = cputime-tOur2; end tOur = cputime-tOur; % Output the result observed_psnr = - 20*log10(sqrt(norm(g - I, 'fro')^2/m^2)); if algorithm == 1 || algorithm == 2 restored_psnr = - 20*log10(sqrt(norm(final_sol - I, 'fro')^2/m^2)); fprintf('\nAlgorithm %d:\n', algorithm); fprintf('Observed Psnr = %.2f, Restored Psnr = %.2f, CPU time = %.2f\n', observed_psnr, restored_psnr, tOur); else restored_psnr1 = - 20*log10(sqrt(norm(final_sol1 - I, 'fro')^2/m^2)); restored_psnr2 = - 20*log10(sqrt(norm(final_sol2 - I, 'fro')^2/m^2)); fprintf('\nAlgorithm 1:\n'); fprintf('Observed Psnr = %.2f, Restored Psnr = %.2f, CPU time = %.2f\n', observed_psnr, restored_psnr1, tOur1); fprintf('Algorithm 2:\n'); fprintf('Observed Psnr = %.2f, Restored Psnr = %.2f, CPU time = %.2f\n', observed_psnr, restored_psnr2, tOur2); end figure, imagesc(I, [0 1]) title('Original Image', 'fontsize', 20) colormap(gray); axis off; axis equal figure, imagesc(g, [0 1]) title(sprintf('Observed Image: PSNR = %.2f', observed_psnr), 'fontsize', 20) colormap(gray); axis off; axis equal if algorithm == 1 || algorithm == 2 figure, imagesc(final_sol, [0 1]) title(sprintf('Algorithm %d: PSRN = %.2f', algorithm, restored_psnr),'fontsize', 20) colormap(gray); axis off; axis equal else figure, imagesc(final_sol1, [0 1]) title(sprintf('Algorithm 1: PSRN = %.2f', restored_psnr1),'fontsize', 20) colormap(gray); axis off; axis equal figure, imagesc(final_sol2, [0 1]) title(sprintf('Algorithm 2: PSNR = %.2f', restored_psnr2),'fontsize', 20) colormap(gray); axis off; axis equal end