Computation of the area in the discrete plane: Green’s theorem revisited

Abstract. The detection of the contour of a binary object is a common problem; however, the area of a region, and its moments, can be a significant parameter. In several metrology applications, the area of planar objects must be measured. The area is obtained by counting the pixels inside the contour or using a discrete version of Green’s formula. Unfortunately, we obtain the area enclosed by the polygonal line passing through the centers of the pixels along the contour. We present a modified version of Green’s theorem in the discrete plane, which allows for the computation of the exact area of a two-dimensional region in the class of polyominoes. Penalties are introduced and associated with each successive pair of Freeman displacements along the contour in an eight-connectivity system. The proposed equation is shown to be true and properties of the equation related to the topology of the regions are presented. The proposed approach is adapted for faster computation than the combinatorial approach proposed in the literature.


Introduction
Let us consider Ω to be a binary four-connected region with or without holes. We suppose that Ω is filled with white pixels and surrounded by black pixels. This class of regions is the well-known polyominoes. 1 For such a region Ω, we propose an algorithm to identify its eight-connected, closed, and positively oriented contour Γ (black pixels). Second, we propose an exact equation to compute the area of Ω from the coordinates of the pixels in Γ. A simple way to obtain the area of such a region is to scan the region and to count the interior pixels inside the contour Γ. Otherwise, a corollary of Green's theorem in the continuous plane 2 states that if Ω is a closed and bounded region, surrounded by a simple closed path Γ, which is positively oriented and piecewise continuous, then the area AðΩÞ of Ω is given by the following line integral: E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 0 1 ; 6 3 ; 2 6 2 AðΩÞ ¼ The area of a discrete region is often computed from a discrete version of the last Eq. (1). This discrete equation is the well-known Pick's theorem. 3 The contour Γ will be an ordered set of pixels E Q -T A R G E T ; t e m p : i n t r a l i n k -; s e c 1 ; 6 3 ; 1 7 5 Γ ¼ fP 1 ; P 2 ; : : : ; P i ; P iþ1 ; : : : ; P L ; P Lþ1 ¼ P 1 g; where P i ¼ ðx i ; y i Þ are the coordinates associated with the center of the pixel P i ; i ¼ 1; : : : ; L þ 1. The integer L represents the number of pixels in Γ. The discrete version of Eq. (1) is given by the equation AðΩÞ ¼ 1 2 Unfortunately, the area obtained with this equation corresponds to the one enclosed by the polygonal line passing through the center of each pixel along the contour. Consequently, the area is greater than the number of white pixels. For example, the unitary region shown in Fig. 1 has an area equal to two pixels when using Eq. (2). The area is overestimated because of the contribution of the pixels on the contour at the left of the straight line passing through the center of each pixel in the contour. To correct Eq. (2) in its discrete formulation, we introduce a penalty associated with each Freeman displacement from one pixel to its successor along the positively oriented outer contour Γ. The sum of these penalties will correspond to the difference between the real area and the estimate given by Eq. (2). Before introducing the contour algorithm and penalties, we will provide some definitions to specify the topology of the domains covered by our approach. Many authors have treated this topic in the context of digital images, in particular the research works of Rosenfeld. [4][5][6][7][8] Otherwise, a different version of the Green theorem 9,10 based on the exterior edges of the contour's pixels (boundary) of a polyomino is used to calculate discrete geometric parameters, such as the center of gravity and the moment of inertia of the polyomino. In these studies, the contour is the adjacent pixels of the polyomino that are four-connected, and the boundary is encoded by a four-letter alphabet. Our approach, adapted for pattern recognition aims, is different from this combinatorial approach. We will consider simply four-connected regions in the discrete plane (white pixels). Our approach is to extract simultaneously the contour (eight-connected black pixels) and the ordered list of Freman's directions between each pair of successive pixels. These two topics are related in the calculation of the area. In Sec. 2, we describe the structures of a class of regions of interest, in Sec. 3 we present the construction of the oriented contour of such regions, and finally we present the equation for the computation of the area in Sec. 4 before the conclusion.

