ClassesClassesClassesClasses | | | | Operators

inpainting_anisoinpainting_anisoInpaintingAnisoinpainting_anisoInpaintingAnisoInpaintingAniso (Operator)


inpainting_anisoinpainting_anisoInpaintingAnisoinpainting_anisoInpaintingAnisoInpaintingAniso — Perform an inpainting by anisotropic diffusion.


inpainting_aniso(Image, Region : InpaintedImage : Mode, Contrast, Theta, Iterations, Rho : )

Herror inpainting_aniso(const Hobject Image, const Hobject Region, Hobject* InpaintedImage, const char* Mode, double Contrast, double Theta, const Hlong Iterations, double Rho)

Herror T_inpainting_aniso(const Hobject Image, const Hobject Region, Hobject* InpaintedImage, const Htuple Mode, const Htuple Contrast, const Htuple Theta, const Htuple Iterations, const Htuple Rho)

Herror inpainting_aniso(Hobject Image, Hobject Region, Hobject* InpaintedImage, const HTuple& Mode, const HTuple& Contrast, const HTuple& Theta, const HTuple& Iterations, const HTuple& Rho)

HImage HImage::InpaintingAniso(const HRegion& Region, const HTuple& Mode, const HTuple& Contrast, const HTuple& Theta, const HTuple& Iterations, const HTuple& Rho) const

HImageArray HImageArray::InpaintingAniso(const HRegion& Region, const HTuple& Mode, const HTuple& Contrast, const HTuple& Theta, const HTuple& Iterations, const HTuple& Rho) const

void InpaintingAniso(const HObject& Image, const HObject& Region, HObject* InpaintedImage, const HTuple& Mode, const HTuple& Contrast, const HTuple& Theta, const HTuple& Iterations, const HTuple& Rho)

HImage HImage::InpaintingAniso(const HRegion& Region, const HString& Mode, double Contrast, double Theta, Hlong Iterations, double Rho) const

HImage HImage::InpaintingAniso(const HRegion& Region, const char* Mode, double Contrast, double Theta, Hlong Iterations, double Rho) const

void HOperatorSetX.InpaintingAniso(
[in] IHUntypedObjectX* Image, [in] IHUntypedObjectX* Region, [out] IHUntypedObjectX*InpaintedImage, [in] VARIANT Mode, [in] VARIANT Contrast, [in] VARIANT Theta, [in] VARIANT Iterations, [in] VARIANT Rho)

IHImageX* HImageX.InpaintingAniso(
[in] IHRegionX* Region, [in] BSTR Mode, [in] double Contrast, [in] double Theta, [in] Hlong Iterations, [in] double Rho)

static void HOperatorSet.InpaintingAniso(HObject image, HObject region, out HObject inpaintedImage, HTuple mode, HTuple contrast, HTuple theta, HTuple iterations, HTuple rho)

HImage HImage.InpaintingAniso(HRegion region, string mode, double contrast, double theta, int iterations, double rho)


The operator inpainting_anisoinpainting_anisoInpaintingAnisoinpainting_anisoInpaintingAnisoInpaintingAniso uses the anisotropic diffusion according to the model of Perona and Malik, to continue image edges that cross the border of the region RegionRegionRegionRegionRegionregion and to connect them inside of RegionRegionRegionRegionRegionregion.

With this, the structure of the edges in RegionRegionRegionRegionRegionregion will be made consistent with the surrounding image matrix, so that an occlusion of errors or unwanted objects in the input image, a so called inpainting, is less visible to the human beholder, since there remain no obvious artefacts or smudges.

Considering the image as a gray value function u, the algorithm is a discretization of the partial differential equation

  u_t = div(g(|grad u|^2, c) grad u)

with the initial value u = u_0 defined by ImageImageImageImageImageimage at a time t_0 = 0. The equation is iterated IterationsIterationsIterationsIterationsIterationsiterations times in time steps of length ThetaThetaThetaThetaThetatheta, so that the output image InpaintedImageInpaintedImageInpaintedImageInpaintedImageInpaintedImageinpaintedImage contains the gray value function at the time IterationsIterationsIterationsIterationsIterationsiterations * ThetaThetaThetaThetaThetatheta .

