inpaintCCST

PURPOSE ^

INPAINTCCST Inpaint with continous curvature splines in tension

SYNOPSIS ^

function imgInpainted = inpaintCCST(img, mask, tension, relTolerance, maxIters)

DESCRIPTION ^

INPAINTCCST Inpaint with continous curvature splines in tension

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function imgInpainted = inpaintCCST(img, mask, tension, relTolerance, maxIters)
0002 %INPAINTCCST Inpaint with continous curvature splines in tension
0003 
0004 % Input parameters check
0005 if nargin < 4 || isempty(relTolerance)
0006     relTolerance = 1e-15;
0007 end
0008 if nargin < 5 || isempty(maxIters)
0009     maxIters = 1e8;
0010 end
0011 
0012 % Gradient descent step size
0013 % tau = .8/4;
0014 epsilon = 1e-1;
0015 tau = .9*epsilon/4;
0016 
0017 Pi = @(f)f.*(1-mask) + img.*mask;
0018 laplace5pt = [ 0 1 0; 1 -4 1; 0 1 0]; % Laplacian stencil
0019 biharmonic13pt = [0 0 1 0 0; 0 2 -8 2 0; 1 -8 20 -8 1; 0 2 -8 2 0; 0 0 1 0 0]; % Biharmonic stencil
0020 
0021 f = img;
0022 for i=1:maxIters
0023      laplacian = conv2(f, laplace5pt, 'same');
0024      biharmonic = conv2(f, biharmonic13pt, 'same');
0025 %     g1 = grad(f);
0026 %     g2 = grad(g1);
0027 
0028     myfun = -1*(1-tension).*biharmonic - tension.*laplacian;
0029     
0030 %     fnew = Pi(f + tau*myfun);
0031     fnew = Pi(f + tau*myfun);
0032     
0033     diff = norm(fnew(:)-f(:))/norm(fnew(:));
0034     
0035     % UPDATE
0036     f = fnew;
0037     
0038     % TEST EXIT CONDITION
0039     if diff<relTolerance
0040         break
0041     end
0042     
0043     imagesc(f'); axis xy; colorbar;   
0044 end
0045 
0046 if i == maxIters
0047     warning('Maximum number of iterations reached');
0048 end
0049 
0050 imgInpainted = f;

Generated on Thu 10-Dec-2020 17:34:27 by m2html © 2005