Definitions
Let Ω be a four-connected region in the discrete plane. If the number of pixels in Ω is finite, then Ω is called a closed and bounded region; otherwise it is open on the world. The set Ω c is the complementary set in the discrete plane or in the image.

Definition 1
Let Ω be a four-connected, closed, and bounded set of pixels (white pixels) in the discrete plane; therefore, the contour ∂Ω of Ω is the set of pixels (black pixels) in Ω c such that each pixel of ∂Ω is adjacent (fourconnectedness) to at least one pixel of Ω.
We recall that four-connectedness means edge connectivity; therefore, two pixels are four-connected if and only if they have a common edge. In this paper, we consider only simply connected regions. Otherwise, if a region contains holes, we can easily subtract the area of the holes from the region containing these holes.

Definition 2
The oriented contour Γ of Ω, or the contour, is an ordered rearrangement of the pixels in ∂Ω such that Γ is a closed, eight-connected, and positively oriented (counterclockwise) path. We represent the contour by an ordered set of pixels E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 0 3 ; 6 3 ; 2 4 4 Γ ¼ fP 1 ; P 2 ; : : : ; P i ; P iþ1 ; : : : ; P L ; P Lþ1 ¼ P 1 g; (3) where P 1 is any pixel in Γ.
Because of the orientation of the contour, the region Ω is at the left side of the oriented segment defined by any pair of successive pixels ½P i ; P iþ1 along the contour. The choice of the counterclockwise orientation is in accordance with the Green's theorem in vector calculus to ensure that the area is positive.