The primary goal of the anisotropic diffusion, which is also referred to as nonlinear isotropic diffusion, is the elimination of image noise in constant image patches while preserving the edges in the image. The distinction between edges and constant patches is achieved using the threshold ContrastContrastContrastContrastContrastcontrast on the magnitude of the gray value differences between adjacent pixels. ContrastContrastContrastContrastContrastcontrast is referred to as the contrast parameter and is abbreviated with the letter c. If the edge information is distributed in an environment of the already existing edges by smoothing the edge amplitude matrix, it is furthermore possible to continue edges into the computation area RegionRegionRegionRegionRegionregion. The standard deviation of this smoothing process is determined by the parameter RhoRhoRhoRhoRhorho.

The algorithm used is basically the same as in the anisotropic diffusion filter anisotropic_diffusionanisotropic_diffusionAnisotropicDiffusionanisotropic_diffusionAnisotropicDiffusionAnisotropicDiffusion, except that here, border treatment is not done by mirroring the gray values at the border of RegionRegionRegionRegionRegionregion. Instead, this procedure is only applicable on regions that keep a distance of at least 3 pixels to the border of the image matrix of ImageImageImageImageImageimage, since the gray values on this band around RegionRegionRegionRegionRegionregion are used to define the boundary conditions for the respective differential equation and thus assure consistency with the neighborhood of RegionRegionRegionRegionRegionregion. Please note that the inpainting progress is restricted to those pixels that are included in the ROI of the input image ImageImageImageImageImageimage. If the ROI does not include the entire region RegionRegionRegionRegionRegionregion, a band around the intersection of RegionRegionRegionRegionRegionregion and the ROI is used to define the boundary values.

The result of the diffusion process depends on the gray values in the computation area of the input image ImageImageImageImageImageimage. It must be pointed out that already exisiting image edges are preserved within RegionRegionRegionRegionRegionregion. In particular, this holds for gray value jumps at the border of RegionRegionRegionRegionRegionregion, which can result for example from a previous inpainting with constant gray value. If the procedure is to be used for inpainting, it is recommended to apply the operator harmonic_interpolationharmonic_interpolationHarmonicInterpolationharmonic_interpolationHarmonicInterpolationHarmonicInterpolation first to remove all unwanted edges inside the computation area and to minimize the gray value difference between adjacent pixels, unless the input image already contains information inside RegionRegionRegionRegionRegionregion that should be preserved.

The variable diffusion coefficient g can be chosen to follow different monotonically decreasing functions with values between 0 and 1 and determines the response of the diffusion process to an edge. With the parameter ModeModeModeModeModemode, the following functions can be selected:

  g_1(x,c) = 1/sqrt( 1 + 2*x/c^2 )

Choosing the function g_1 by setting ModeModeModeModeModemode to 'parabolic'"parabolic""parabolic""parabolic""parabolic""parabolic" guarantees that the associated differential equation is parabolic, so that a well-posedness theory exists for the problem and the procedure is stable for an arbitrary step size ThetaThetaThetaThetaThetatheta. In this case however, there remains a slight diffusion even across edges of an amplitude larger than c.

  g_2(x,c) = 1/( 1 + (x/c^2) )

The choice of 'perona-malik'"perona-malik""perona-malik""perona-malik""perona-malik""perona-malik" for ModeModeModeModeModemode, as used in the publication of Perona and Malik, does not possess the theoretical properties of g_1, but in practice it has proved to be sufficiently stable and is thus widely used. The theoretical instability results in a slight sharpening of strong edges.

  g_3(x,c) = 1-exp(-C*c^8/x^4)

The function g_3 with the constant C=3.31488, proposed by Weickert, and selectable by setting ModeModeModeModeModemode to 'weickert'"weickert""weickert""weickert""weickert""weickert" is an improvement of g_2 with respect to edge sharpening. The transition between smoothing and sharpening happens very abruptly at x = c^2.

Furthermore, the choice of the value 'shock'"shock""shock""shock""shock""shock" is possible for ModeModeModeModeModemode to select a contrast invariant modification of the anisotropic diffusion. In this variant, the generation of edges is not achieved by variation of the diffusion coefficient g, but the constant coefficient g=1 and thus isotropic diffusion is used. Additionally, a shock filter of type

  u_t = -sgn(grad |grad u|) |grad u|

