BertalmioInpainter

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 classdef BertalmioInpainter < FDPDEInpainter
0002     % Bertalmio et al. Inpainter, implementation of the method presented in:
0003     %     Marcelo Bertalmio, Guillermo Sapiro, Vincent Caselles, and Coloma Ballester. 2000. Image inpainting. In Proceedings of the 27th annual conference on Computer graphics and interactive techniques (SIGGRAPH ’00). ACM Press/Addison-Wesley Publishing Co., USA, 417–424. DOI:https://doi.org/10.1145/344779.344972
0004     
0005     
0006     properties
0007         laplacianStencil; % Laplacian stencil
0008         Kfx; % Forward differences in X kernel
0009         Kfy; % Forward differences in Y kernel
0010         Kbx; % Backward differences in X kernel
0011         Kby; % Backward differences in Y kernel
0012         Kxx; % Forward - Backward differences in X kernel
0013         Kyy; % Forward - Backward differences in Y kernel
0014         Kcx; % Centered differences in X kernel
0015         Kcy; % Centered differences in Y kernel
0016         curIter; % Internal counter for number of iterations
0017     end
0018     
0019     methods
0020         function obj = BertalmioInpainter(varargin)
0021             obj@FDPDEInpainter(varargin{:});
0022             
0023             % Compute the stencils
0024             obj.laplacianStencil = laplacian5PointsStencil(obj.hx, obj.hy);
0025             [obj.Kfx, obj.Kfy] = forwardDifferenceKernels(obj.hx, obj.hy);
0026             [obj.Kbx, obj.Kby] = backwardDifferenceKernels(obj.hx, obj.hy);
0027             obj.Kxx = obj.Kfx - obj.Kbx;
0028             obj.Kyy = obj.Kfy - obj.Kby;
0029             [obj.Kcx, obj.Kcy] = centeredDifferenceKernels(obj.hx, obj.hy);
0030         end
0031         
0032         function f = stepFun(obj, f, mask)            
0033             % First derivatives X/Y (gradient)
0034             ux = conv2(f, obj.Kfx, 'same');
0035             uy = conv2(f, obj.Kfy, 'same');
0036             
0037             % Normal field: perpendicular to gradient
0038             uxn = uy;
0039             uyn = -1*ux;
0040 %             uxn = -1*uy;
0041 %             uyn = ux;
0042             
0043             % And the gradient of the Laplacian
0044             laplacian = conv2(f, obj.laplacianStencil, 'same');
0045             lux = conv2(laplacian, obj.Kfx, 'same');
0046             luy = conv2(laplacian, obj.Kfy, 'same');
0047             
0048             % Normalize the direction fields
0049             normFactor = sqrt(uxn.^2 + uyn.^2 + 1e-15);
0050             uxn = uxn./normFactor;
0051             uyn = uyn./normFactor;
0052             normFactor = sqrt(lux.^2 + luy.^2 + 1e-15);
0053             lux = lux./normFactor;
0054             luy = luy./normFactor;
0055             
0056             f = -1.*((uxn.*lux) + (uyn.*luy));
0057         end
0058         
0059         
0060         function u = anisotropicDiffusion(obj, u, dt, numIters, eps, geps) 
0061             ux  = conv2(u, obj.Kcx, 'same');
0062             uy  = conv2(u, obj.Kcy, 'same');
0063             uxx = conv2(u, obj.Kxx, 'same');
0064             uyy = conv2(u, obj.Kyy, 'same');
0065             uxy = conv2(ux, obj.Kcy, 'same');
0066                 
0067             for i=1:numIters
0068                 sqNormGradient = ux.^2 + uy.^2 + eps;                
0069                 u = u + dt*geps*(uyy .* (ux.^2) + uxx .* (uy.^2) - 2.*ux.*uy.*uxy) / sqNormGradient;
0070             end
0071         end
0072     end
0073 end
0074

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