clear; np = 8; I = double(checkerboard(np)); m = size(I,1); H = fspecial('gaussian',50,2); B = imfilter(I,H,'replicate'); subplot(221);imshow(I,[]); title('Original'); subplot(222);imshow(B,[]); title('Blurred'); tol = 1.e-2; maxit = 400; u0 = B(:); t = 2.e+2; if 1; t0 = cputime; [u1,iter,nf] = myGD(@TVL2B,u0,tol,maxit,u0,t,m,H); tcpu = cputime - t0; [f,g] = TVL2B(u1,u0,t,m,H); fprintf(' myGD: iter %3i, nf = %4i, tcpu = %6.2e\n',iter,nf,tcpu) fprintf(' myGD: f = %12.6e, norm(g) = %9.3e \n\n',f,norm(g)) end if exist('myCG'); t0 = cputime; [u2,iter,nf] = myCG(@TVL2B,u0,tol,maxit,u0,t,m,H); tcpu = cputime - t0; [f,g] = TVL2B(u2,u0,t,m,H); fprintf('myCG: iter %3i, nf = %4i, tcpu = %6.2e\n',iter,nf,tcpu) fprintf('myCG: f = %12.6e, norm(g) = %9.3e \n\n',f,norm(g)) end U = reshape(u1,m,m); subplot(223);imshow(U,[]); title('Deblurred by GD'); U = reshape(u2,m,m); subplot(224);imshow(U,[]); title('Deblurred by CG-PR');