is applied, which, just like a negative diffusion coefficient, causes a sharpening of the edges, but works independent of the absolute value of |grad u|. In this mode, ContrastContrastContrastContrastContrastcontrast does not have the meaning of a contrast parameter, but specifies the ratio between the diffusion and the shock filter part applied at each iteration step. Hence, the value 0 would correspond to pure isotropic diffusion, as used in the operator isotropic_diffusionisotropic_diffusionIsotropicDiffusionisotropic_diffusionIsotropicDiffusionIsotropicDiffusion. The parameter is scaled in such a way that diffusion and sharpening cancel each other out for ContrastContrastContrastContrastContrastcontrast=1. A value ContrastContrastContrastContrastContrastcontrast>1 should not be used, since it would make the algorithm unstable.



ImageImageImageImageImageimage (input_object)  (multichannel-)image(-array) objectHImageHImageHImageHImageXHobject (byte / uint2 / real)

Input image.

RegionRegionRegionRegionRegionregion (input_object)  region objectHRegionHRegionHRegionHRegionXHobject

Inpainting region.

InpaintedImageInpaintedImageInpaintedImageInpaintedImageInpaintedImageinpaintedImage (output_object)  image(-array) objectHImageHImageHImageHImageXHobject * (byte / uint2 / real)

Output image.

ModeModeModeModeModemode (input_control)  string HTupleHTupleHTupleVARIANTHtuple (string) (string) (HString) (char*) (BSTR) (char*)

Type of edge sharpening algorithm.

Default value: 'weickert' "weickert" "weickert" "weickert" "weickert" "weickert"

List of values: 'parabolic'"parabolic""parabolic""parabolic""parabolic""parabolic", 'perona-malik'"perona-malik""perona-malik""perona-malik""perona-malik""perona-malik", 'shock'"shock""shock""shock""shock""shock", 'weickert'"weickert""weickert""weickert""weickert""weickert"

ContrastContrastContrastContrastContrastcontrast (input_control)  real HTupleHTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double) (double)

Contrast parameter.

Default value: 5.0

Suggested values: 0.5, 2.0, 5.0, 10.0, 20.0, 50.0, 100.0

Restriction: Contrast > 0

ThetaThetaThetaThetaThetatheta (input_control)  real HTupleHTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double) (double)

Step size.

Default value: 0.5

Suggested values: 0.5, 1.0, 5.0, 10.0, 30.0, 100.0

Restriction: Theta > 0

IterationsIterationsIterationsIterationsIterationsiterations (input_control)  integer HTupleHTupleHTupleVARIANTHtuple (integer) (int / long) (Hlong) (Hlong) (Hlong) (Hlong)

Number of iterations.

Default value: 10

Suggested values: 1, 3, 10, 100, 500

Restriction: Iterations >= 1

RhoRhoRhoRhoRhorho (input_control)  real HTupleHTupleHTupleVARIANTHtuple (real) (double) (double) (double) (double) (double)

Smoothing coefficient for edge information.

Default value: 3.0

Suggested values: 0.0, 0.1, 0.5, 1.0, 3.0, 10.0

Restriction: Rho >= 0

Example (HDevelop)

read_image (Image, 'fabrik')
gen_rectangle1 (Rectangle, 270, 180, 320, 230)
harmonic_interpolation (Image, Rectangle, InpaintedImage, 0.01)
inpainting_aniso (InpaintedImage, Rectangle, InpaintedImage2, \
                  'perona-malik', 5.0, 100, 50, 0.5)


harmonic_interpolationharmonic_interpolationHarmonicInterpolationharmonic_interpolationHarmonicInterpolationHarmonicInterpolation, inpainting_ctinpainting_ctInpaintingCtinpainting_ctInpaintingCtInpaintingCt, inpainting_mcfinpainting_mcfInpaintingMcfinpainting_mcfInpaintingMcfInpaintingMcf, inpainting_textureinpainting_textureInpaintingTextureinpainting_textureInpaintingTextureInpaintingTexture, inpainting_cedinpainting_cedInpaintingCedinpainting_cedInpaintingCedInpaintingCed


J. Weickert; “Anisotropic Diffusion in Image Processing”; PhD Thesis; Fachbereich Mathematik, Universität Kaiserslautern; 1996.
P. Perona, J. Malik; “Scale-space and edge detection using anisotropic diffusion”; Transactions on Pattern Analysis and Machine Intelligence 12(7), pp. 629-639; IEEE; 1990.
G. Aubert, P. Kornprobst; “Mathematical Problems in Image Processing”; Applied Mathematical Sciences 147; Springer, New York; 2002.



ClassesClassesClassesClasses | | | | Operators