0001 function imgInpainted = inpaintCCST(img, mask, tension, relTolerance, maxIters)
0002
0003
0004
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
0013
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];
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];
0020
0021 f = img;
0022 for i=1:maxIters
0023 laplacian = conv2(f, laplace5pt, 'same');
0024 biharmonic = conv2(f, biharmonic13pt, 'same');
0025
0026
0027
0028 myfun = -1*(1-tension).*biharmonic - tension.*laplacian;
0029
0030
0031 fnew = Pi(f + tau*myfun);
0032
0033 diff = norm(fnew(:)-f(:))/norm(fnew(:));
0034
0035
0036 f = fnew;
0037
0038
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;