inpaintSobolev

PURPOSE ^

SOBOLEV Inpainting of an "image" by iterative minimization of the Sobolev

SYNOPSIS ^

function imgInpainted = inpaintSobolev(img, mask, relTolerance, maxIters, outDemoVideo)

DESCRIPTION ^

SOBOLEV Inpainting of an "image" by iterative minimization of the Sobolev
   norm

 Input:
   img: input image to be inpainted
   mask: logical mask of the same size as the input image. 1 == known pixels, 0 == unknown pixels to be
         inpainted
   relTolerance: relative tolerance, stop the gradient descent when the energy descent between iterations is less than this value
   numIters: maximum number of gradient descent iterations to perform (default = 100000)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function imgInpainted = inpaintSobolev(img, mask, relTolerance, maxIters, outDemoVideo)
0002 %SOBOLEV Inpainting of an "image" by iterative minimization of the Sobolev
0003 %   norm
0004 %
0005 % Input:
0006 %   img: input image to be inpainted
0007 %   mask: logical mask of the same size as the input image. 1 == known pixels, 0 == unknown pixels to be
0008 %         inpainted
0009 %   relTolerance: relative tolerance, stop the gradient descent when the energy descent between iterations is less than this value
0010 %   numIters: maximum number of gradient descent iterations to perform (default = 100000)
0011 
0012 % Input parameters check
0013 if nargin < 3 || isempty(relTolerance)
0014     relTolerance = 1e-5;
0015 end
0016 if nargin < 4 || isempty(maxIters)
0017     maxIters = 100000;
0018 end
0019 createDemoVideo = false;
0020 if nargin > 4 && ~isempty(outDemoVideo)
0021    % Create the output video
0022    createDemoVideo = true;
0023    video = VideoWriter(outDemoVideo,'Motion JPEG AVI');
0024    video.Quality = 100;
0025    open(video);
0026    itersPerFrame = 10;
0027 end
0028 
0029 % Functors
0030 Pi = @(f)f.*(1-mask) + img.*mask;
0031 Delta = @(x)div(grad(x));
0032 norm1 = @(f)norm(f(:));
0033 
0034 % Gradient descent step size
0035 tau = .8/4;
0036 
0037 % Gradient descent iterations
0038 imgInpainted = img;
0039 energyPrev = 0;
0040 for i=1:maxIters
0041     energy = norm1(grad(imgInpainted));        
0042     imgInpainted = Pi( imgInpainted + tau*Delta(imgInpainted) );
0043     
0044     if abs(energy-energyPrev) < relTolerance
0045         break;
0046     end
0047     energyPrev = energy;
0048     
0049     % Save a frame of the video
0050     if createDemoVideo && mod(i-1, itersPerFrame) == 0
0051         imagesc(imgInpainted'); axis xy; colorbar;
0052         frame = getframe(gcf);        
0053         writeVideo(video, frame);
0054     end
0055 end
0056 
0057 if i == maxIters
0058     warning('Maximum number of iterations reached');
0059 end
0060 
0061 if createDemoVideo, close(video); end
0062 
0063 end

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