Definition 3
The oriented contour is said to be simple if The length L of an eight-connected contour is minimal when the contour is simple. Now, we consider topological structures to deal with regions having nonsimple contours as well and to extend the calculation of the area for a class of regions as large as possible. For this purpose, we introduce the definitions of a stem, branch, tree, and leaf connected to a stem. Subsequently, we will consider the juxtaposition of all these structures.
Definition 4 A stem in a contour Γ is a subset S ⊂ Γ such that there exist two integers 1 ≤ i ≤ L and k > 0 such that E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 0 4 ; 3 2 6 ; 6 5 8 S ¼ fP i ; P iþ1 ; P iþ2 ; : : : ; P iþk−1 ; P iþk ; P iþkþ1 ; : : : ; The pixel P i is called the root of the stem, and the pixel P iþk is called the extremity of the stem.
A stem is like a single filament growing inside the region Ω [see Fig. 2 . We now describe a branch in a contour as the union of many stems. One of these stems is identified as the principal stem on which all others stems are connected [see Fig. 2(d)]. All of these stems are disjoint, but many of these can have a common root on S 0 . A branch is welldefined in graph theory as a simple connected graph without any simple cycle. Here, the vertices in the graph are the pixels, and the edges are represented by the displacements.
Definition 5 Let S 0 be a fixed single stem in Γ with root R 0 ∈ Γ. Let S j ; j ¼ 1; : : : ; N, be N disjoint stems in Γ connected to S 0 by a root R j ∈ S 0 . The union of the stems fS j g n j¼0 is called a branch. The pixel R 0 is called the root of the branch, and S 0 is called the principal stem of the branch.
The choice of the principal stem is arbitrary. For instance, we can choose the longest as the principal stem. We define the union of branches as a tree.
Definition 6 Let T 0 be a fixed stem in Γ with root R 0 ∈ Γ and let B j ; j ¼ 1; : : : ; N, be N disjoint branches in Γ with R j ∈ T 0 the root of the branch B j , then the union of all branches is called a tree. The stem T 0 is called the trunk of the tree. The root R 0 is called the root of the tree.
In the last definition, branches can have a common root. We add a last structure that can be included first at the end of a stem.
Definition 7 A leaf F in Ω is a set of pixels connected to the extremity of a stem in Γ. The set of the pixels of a leaf, including its contour, is a simply four-connected region. The contour F c of a leaf is included in Γ.
A leaf is closed if its contour surrounds only black pixels; otherwise, it is open [see Fig. 2(f)]. The class C regions considered in this paper are those with stems, branches, trees, leaves, and all admissible combinations of these structures, and they are simply connected.

Definition 8
The principal contour of a region Ω ∈ C is the set of pixels in Γ that remains after the elimination of all stems, branches, trees, and leaf contours.

Proposition 1
Let Ω be a nonempty, bounded, and fourconnected region; then Ω has a finite and closed fourconnected outer contour ∂Ω and a contour Γ.
Proof. The outer contour ∂Ω of Ω is the set of all pixels in Ω c adjacent by the edges to the pixels in Ω. Since Ω is bounded, Ω contains a finite number of pixels and consequently ∂Ω is finite. If the contour ∂Ω is not closed, then Ω is not bounded and we have a contradiction. We conclude that Γ exists as a rearrangement of ∂Ω. ▯ The extraction of the closed, eight-connected, and positively oriented contour Γ from the outer contour ∂Ω of a four-connected region Ω and the associated sequence of successive and admissible displacements are presented below.
3 Construction of the Oriented Contour Now, we are ready to propose a new contour algorithm enabling us to construct the contour Γ (eight-connected, closed, and positively oriented) of a region Ω ∈ C. The algorithm presented in this section was introduced in Ref. 11 for the detection of the contour of "hydropsyche" nets in an environmental application in connection with toxicological studies. The algorithm contains three major steps: the identification of a starting pixel on the contour, the step-by-step construction of successive eight-connected pixels on the contour (see Fig. 3), and the ending of the process when connecting with the starting pixel. We first identify a set of potential starting pixels along the contour of Ω. In practice, we need one starting pixel for each connected component. The Freeman directions will be used as identifiers of the displacements along the contour. The Freeman codification is the standard one in an eight-connected topology; the value is 0 in the right direction and is increasing in a counterclockwise manner. A displacement is an oriented segment (counterclockwise) between two successive pixels along the contour. We will denote ½P a ; P b an oriented segment, or vector, from the center of the pixel P a to the center of the pixel P b .
Definition 9 A black pixel P s ¼ ði; jÞ is called a potential starting pixel of a contour if the adjacent pixel with coordinates P r ¼ ði − 1; j þ 1Þ is black and if the pixel with coordinates P t ¼ ði; j þ 1Þ is white. The Freeman direction associated with the displacement from P s to P r is α ¼ 5.
We denote SðΩÞ the set of all potential starting pixels.

Proposition 2
Let Ω ∈ C and its contour Γ. There exist P 1 and P 2 in Γ such that the Freeman direction of the oriented segment ½P 1 ; P 2 equals α ¼ 5 and such that P 1 ∈ SðΩÞ has a unique pixel P L ∈ Γ as predecessor.
Proof. Let P s ¼ ðk; jÞ be the pixel with coordinates E Q -T A R G E T ; t e m p : i n t r a l i n k -; s t 1 3 ; 3 2 6 ; 2 1 6 j ¼ min Since Ω is bounded, then P s exists. By the definition of P s , we have P 1 ¼ ðk − 1; jÞ and P 2 ¼ ðk; j − 1Þ in Γ are the two successive candidate pixels with the Freeman direction equal to α ¼ 5. It is easy to show, or to illustrate, that the predecessor P L of P 1 belongs to the exclusive set of coordinates fðk − 1; j þ 1Þ; ðk − 2; jÞ; ðk − 2; j þ 1Þ; ðk; j þ 1Þg; otherwise, we have a contradiction because of the definition of P s . ▯ The last proposition confirms that we can start the detection of the contour with the specific starting pixel selected.  Many other starting pixels are admissible. In the case of a region with many connected components, we switch off any pixel in SðΩÞ encountered during the construction of a contour with the intent of individually constructing the contour of each component. When the set SðΩÞ becomes empty, no component remains. Finally, when we reach the predecessor P L , the construction of the contour is stopped. Let P 1 and P 2 be the starting and second pixels identified previously, respectively, and let k ¼ 1.
At each step k ≥ 1, we have to identify the pixel P kþ2 such that the oriented segment d kþ1 ¼ ½P kþ1 ; P kþ2 satisfies the two following conditions: (1) P kþ2 is a black pixel and (2) fP 1 ; P 2 ; : : : ; P k ; P kþ1 ; P kþ2 g is the minimal eightconnected and counterclockwise-oriented chain of pixels on Γ, which minimizes the length (number of pixels) of all chains of black pixels belonging to ∂Ω and linking P 1 to P kþ2 . Let d k ¼ ½P k ; P kþ1 the oriented segment on the contour issued from the step k ≥ 1. Let α k be the Freeman direction associated with this displacement. We will prove that there exists one and only one pixel P kþ2 such that the preceding conditions are verified. The black pixel P kþ2 ∈ Γ is chosen according to the knowledge of the direction α k between the preceding pixels. The choice of the pixel P kþ2 must respect the last two constraints. The enumeration of the potential patterns of distribution of white and black pixels in the neighborhood of P k and P kþ1 will allow us to identify this unique pixel on an eight-connected contour. To select the pixel P kþ2 , we covered all of the possible patterns (see Table 1) in the neighborhood of the pixels P k and P kþ1 that respect the attributes of the contour. In Table 1, a value at the position (i; j) indicates that a displacement in the Freeman direction α kþ1 ¼ j is admissible after a displacement in the direction α k ¼ i along the contour. The meaning of the value in position (i; j) will be specified further on. For a given i ¼ α k , there exists only one j ¼ α kþ1 that corresponds to a displacement along the contour such that the constraints are verified, then we can determine the unique P kþ2 . In Fig. 4, we show in a minimal geometric representation all successive and admissible displacements. The other data associated with these representations will serve to explain penalties associated with these displacements.
Given the pixels P k and P kþ1 and displacement α k , we see from Table 1 that there are no more than seven directions to visit before choosing the next pixel P kþ2 and the direction α kþ1 , which is unique along the contour. Furthermore, we note that some opposite Freeman directions are admissible to take into account reverse displacements along the stems. Finally, since the starting pixel has a unique predecessor as shown in Proposition 2, the algorithm stops when we reach the first pixel P 1 . The next theorem summarizes the situation discussed above.

Theorem 1
Let Ω ∈ C be a nonempty region and let P 1 and P 2 be the two pixels found at the first step of the algorithm. Then, 1. there exists a unique pixel P 3 ∈ Γ such that the sequence of pixels fP 1 ; P 2 ; P 3 g is positively oriented and α 2 is equal to 6 or 7, 2. for k > 1, if P k and P kþ1 are the two successive pixels in Γ, then there exists a unique pixel P kþ2 ∈ Γ such that fP k ; P kþ1 ; P kþ3 g is a positively oriented path in Γ.
Proof. If α 2 equals values other than 6 or 7, we have a contradiction in regard to the position of the pixel P s , as defined in the proof of Proposition 2. The second part is a consequence of the proposed construction for Γ. ▯ To prove the correctness of the proposed contour algorithm, some intermediary results are necessary. First, we show that the algorithm is finite. For this purpose, it is sufficient to show that a pixel on the contour is revisited at most a finite number of times. We will focus our argument on the geometry of stems and branches in the discrete plane.

Lemma 1
The extremity of a stem is at most the root of three other stems.
Proof. The proof is based on geometric arguments. Figure 5 shows all geometric patterns combining a root of a stem connected to its predecessor in Γ. For each one of these patterns, we connected the maximum number of independent stems to the extremity of the main stem. Figure 6 shows all combinations (classes of equivalence under orthogonal rotations) when connecting stems to an extremity. We observe that only two or three stems can be connected. ▯ Before moving on to the correctness of the algorithm, we present the next lemma.
Proof. The only pixels revisited on Γ are pixels belonging to a stem and consequently to a branch or a tree. Let P k be such a pixel. If P k is not a root, then P jþ1 ¼ P k−1 ≠ P kþ1 and then α k ≠ α j . If P k is a root, then it is clearly visited at most a finite number of times. ▯ We conclude that P k is revisited at most a finite number of times. In conclusion, we have proved that the algorithm can be initialized and the contour is well-defined at each step. Also, we have proved that each pixel is visited at most a finite number of times along Γ and then the procedure is finite in time. Furthermore, the procedure is closed since     Journal of Electronic Imaging 063022-5 Nov∕Dec 2017 • Vol. 26 (6) oriented segments d k ¼ ½P k ; P kþ1 ðk ≥ 1Þ along the contour. Our objective is to remove systematically, for each pair of successive displacements ½α k ; α kþ1 ð1 ≤ k ≤ LÞ, the additional surface area introduced when using Pick's formula. For this purpose, we define for each successive displacement a penalty p k ¼ pðα k ; α kþ1 Þ, and this value is subtracted from the corresponding term in the original Eq.
(2) as we will see later. The penalty p k is calculated according to the next definition.
Definition 10 For k ≥ 1, let P k , P kþ1 , and P kþ2 be three successive pixels in Γ and let α k and α kþ1 be the Freeman directions associated with the oriented segments d k ¼ ½P k ; P kþ1 and d kþ1 ¼ ½P kþ1 ; P kþ2 . Let P Ã kþ1 and P Ã kþ2 be the two orthogonal projections of P kþ1 and P kþ2 on the adjacent edges in the direction of Ω, respectively, such that the angle between the oriented segments d k and ½P kþ1 ; P Ã kþ1 (resp., ½P kþ2 ; P Ã kþ2 ) is acute. The penalty p k is the surface of the polygon with vertices fP Ã kþ1 ; P kþ1 ; P kþ2 ; P Ã kþ2 g inside P kþ1 S P kþ2 .
In Fig. 7, we illustrate the calculation of the penalty pð0; 1Þ for the particular successive pair of displacements α k ¼ 0 and α kþ1 ¼ 1. Table 1 shows the values of these penalties calculated for all admissible and successive pairs of displacements. In Fig. 4, we can see the penalized area for each admissible pair of admissible displacement.
Before demonstrating the correctness of the modified Green's formula (see Proposition 4), we prove the invariance under rotations of the penalty values.

Lemma 3 The penalty associated with a pair of admissible displacements along Γ is invariant under rotations.
Proof. Let ði; jÞ be the indices of two successive and admissible displacements (0 ≤ i; j ≤ 7), then the rotation of ði; jÞ gives the pair ði 0 ; j 0 Þ where i 0 ¼ ði þ 2Þmod 8 and j 0 ¼ ðj þ 2Þmod 8. From Table 1, we verify that pði; jÞ ¼ pði 0 ; j 0 Þ for all pairs of displacements. We conclude that penalties are invariant under rotations. ▯ At this time, we are able to propose a modified Green's formula. First, we prove that the proposed equation computes the right area of a region with a simple contour without the presence of stems, branches, trees, and leaves. We will denote C 0 such a region, and its contour will be called a simple contour.

Theorem 2
Let Ω ∈ C 0 be a region and Γ its contour given by the sequence of pixels E Q -T A R G E T ; t e m p : i n t r a l i n k -; s t 2 3 ; 3 2 6 ; 6 3 8 ½P 1 ; P 2 ; : : : ; P k−1 ; P k ; : : : ; P L ; P Lþ1 ¼ P 1 ; where P i ≠ P j for 1 ≤ i ≠ j ≤ L. The area of Ω is given by the following equation: E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 0 5 ; 3 2 6 ; 5 8 1 where pðα k ; α kþ1 Þ is the penalty associated with two successive and admissible displacements d k ¼ ½P k ; P kþ1 and d kþ1 ¼ ½P kþ1 ; P kþ2 with Freeman directions α k and α kþ1 .
Proof. We proceed by induction on the size n ≥ 1 of the area of Ω. The only region with an area equal to 1 was shown in Fig. 1. If we suppose that the white pixel of this domain has coordinates ði; jÞ, then its contour is given by the sequence of pixels fP 1 ; P 2 ; P 3 ; P 4 ; P 5 ¼ P 1 g where P 1 ¼ ði − 1; jÞ; P 2 ¼ ði; j − 1Þ; P 3 ¼ ði þ 1; jÞ, and P 4 ¼ ði; j þ 1Þ. The Freeman directions associated with this contour are given by the sequence {5, 7, 1, 3}. If we calculate the area using the discrete Eq. (5), then E Q -T A R G E T ; t e m p : i n t r a l i n k -; s t 2 4 ; 3 2 6 ; 3 8 3 − ½pð5;7Þ þ pð7;1Þ þ pð1;3Þ þ pð3;5Þ Let Ω Ã ∈ C 0 be a region with an area equal to n þ 1 and Γ Ã its contour. Let us suppose that Eq. (5) is exact for all regions Ω with an area equal to n ≥ 1 (mathematical induction on the integer n). The basic idea of the proof consists of eliminating P e ∈ Ω Ã , a pixel adjacent to the contour, and then applying the assumption to the resulting region Ω ¼ Ω Ã − fP e g. We denote Γ the contour of Ω. If we remove such a pixel in Ω Ã , the contour Γ Ã is modified to become Γ. The resulting deformation of Γ Ã depends on the position of P e along the contour. As shown in Fig. 8, if we switch off P e ¼ ði; jÞ from Ω Ã , then we obtain a local reconstruction of the contour passing through the pixel P e Unfortunately, to establish the proof we have to forecast all possible deformations of Γ Ã when eliminating a pixel P e ∈ Ω Ã adjacent to Γ Ã . In Fig. 9, we illustrate all patterns  Journal of Electronic Imaging 063022-6 Nov∕Dec 2017 • Vol. 26 (6) of deformations of Γ Ã obtained when eliminating a pixel P e in Ω Ã with the constraint that the region must remain connected. We assert that any region Ω Ã ∈ C 0 respects at least one of these patterns along its boundary following such an elimination. These equivalence classes of deformations of Γ Ã (patterns) are constructed taking into account orthogonal rotations and vertical and horizontal flips and were established by enumeration. The reorganization of the contour Γ Ã is represented by a dotted line passing through the pixel P e . For each deformation, we first apply Eq. (5) to the contour Γ of the region Ω with an area equal to n, and subsequently we add the area eliminated following the reorganization of the original contour Γ Ã . By a reorganization of the resulting algebraic expression, we obtain Eq. (5) for the region Ω Ã with an area equal to n þ 1. We will show this result only for the pattern shown in Fig. 8; the proof is similar for the other patterns (Fig. 9). Let us consider P e ¼ ði; jÞ as the pixel removed from Ω Ã , and let us denote E Q -T A R G E T ; t e m p : i n t r a l i n k -; s e c 4 ; 6 3 ; 3 9 1 Γ Ã ¼ ½P 1 ; : : : ; P J−1 ; P J ; P Jþ1 ; P Jþ2 ; P Jþ3 ; P Jþ4 ; : : : ; P L ; P Lþ1 ¼ P 1 : If we remove P e and if we apply the modified Green's formula to the region Ω, then using the induction assumption and rewriting the terms involved in the deformation of the contour, we obtain the area of Ω E Q -T A R G E T ; t e m p : i n t r a l i n k -; s e c 4 ; 6 3 ; 2 9 8 From the last equation, we have E Q -T A R G E T ; t e m p : i n t r a l i n k -; s e c 4 ; 3 2 6 ; 7 4 1 n þ 1 ¼ 1 2 Otherwise, if we apply Eq. (5) to Γ Ã and if we apply the last expression, we obtain the desired result E Q -T A R G E T ; t e m p : i n t r a l i n k -; s e c 4 ; 3 2 6 ; 6 3 0 In the last theorem, we supposed that the contour was simple. In this specific case, the enumeration of all classes of rearrangement of the contour allows us to bypass the combinatorial and the geometric complexity. To complete the demonstration, we will show the effect of a single stem in the computation of the area before extending the last theorem to a general region with multiple stems, branches, trees, and leaves.
Lemma 4 Let S 0 be a stem given by the sequence of pixels E Q -T A R G E T ; t e m p : i n t r a l i n k -; s t 2 5 ; 3 2 6 ; 2 7 4 S 0 ¼ fP 0 ; P 1 ; : : : ; P t−1 ; P t ; P tþ1 ; : : : ; P 2 t−1 ; P 2 t g where P 2t ¼ P 0 is the root of the stem. If P j ¼ ðx j ; x jþ1 Þ, then the following identities are verified: E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 0 6 ; 3 2 6 ; 2 2 3 1 2 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 0 7 ; 3 2 6 ; 1 8 0 E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 0 8 ; 3 2 6 ; 1 4 3 1 2 where the constant t represents the number of pixels in the stem. Proof From the definition of a stem, we have E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 0 9 ; 6 3 ; 1 8 8 P 2t−j ¼ P j ; j ¼ 0; : : : ; t − 1: Since each pixel is visited twice in two opposite directions along the stem, the ordered list of Freeman directions along the stem can be rewritten as follows: E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 1 0 ; 6 3 ; 1 2 7 fα 0 ; α 1 ; : : : ; α t−1 ; α t ; α tþ1 ; : : : ; α 2 t−1 g; and these directions verify the next identity E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 1 1 ; 6 3 ; 8 5α tþj ¼ α T t−j−1 ; j ¼ 0; : : : ; ðt − 1Þ; (11) where α T t−j−1 is the inverse direction of α t−j−1 . With this notation, we can rewrite the equation at the left of Eq. (6) E Q -T A R G E T ; t e m p : i n t r a l i n k -; s e c 4 ; 3 2 6 ; 1 7 6 1 2 ½x 2t−j y 2 t−ðjþ1Þ − y 2 t−j x 2 t−ðjþ1Þ : Fig. 9 Patterns of a local rearrangement along a contour.
▯ From the last lemma, we conclude that the contribution of the pixels of a stem in the algebraic expression of the modified Green's formula equals the number of pixels on the stem with a negative sign. Here is the following theorem.
Theorem 3 Let Ω be a region having a single stem, then the modified Green's formula [Eq. (5)] applied to the contour gives the exact area of Ω.
Proof Let us suppose that Ω has an area equal to n ≥ 1 and let Γ be its contour. If Ω has only one stem, then the contour is given by the sequence E Q -T A R G E T ; t e m p : i n t r a l i n k -; s t 2 8 ; 6 3 ; 2 2 1 Γ ¼ fP 1 ; P 2 ; : : : ; P i ¼ P s 0 ; P s 1 ; : : : ; P s t ; P s tþ1 ; : : : ; P s 2 t−1 ; P s 2 t ¼ P i ; P iþ2 tþ1 ; : : : ; P L ; P Lþ1 ¼ P 1 g; where P 1 is the starting pixel. In this sequence, the stem is represented by the following subsequence of pixels: E Q -T A R G E T ; t e m p : i n t r a l i n k -; s t 2 8 ; 6 3 ; 1 4 9 Γ a ¼ fP i ¼ P s 0 ; P s 1 ¼ P iþ1 ; : : : ; P s t ¼ P iþt ; P s tþ1 ¼ P iþtþ1 ; : : : ; P s 2 t−1 ¼ P iþ2 t−1 ; P s 2 t ¼ P iþ2 t : ¼ P i g: The pixel P i ¼ P s 0 ¼ P s 2t is the root of the stem. Let Γ p be the principal contour of Ω, which is defined by the subsequence of pixels E Q -T A R G E T ; t e m p : i n t r a l i n k -; s e c 4 ; 3 2 6 ; 7 5 2 Γ p ¼ fP 1 ; P 2 ; : : : ; P i ; P iþ2 t−1 ; : : : ; P L ; P Lþ1 ¼ P 1 g: Let Ω Ã be the region surrounded by the principal contour Γ p . If we apply the modified Green's formula [Eq. (5)] to the region Ω, then we have the following algebraic decomposition based on the coordinates of the pixels in the contour Γ: E Q -T A R G E T ; t e m p : i n t r a l i n k -; s e c 4 ; 3 2 6 ; 6 8 6 In the last summation, we identify three terms E Q -T A R G E T ; t e m p : i n t r a l i n k -; s e c 4 ; 3 2 6 ; 5 2 4 k¼i pðα k ; α kþ1 Þ; The sum S ¼ S 1 þ S 3 corresponds to the area of the region Ω Ã surrounded by Γ p ; then we have S ¼ n þ t.
Here, t is the number of distinct pixels on the stem. In addition, by Lemma 4, we see that S 2 ¼ −t. In conclusion, ▯ It is possible to generalize the last proposition to regions with a branch in Ω.

Proposition 3
Let Ω be a region with a branch connected to the principal contour Γ p . Let Γ be the contour of Ω E Q -T A R G E T ; t e m p : i n t r a l i n k -; s t 2 9 ; 3 2 6 ; 3 0 2 Γ ¼ fP 1 ; : : : ; P i ; P iþ1 ; : : : ; P b 0 ; P b 1 ; : : : ; P b j ; : : : ; P b 2N ¼ P b 0 ; : : : ; P M ¼ P 1 g: Let B 1 be the branch defined by the subsequence of pixels B 1 ¼ fP b 0 ; P b 1 ; : : : ; P b j ; : : : is the root of the main stem on the branch, which is connected to Γ p . Let us denote P b j ¼ ðx b j ; y b j Þ the coordinates of the j'th pixel in B 1 and α b j be the Freeman direction associated with the oriented segment ½P b j ; P b jþ1 for j ¼ 0; : : : ; 2 N − 1. Thus, we have E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 1 2 ; 3 2 6 ; 1 6 6 1 2 Proof. We can split the expression [Eq. (12)] in such a way that we obtain a summation restricted to the pixels of the main stem and other individual summation for each secondary stem. Then, applying Lemma 4 at each summation Journal of Electronic Imaging 063022-9 Nov∕Dec 2017 • Vol. 26 (6) we obtain the total number of pixels in B 1 with a negative sign. The root P a 0 is not counted. ▯ The proof of the Proposition 3 can be easily extended to regions with multiple branches and trees. To conclude this section, we extend the previous results to regions with leaves.
Proposition 4 Let a region Ω ∈ C and Γ its contour; suppose that Γ has only one leaf connected to the end of a stem S 0 in Ω, then the area of Ω is given by the modified Green's formula [Eq. (5)].
Proof. The leaf can be closed or open. If the leaf is open, the interior of its leaf contour does not contain a subset of Ω. Let us consider the partition of the pixels in Γ • Γ p : the set of all pixels in the principal contour of Ω, • Γ a : the set of internal pixels in S 0 , and • Γ b : the set of pixels in the leaf contour.
Since Γ p is a simple contour, then by Theorem 2, the contribution of these pixels to Eq. (5) gives the area of the domain inside Γ p . Otherwise, by Lemma 4, the contribution of the pixels in Γ a gives, with a minus sign, the number of pixels in Γ a . However, we can show that the contribution of the pixels in Γ b is equal to the number of pixels in the leaf.
Let us denote fP b 1 ; P b 2 ; : : : ; P b J ; P b Jþ1 ¼ P b 1 g the subsequence of pixels defining the leaf contour, where P b j ¼ ðx b j ; y b j Þ; j ¼ 1; : : : ; J are the coordinates of such a pixel and α b j is the Freeman direction of the segment ½P b j ; P b jþ1 . Let us consider the two sums E Q -T A R G E T ; t e m p : i n t r a l i n k -; e 0 1 3 ; 6 3 ; 1 4 4 S b 1 ¼ 1 2 The first sum S b 1 gives the area inside the polygonal line passing through the center of each pixel on the leaf contour with a negative sign since the path is clockwise. For instance, the sum S b 2 gives the black area outside the leaf contour, but within the leaf, with a negative sign. If we combine these two results, the modified Green's formula will give the area inside the principal contour minus the length of the stem and the area occupied by the leaf.
▯ The same result is valid for a region with a stem, branch, tree, or leaf. If we combine all of the arguments used in these proofs, then we conclude that the proposed equation is valid for all regions with any combination of these attributes. If we apply the original Eq. (2) and the modified or penalized Green's formula to the region shown in Fig. 10, we obtain an area of 798 and 415 pixels (exact area). This numerical result confirms the importance of having a precise evaluation of the area.

Conclusion
We proposed and demonstrated a new algebraic expression of a fundamental corollary derived from Green's formula applied to the computation of the area of a four-connected binary region. For this purpose, we introduced penalties associated with pairs of successive displacements along an eight-connected positively oriented contour. The correctness of the equation was formally proved for a general class of binary connected regions in the discrete plane. The modified Green's formula was derived from geometric observations, but further research work will eventually establish the proposed approach as a consequence of a discrete vector calculus theory. We are extending these results (unpublished as of yet) to triangular and hexagonal mesh.