We consider the Cahn-Hilliard equation for solving the binary image inpainting problem with emphasis on the recovery of low-order sets (edges, corners) and enhanced edges. The model consists in solving a modified Cahn-Hilliard equation by weighting the diffusion operator with a function which will be selected locally and adaptively. The diffusivity selection is dynamically adopted at the discrete level using the residual error indicator. We combine the adaptive approach with a standard mesh adaptation technique in order to well approximate and recover the singular set of the solution. We give some numerical examples and comparisons with the classical Cahn-Hillard equation for different scenarios. The numerical results illustrate the effectiveness of the proposed model.
Image inpainting is a fundamental problem in image processing. It has interesting applications and has wide applications in different imaging fields, such as medical imaging, photoshop, augmented reality, robotic and even in daily life (see e.g., Bertalmio et al.1,2; Chan and Shen3; Esedoglu and Shen4). It refers to restoring a damaged image with missing information. Various mathematical models have been proposed and discussed for this problem with different success rate. Among them, partial differential equations (PDEs) are widely used, and they showed good success mainly for cartoon and binary images Chan and Shen.3 In this work, we are interested in the Cahn-Hilliard equation (CHE) and its application in binary images inpainting. The Cahn-Hilliard equation originally refers to the authors Cahn and Hilliard5 and was introduced to phenomenologically describe the evolution of an interface between two state phases. It is a fourth-order semi-linear PDE which is derived from the -gradient flow of the following Ginzburg-Landau energy
where
is a smooth free energy Elliott,6 called double-well potentials, which models the phase separation.
For binary image inpainting, Cahn-Hilliard equation was first exploited by Bertozzi et al.7,8 by considering the following modified version
Equation (2) is obtained by incorporating the fidelity part which keeps the image u close to the observed data f in the damaged domain , where is the user-supplied inpainting region and
where is the indicator function of the subdomain and . The two state phases modelled by the Cahn-Hilliard equation can be seen as homogeneous regions in the image, while the interface between them plays the role of an edge. Because the double well potential W vanishes only at the values 0 and 1, the model (2) is appropriate for inpainting only two scale images.
A non-smooth version of Cahn-Hilliard equation was used in Bosch et al.9; Blowey and Elliott10,11 in image inpainting by considering the following non-smooth double obstacle potential
where and
This non-smooth double obstacle potential has the advantage of giving more intense colors and it then reveals the high contrast and the edges in the image. In this case, the full model consists in solving the following PDEs
where denotes the sub-differential of the non-smooth part
The system (4) to (7) leads to a variational inequality which requires the use of Lagrange multipliers associated with the constraints in equation (6). Those constraints can be also relaxed using Moreau-Yosida regularization, see Bosch et al.9
The edge quality when using Cahn-Hilliard like models in image inpainting is related to the choice of the parameter ϵ, which usually affects the sharpness of the edges. A large value of ϵ is always needed in order to join edges over large distances, whereas, in the same time, small value is preferred to sharpen the edges as the contrast depends on the ϵ-jump. Thus, choosing ϵ to be constant, whether it is large or small, in the classical Cahn-Hilliard equation is not always relevant to inpaint large damaged areas due to the trade-off between inpainting of large areas and the sharpness of edges, see Bertozzi et al.7,8; Bertozzi and Schönlieb.12 In practice, the authors in Bertozzi et al.,7 Bertozzi and Schönlieb12 used two step-process; they began the numerical computation with a large value of ϵ to reach a steady state. Then, they switch to a new system with a small value of ϵ using the previous result (i.e. computed with large ϵ) as initial data in order to sharpen the edges. This numerical adjustment of ϵ can be seen as an adaptive choice for ϵ, however, subjected to a hand tuning and being uniform in the entire domain.
In this work, we propose a model which can cope with the compromise between the inpainting of large areas and the sharpness of edges. We consider a weighted Cahn-Hilliard equation by adding a diffusion function α. More precisely, the model is given by the following equation
where . The diffusion function α, which encodes different scales in the image, is dynamically chosen in order to control the amount of the smoothing of the operator. The benefits of the proposed approach have two folds:
The inpainting of large damaged domains by choosing the parameter ϵ sufficiently large.
The recovery of the fine features of the initial image by controlling the diffusion function α locally and adaptively depending on the position . This will help to achieve an inpainting process with high-contrasted and sharp edges.
In equation (8), we have chosen to use the smooth Cahn-Hilliard model, as it is more convenient for the numerical computation comparing to the non-smooth one. Equation (8) is obtained by considering the gradient flow of the following Ginzburg-Landau type energy
while the second fitting part can be derived from a gradient flow in L2 for the following energy
The aim is to simultaneously inpaint and sharpen the edges across large damaged domain. In fact, the parameter ϵ will deal with the inpainting a large damaged domain, while α will recover the singularities and sharp edges.
The article is organized as follows: In the next section, we show the well posedness of the stationary equation related to equation (8). Then, we construct a linearized version of equation (8) based on the convexity-splitting method. In the penultimate section is dedicated to the introduction of the adaptive strategy for the selection of the diffusion parameter α based on the residual error indicator. Finally, different numerical examples are outlined in Section 5 to show the efficiency and robustness of the proposed method.
H1-weak solution of the stationary equation
We suppose that the domain Ω is partitioned into N disjoint sub-domains such that α is given by the piecewise constant scalar function
We denote and . For simplicity, we will use the homogeneous boundary condition of , and this condition is not a restrictive. Let be the dual space of ,
and induced by the following norm
where the operator is the inverse of the negative Laplacian with homogeneous Dirichlet boundary conditions. A weak solution of the stationary problem which corresponds to equation (8) is defined as a function u in the space such that
and which, equivalently, solves the following system
Proposition 1.For, where C is a positive constant depending only on, and W. For, the weak problem (11) admits a solution.
Proof. The proof can be done similarly to Bertozzi and Schönlieb12; Burger et al.13 using classical calculus of variation analysis and fixed point techniques.
Theorem 2.1. Let , the initial-boundary value problem (8) possesses a unique solution u which belongs to
Proof. The proof is based on the results in Bertozzi et al.7
Numerical algorithm
In this section, we present the numerical algorithm that we use to approximate the solution of the proposed modified Cahn-Hilliard evolution equation (8). More precisely, we use a semi-implicit approach called convexity splitting (CS) method (see Eyre14) which was originally proposed by Yuille and Rangarajan15 to solve general optimization problems. It was also applied for different nonlinear models such as the Cahn-Hilliard and Ohta-Kawasaki models (see Bertozzi and Schönlieb12; Kim and Shin16). The idea of CS is to divide the energies (9) and (10) into two parts; a convex plus a concave one. The convex part is then treated implicitly, while the concave part is treated explicitly. We refer the reader to Elsey and Wirth17; Hale18; Shin et al.19 for more details and various type of applications.
where . Note that E1 and E2 are the functional given in equations (9) and (10), respectively. Then, we apply the convexity splitting scheme to the two parts in equation (9) and in equation (10) separately. More precisely, we write where
It is clear that E11 is strictly convex for any , and the functional E12 is strictly convex for all . Similarly, assuming where
E22 is strictly convex if and only if . Let be the discrete time step width, and write , with . In addition, let be the approximate solution of the corresponding time-discrete numerical scheme of u(x, t) at time . Hence, the resulting time-stepping scheme for the splitting choices of the energies E1 and E2 is
where and are the descent gradients with respect to the - and L2-inner product, respectively.
We obtain the following scheme
Remark 1. In Bertozzi and Schönlieb,12the authors proved that this time-stepping scheme is unconditionally stable in the sense that the numerical solutionis uniformly bounded on a finite time interval. The stability proof of this scheme in our case requires some modifications and the result still holds.
Space discretization
For space discretization, we will use mixed finite element method. We introduce the following auxiliary function
Then, from the PDEs (equation (13)), we get the following system
Multiplying the first and the second equations in equation (15) by two test functions , respectively, then integrating over Ω, we obtain for all and the following weak formulation
Proposition 2. For a fixed, the system (16) has a unique solution.
Proof. For a given , and let C1, C2, and are positive constants. We define
Then, with the above notations, the system (15) is equivalent to
Moreover, for fixed , similarly to the system (12), we can prove equation (17) admits a unique solution . In addition, it is clear that the pair satisfies the system (16). To prove the uniqueness, let be another solution of the system (16). For all , we then have
Let be a partition of unity associated to the decomposition , and picking , in the second equation, we have the identity
Integrating by parts twice the right-hand side and summing up, we obtain
By choosing the test function in the first equation, using equation (20) and the positivity of C1, C2 and λ, we obtain
From the nonnegativity of , we get
Therefore, , and consequently, .
Finite element discretization and adaptive strategy
In order to find the solution of this problem, we apply the finite element method. Let h > 0, Ωh be a polygonal subset of Ω and be a nondegenerate triangulation of the discrete domain Ωh where each triangle or quadrilateral has maximum diameter bounded by h, satisfying the usual admissibility assumptions, i.e. the intersection of two different elements is either empty, a vertex, or a whole edge. We denote by the space of all polynomials defined on triangular elements K. We introduce the following discrete space
The finite discretization of equation (16) is defined by the following algebraic system
where
denotes the discrete L2-inner product, and be a basis of Xh with J is the set of all vertices. We write the above system as follows
where and .
Adaptivity
As mentioned in the introduction, the diffusion parameter α plays an important role in the inpainting process. Therefore, it is of interest to choose it based on a satiable strategy. Hence, we use an adaptive local procedure based on a residual error indicator. For each element K ∈ , we use the following local discrete energy
which contains information about the error distribution of the computed solution uh and also acts as an edge detector. In fact, the discontinuities (edges) are contained in regions where the brightness changes abruptly and therefore where this error indicator is large. Thus, quantity is well suited to locally control and select the diffusion coefficient α using an adaptive strategy, see Belhachmi and Frédéric20; Theljani et al.21,22 During the adaptation, we use the following formula for each triangle K
where αtrh is a threshold parameter and κ is a coefficient chosen to control the rate of decreasing in α. In addition, we use a mesh-adaptation technique allowing a tight location of the singularities. It also permits both the refinement (near the edges) and the coarsening of the grid (in homogeneous area) in order to best fit the geometry of the image and to make the method considerably fast. The build mesh is done iteratively until a maximum number of iterations are reached. Our algorithm is described as follows.
Algorithm 1: Adaptive algorithm based image inpainting
Initialization: Start with the initial grid and .
Iterations: For fixed function and mesh , compute so using convexity splitting (CS) method.
(a) Perform mesh adaptation to get the new mesh with mesh refinement step (in our case using the metric adaptation with FreeFem++).
(b) Perform a local choice of to obtain new functions .
3. Go to step (2) until convergence.
Remark 2.The advantages of this algorithm rely in two points: First, we make the “optimal” choice of the function α, following the map furnished by the error indicator, on each element K in order to approximate correctly the edges. Second, we build an adapted mesh(in the sense of the finite element method, i.e. with respect to the parameter h) by cutting the elements K, close to the jump sets of uh into a finite number of smaller elements to fit the edges, while, far from these jumps, the grid is coarsened.
Numeric
We present some numerical experiments to show the efficiency of our approach for image inpainting, and we compare it with classical Cahn-Hilliard equation Bertozzi et al.7 In all examples, the damaged regions are marked with red and gray colors.
We use the Structural Similarity Index Measurement (SSIM) as an evaluation metric to compare both models and which is given by the following formula
where μ, , σ are the mean, the variance, the covariance, respectively, and c1 and c2 are two positive parameters. The SSIM allows to estimate the quality of a reconstructed image with respect to its original version image. It takes a value between 0 and 1 where closer to 1 means a better inpainting process.
In Figure 1, we have chosen the same image presented by the authors Bertozzi et al.7 The result using classical Cahn-Hilliard equation in Figure 1(b) was computed in a two steps process. In the first step, the authors solved their equation with a large value of ϵ, e.g. , until getting steady-state solution. In this step, the level lines are smoothly continued into the missing domain. In a second step, the previous result from step 1 was used as an initial time condition for a smaller ϵ (e.g., ) in order to sharpen the contours. From the result of our model in Figure 1(c), we can see the corners are accurately approximated and the edges are properly and sharply inpainted contrary to the result of the classical Cahn-Hilliard model (Figure 1(b)). We also display in Figure 2 the evolution of the mesh at iteration 0, 3, 7 and 20, respectively. The first is the initial mesh which is regular such that every node corresponds to a pixel in the image and the last one is the final coarsed mesh.
Destroyed binary image and the solutions of the different models. (a) Damaged image, (b) model of Bertozzi et al.,7 SSIM = 0.89 and (c) New model, SSIM = 0.92.
The adopted mesh refinement with iterations. (a) Iteration 0, (b) Iteration 3, (c) Iteration 7 and (d) Iteration 20.
In the Figure 3, we compare both models in inpainting edges across large distance by considering three different inpainting scenarios (first line in Figure 3). The images in the second line were obtained using the classical Cahn-Hilliard model, where in all the domain Ω. The value is large enough and allows to join the both sides of the damaged stripe for the three scenarios. However, it leads to a very blurred edge because the contrast of the latter depends on the ϵ-jump. In another hand, if we choose a small value, i.e. (third line of Figure 3), the model is able to join the edges only for non-large damaged domain and fails to join them across large domains. Contrary, our proposed approach, see last line in Figure 3, gives successful result as the stripe is well inpainted and the edges are sharply recovered in all scenarios. We used in all the image domains Ω in order to match the edges and we adapted the diffusion function α to recover the singularities of the image, i.e. edges. Thus, we reconstruct edges across large domain and keeping them sharp enough. We tabulate the number of iterations and the SSIM values for the different models and the different scenarios in Table 1. It is clear that our model gives better results among in terms of SSIM and also necessitates less iterations.
First line: Three different inpainting domains. Second line: Restored images by classical Cahn-Hilliard (). Third line: Restored images by classical Cahn-Hilliard (). Fourth one: Restored images by new model.
or comparison between the different models related to the example in Figure 3.
Figure 3 (a)
Figure 3 (b)
Figure 3 (c)
SSIM
#Iter.
SSIM
#Iter.
SSIM
#Iter.
Cahn-Hilliard with
0.93
10
0.9
15
0.88
20
Cahn-Hilliard with
0.97
20
0.85
26
0.83
26
New model
0.98
8
0.97
12
0.95
20
SSIM: Structural Similarity Index Measurement.
In Figure 4, we test our model in reconstructing damaged part of a disk in order to show the efficiency of the adaptive strategy for curvature reconstruction. Figure 4(a) is the initial damaged image f (inpainting region in red). In Figure 4(b), we display the inpainted images using the classical Cahn-Hilliard model for and after 16 time-iterations. The reconstructed edges clearly are blurred. In Figure 4(c), we show the result of our adaptive strategy using the error indicators ηK in equation (22). We initialized the algorithm with large value of α = 10 and we performed only 6 adaptive iterations to obtain. We also display zoomed regions in Figure 5 to highlight the main visual differences between the different results. The zoom captions prove that our model can effectively sharpen edges and preserve curvatures.
From left to right: Damaged image, Cahn-Hiliard equation with constant (SSIM = 0.96) and new model (SSIM = 0.98). (a) Damaged image, (b) Classical Cahn-Hiliard and (c) new model.
Zoom captions from the test in Figure 4. (a) Referenced image, (b) Classical Cahn-Hiliard equation with α is fixed constant and (c) new model.
The last example in Figure 6 deals with real application for a binary QR-code image inpainting. It gives a promising result for corners and large gap reconstruction. The efficiency of our new approach can be seen in all the image domains, and in particular in the damaged region. In fact, all corners and edges were well reconstructed.
From left to right and top to bottom: The referenced image, damaged image, restored image by the new model at iterations 4 and 33. (a) The referenced image, (b) damaged image, (c) new model at iteration 4, SSIM = 0.81 and (d) new model after 33 iterations, SSIM = 0.97.
Conclusion
In this paper, we have addressed a new approach for binary image inpainting problem based on a weighted Cahn-Hilliard equation. The weight parameter controls the over-smoothness of the operator and is chosen locally and adaptively based on the residual error indicator in each pixel of the image. In the numerical computation, we used the splitting convexity method in order to linearise the proposed non-linear equation. The experiment results show the good performance in recovering well enhanced edges in comparison with classical Cahn-Hilliard model.
Footnotes
Declaration of Conflicting Interests
The author(s) declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.
Funding
The author(s) received no financial support for the research, authorship, and/or publication of this article.
ORCID iDs
Anis Theljani
Hamdi Houichet
References
1.
BertalmioMBertozziASapiroG. Navier-Stokes, fluid dynamics, and image and video inpainting. In: Proceedings of the international conference on computer vision and pattern recognition, Hauai, HI, 8-14 December, New York: IEEE, 2001, pp.355–362.
2.
BertalmioMSapiroGCasellesV, et al. Image inpainting. In: Proceedings of the 27th annual conference on computer graphics and interactive techniques. New York: ACM, 2000, pp.417–427.
3.
ChanTShenJ.Mathematical models for local non-texture inpainting. SIAM J Appl Math2002;
62: 1019–1043.
CahnJHilliardE.Free energy of a nonuniform system. I. Interfacial free energy. J Chem Phys1989;
28.
6.
ElliottCM. The Cahn-Hilliard model for the kinetics of phase separation. In: Mathematical models for phase change problems. Berlin: Springer, 1989, pp.35–73.
7.
BertozziAEsedogluSGilletteA.Analysis of a two-scale Cahn-Hilliard model for image inpainting. Multiscale Model Simul2007;
6: 913–936.
8.
BertozziAEsedogluSGilletteA.Inpainting of binary images using the Cahn-Hilliard equation. IEEE Trans Image Process2007;
16: 285–291.
9.
BoschJKayDStollM, et al.
Fast solvers for Cahn-Hilliard inpainting. SIAM J Imaging Sci2014;
7: 67–97.
10.
BloweyJFElliottCM.The Cahn-Hilliard gradient theory for phase separation with non-smooth free energy part I: mathematical analysis. Eur J Appl Math1991;
2: 233–280.
11.
BloweyJFElliottCM.The Cahn-Hilliard gradient theory for phase separation with non-smooth free energy part II: numerical analysis. Eur J Appl Math1992;
3: 147–179.
12.
BertozziASchönliebC-B.Unconditionally stable schemes for higher order inpainting. Commun Math Sci2011;
9: 413–457.
13.
BurgerMHeLSchönliebC-B.Cahn-Hilliard inpainting and a generalization for grayvalue images. SIAM J Imaging Sci2009;
2: 1129–1167.
14.
EyreDJ. An unconditionally stable one-step scheme for gradient systems. Unpublished article, 1998.
KimJShinJ.An unconditionally gradient stable numerical method for the Ohta-Kawasaki model. Bull Korean Math Soc2017;
54: 145–158.
17.
ElseyMWirthB.A simple and efficient scheme for phase field crystal simulation. Esaim: M2an2013;
47: 1413–1432.
18.
HaleJK.Asymptotic behavior of dissipative systems, no. 25 in mathematical surveys and monographs 025.
Providence, RI:
American Mathematical Society, 1988.
19.
ShinJLeeHGLeeJY.Unconditionally stable methods for gradient flow using convex splitting Runge–Kutta Scheme. J Comput Phys2017;
347: 367–381.
20.
BelhachmiZHechtF.Control of the effects of regularization on variational optic flow computations. J Math Imaging Vis2011;
40: 1–19.
21.
TheljaniABelhachmiZKallelMand Moakher M. A multiscale fourth-order model for the image inpainting and low-dimensional sets recovery. Math Meth Appl Sci2017;
40: 3637–3650.
22.
TheljaniABelhachmiZMoakherM.High-order anisotropic diffusion operators in spaces of variable exponents and application to image inpainting and restoration problems. Nonlinear Analysis: Real World Appl2019;
47: 251–271.