Discrete Morphological Neural Networks
A classical approach to designing binary image operators is Mathematical
Morphology (MM). We propose the Discrete Morphological Neural Networks (DMNN)
for binary image analysis to represent W-operators and estimate them via
machine learning. A DMNN architecture, which is represented by a Morphological
Computational Graph, is designed as in the classical heuristic design of
morphological operators, in which the designer should combine a set of MM
operators and Boolean operations based on prior information and theoretical
knowledge. Then, once the architecture is fixed, instead of adjusting its
parameters (i.e., structural elements or maximal intervals) by hand, we propose
a lattice descent algorithm (LDA) to train these parameters based on a sample
of input and output images under the usual machine learning approach. We also
propose a stochastic version of the LDA that is more efficient, is scalable and
can obtain small error in practical problems. The class represented by a DMNN
can be quite general or specialized according to expected properties of the
target operator, i.e., prior information, and the semantic expressed by
algebraic properties of classes of operators is a differential relative to
other methods. The main contribution of this paper is the merger of the two
main paradigms for designing morphological operators: classical heuristic
design and automatic design via machine learning. As a proof-of-concept, we
apply the DMNN to recognize the boundary of digits with noise, and we discuss
many topics for future research.
Diego Marcondes, Junior Barrera
# Discrete Morphological Neural Networks

###### Abstract.

A classical approach to designing binary image operators is Mathematical Morphology (MM). We propose the Discrete Morphological Neural Networks (DMNN) for binary image analysis to represent W-operators and estimate them via machine learning. A DMNN architecture, which is represented by a Morphological Computational Graph, is designed as in the classical heuristic design of morphological operators, in which the designer should combine a set of MM operators and Boolean operations based on prior information and theoretical knowledge. Then, once the architecture is fixed, instead of adjusting its parameters (i.e., structural elements or maximal intervals) by hand, we propose a lattice gradient descent algorithm (LGDA) to train these parameters based on a sample of input and output images under the usual machine learning approach. We also propose a stochastic version of the LGDA that is more efficient, is scalable and can obtain small error in practical problems. The class represented by a DMNN can be quite general or specialized according to expected properties of the target operator, i.e., prior information, and the semantic expressed by algebraic properties of classes of operators is a differential relative to other methods. The main contribution of this paper is the merger of the two main paradigms for designing morphological operators: classical heuristic design and automatic design via machine learning. Thus, conciliating classical heuristic morphological operator design with machine learning. We apply the DMNN to recognize the boundary of digits with noise, and we discuss many topics for future research.

## 1. Introduction

### Mathematical Morphology and W-operators

Mathematical Morphology (MM), a theory initiated in the sixties by George Matheron [30] and Jean Serra [42, 43] at the Fontainebleau campus of the Ecole Superieur des Mines de Paris (ESMP), has been important for the development of the field of image analysis. Lattices are the fundamental algebraic structure
in MM, which studies mappings between complete lattices, and, from the sixties to the eighties, this theory evolved from Boolean to general lattice mappings [42]. These mappings are decomposed by lattice operations and two pairs of dual elementary operators: erosion and dilation, which commute, respectively, with infimum and supremum, as well as, anti-dilation and anti-erosion, which commute, respectively, with supremum-infimum and infimum-supremum. Based on these elementary operators, Banon and Barrera [4] proposed two dual minimal representations for any lattice operator: one in terms of supremum of sup-generating operators (i.e., infimum of an erosion and an anti-dilation) and another in terms of infimum of inf-generating operators (i.e., supremum of a dilation and an anti-erosion).

A particular class of morphological operators for binary image analysis, very important in practical applications, are the W-operators [9]. Let a binary image \(X\) be a subset of the image domain \(E\) and let \((\mathcal{P}(E),\subseteq)\) be the Boolean lattice of the powerset of \(E\). A set operator \(\psi\) is a mapping from \(\mathcal{P}(E)\) to \(\mathcal{P}(E)\) that transforms image \(X\in\mathcal{P}(E)\) into image \(\psi(X)\). When \((E,+)\) is an _Abelian group_ with respect to a binary operation \(+\), a set operator \(\psi\) is a W-operator if, and only if, it is translation invariant and locally defined in a window \(W\in\mathcal{P}(E)\), i.e., \(\psi(X+h)=\psi(X)+h\) and

\[h\in\psi(X)\iff f_{\psi}((X-h)\cap W)=1,\text{ for }h\in E,\]

in which \(f_{\psi}:\mathcal{P}(W)\to\{0,1\}\) is the characteristic function of \(\psi\). In this case, the kernel of \(\psi\) is \(\mathcal{K}_{W}(\psi)=\{X\in\mathcal{P}(W):f_{\psi}(X)=1\}\) and the basis of \(\psi\), denoted by \(\boldsymbol{B}_{W}(\psi)\), is the collection of maximal intervals in \(\mathcal{K}_{W}(\psi)\). The sup-generating operators

\[\lambda_{[A,B]}(X)=\{h\in E:A\subseteq(X-h)\cap W\subseteq B\},\qquad\ X\in \mathcal{P}(E),\]

associated to intervals \([A,B]\subseteq\mathcal{P}(W)\) are the building blocks to represent any W-operator:

\[\psi(X)=\bigcup\big{\{}\lambda_{[A,B]}(X):[A,B]\in\boldsymbol{B}_{W}(\psi) \big{\}}\qquad\qquad X\in E.\]

This expression has also a dual form based on inf-generating operators. In fact, any W-operator can be represented in terms of unions, intersections, compositions, and complements of erosions, dilations, anti-erosions and anti-dilations, and have several equivalent representations, but all of them can be converted into a unique basis representation [4]. It is possible to compute
incrementally the basis of any W-operator from any representation of it in terms of the elementary operators of mathematical morphology (i.e., erosion and dilation), the Boolean lattice operations, (i.e., intersection, union and complement), and the basis of the identity operator [9].

### Design of set operators

From several studies about mathematical morphology operators [42, 43], followed the proposal of many families of operators which can be combined heuristically to solve image analysis problems. Some classes of operators include the hit-or-miss operators [42], morphological filters [44], and watershed segmentation [11]. The research group at ESMP developed procedures to heuristically design operators, which require prior information about the problem at hand, knowledge of several classes of operators (the so-called MM toolbox), and the ability to combine them through composition and lattice operations. Once the combination of operators is performed, the designer should carefully adjust the parameters of the designed operator to obtain a solution that properly solves the practical problem.

Specialized software, whose architectures were based on basic operators and operations (i.e., erosion, dilation, infimum, supremum, complement), from which more complex operators (i.e., skeletons, filters, etc) can be built, were implemented in the nineties. In special, the researchers and engineers of the Center for Mathematical Morphology of ESMP were the pioneers in developing software and hardware for morphological image processing, and the _mmach_ toolbox for the Khoros system [6], developed by researchers of USP, UNICAMP and INPE in Brazil, became popular at the end of the nineties. These software have had a considerable impact on the solution of a large class of image analysis problems. We refer to [6, 16, 46, 48] for more details on practical methods for the design of MM operators.

Although the heuristic design of morphological operators had a great impact on image analysis, it is a time-consuming manual procedure which does not scale efficiently to more complex problems. Since combining basic morphological operators to form a complex image processing pipeline is not a trivial task, a natural idea is to develop methods to automatically design morphological operators. At the end of the eighties, M. Shimidt [41] proposed a design procedure based on artificial intelligence, which combined W-operators (represented by compositions of parameterized morphological operators) and adjusted their parameters. Since the late nineties, approaches for the automatic design of morphological operators based on machine learning have been
proposed, mainly by the work of Ed. Dougherty, J. Barrera and their collaborators [10], and have been extensively applied in the literature with great success to solve specific problems [7, 12, 13, 15, 21, 22, 24, 25, 26, 27, 32, 33, 40]. Many of these approaches are also heuristics, which may consider prior information about the problem at hand. However, the parameters of the operators are more efficiently adjusted by learning from data and good practical results have been obtained. More details about MM in the context of machine learning may be found in [8, 23].

In the nineties [38], and then more recently, MM methods have been studied in connection with deep neural networks, by either combining convolutional neural networks (CNN) with a morphological operator [29], or by replacing the convolution operations of CNN with basic morphological operators, such as erosions and dilations, obtaining the so-called morphological neural networks (MNN) [19, 28, 31]. A MNN has the general framework of neural networks, and its specificity is on the fact that the layers realize morphological operations. Although it has been seen empirically that convolutional layers could be replaced by morphological layers [19], and MNN have shown a better performance than CNN in some tasks [28], MNN have lost the spirit of MM, that is a careful theoretical design of the operator based on prior information, followed by the adjustment or learning of its parameters implying a fully understanding of its properties. This detachment from classical MM made MNN opaque and as much a black-box as CNN, so no real gain in control and interpretability is obtained with MNN when compared to CNN.

### Main contributions

In this context, we propose the Discrete Morphological Neural Networks (DMNN) to represent and automatically design W-operators via machine learning. The design of a DMNN architecture, which is represented by a Morphological Computational Graph, is equivalent to the first part of the classical heuristic design of operators, in which the designer should combine basic operators and operations based on prior information and theoretical knowledge of MM. When such a combination satisfies certain axioms, it is equivalent to an architecture of a canonical DMNN. Then, once the architecture is fixed, instead of adjusting its parameters by hand, we propose the lattice gradient descent algorithm (LGDA) to train these parameters based on a sample of input and output images under the usual machine learning approach for learning W-operators. Since the
LGDA, that is based on the U-curve algorithms [3, 18, 36, 37], is a combinatorial algorithm whose complexity increases exponentially with the number of computational nodes in the architecture computational graph, we also propose a stochastic version of it that, even though is suboptimal, is much more efficient, is scalable and can obtain good results in practical problems.

The main contribution of this paper is the merger of the two main paradigms for designing morphological operators: classical heuristic design and automatic design via machine learning. On the hand, a DMNN architecture is equivalent to the manual combination of basic operators performed in heuristic design based on prior information and known properties of MM. On the other hand, the training of an architecture, or equivalently the adjustment of the parameters of the heuristic combination, is performed based on data under a machine learning framework. The adjustment of the parameters scales to more complex problems if one considers the stochastic LGDA, and the learning via the LGDA is general and not problem specific as many of the automatic design methods based on machine learning, so the DMNN is a contribution to both design paradigms. This merger is a flexible and transparent approach for automatically designing W-operators in general settings via machine learning.

### Paper structure

In Section 2, we present the main elements of Boolean lattices, in Section 3, we present the canonical decomposition of set operators, and in Section 4, we summarize the main results of [9] about the composition of operators in the canonical form. Sections 2 to 4 follow the presentation of [9]. In Section 5, we define the Morphological Computation Graph and the Discrete Morphological Neural Networks, and then show that DMNN are universal representers of translation invariant and locally defined set operators. In Section 6, we particularize to the canonical DMNN, and in Section 7, we propose the lattice gradient descent algorithm to train them. In Section 8, we illustrate the proposed method with an application, and in Section 9, we discuss the main contributions of this paper.

## 2. Elements of Boolean lattices

Let \(E\) by a non-empty set, and let \(W\) be a finite subset of \(E\). We assume that \((E,+)\) is an _Abelian group_ with respect to a binary operation denoted by \(+\). We denote the zero element of \(E\) by \(o\). Let \(\mathcal{P}(W)\) be the collection of all subsets of \(W\) and let \(\subseteq\) be the usual inclusion relation on sets. The pair \((\mathcal{P}(W),\subseteq)\) is a complete Boolean lattice, with least and greatest element \(\emptyset\)
and \(W\), respectively. The intersection and union of \(X_{1}\) and \(X_{2}\) in \(\mathcal{P}(W)\) are, respectively, \(X_{1}\cap X_{2}\) and \(X_{1}\cup X_{2}\).

Given \(A,B\in\mathcal{P}(W)\), the sub-collection \([A,B]\) of \(\mathcal{P}(W)\) defined by

\[[A,B]=\{X\in\mathcal{P}(W):A\subseteq X\subseteq B\}\]

is called a closed interval, or simply interval. If \(A\subseteq B\), then \(A\) and \(B\) are called, respectively, the left and right extremities of \([A,B]\). For all pairs \((A,B)\) such that \(A\nsubseteq B\), \([A,B]\) represents the empty collection \(\emptyset\).

We will denote sub-collections of \(\mathcal{P}(W)\) by uppercase script letters \(\mathcal{A},\mathcal{B},\ldots,\mathcal{X},\mathcal{Y},\mathcal{Z}\). The collections of closed intervals will be denoted by uppercase bold face letters \(\boldsymbol{A},\boldsymbol{B},\ldots,\boldsymbol{X}\),

\(\boldsymbol{Y},\boldsymbol{Z}\).

An element of a collection of closed intervals \(\boldsymbol{X}\) is called _maximal in_\(\boldsymbol{X}\) if no other element of \(\boldsymbol{X}\) properly contains it, that is, \(\forall[A,B]\in\boldsymbol{X}\),

\[[A,B]\text{ is maximal in }\boldsymbol{X}\iff\forall[A^{\prime},B^{ \prime}]\in\boldsymbol{X},[A,B]\subseteq[A^{\prime},B^{\prime}]\implies[A,B] =[A^{\prime},B^{\prime}].\]

The collection of maximal closed intervals in \(\boldsymbol{X}\) is denoted by \(\operatorname{Max}(\boldsymbol{X})\).

Let \(\mathcal{X}\) be a sub-collection of \(\mathcal{P}(W)\). The collection of all maximal closed intervals contained in \(\mathcal{X}\) is denoted by \(\boldsymbol{M}(\mathcal{X})\) and is given by

\[\boldsymbol{M}(\mathcal{X})=\operatorname{Max}\left(\{[A,B]\subseteq\mathcal{ P}(W):[A,B]\subseteq\mathcal{X}\}\right).\]

Usually, we will denote a sub-collection and the set of maximal intervals contained in it by the same letter, for example \(\boldsymbol{X}=\boldsymbol{M}(\mathcal{X})\).

We denote by \(\cup\boldsymbol{X}\) the collection of all elements of \(\mathcal{P}(W)\) that are elements of closed intervals in \(\boldsymbol{X}\), that is

\[\cup\boldsymbol{X}=\{X\in\mathcal{P}(W):X\in[A,B],[A,B]\in\boldsymbol{X}\}.\]

Note that, for any \(\mathcal{X}\subseteq\mathcal{P}(W),\;\cup\boldsymbol{X}=\mathcal{X}\). Since \(W\) is finite and \(\mathcal{X}\subseteq\mathcal{P}(W)\), for any \([A,B]\subseteq\mathcal{X}\), there exists \([A^{\prime},B^{\prime}]\in\boldsymbol{M}(\mathcal{X})\) such that \([A,B]\subseteq[A^{\prime},B^{\prime}]\), and hence any sub-collection \(\mathcal{X}\) can be represented by its maximal closed intervals.

Let \(\mathcal{P}(\mathcal{P}(W))\) be the collection of all sub-collections of \(\mathcal{P}(W)\) and let \(\subseteq\) be the usual inclusion relation on sets. The pair \((\mathcal{P}(\mathcal{P}(W)),\subseteq)\) is a complete Boolean lattice. The least and the greatest element of \(\mathcal{P}(\mathcal{P}(W))\) are, respectively, \(\emptyset\) and \(\mathcal{P}(W)\). The intersection and the union of \(\mathcal{X}_{1}\) and \(\mathcal{X}_{2}\) in
\(\mathcal{P}(\mathcal{P}(W))\) are, respectively, \(\mathcal{X}_{1}\cap\mathcal{X}_{2}\) and \(\mathcal{X}_{1}\cup\mathcal{X}_{2}\). The complementary collection of a sub-collection \(\mathcal{X}\) in \(\mathcal{P}(\mathcal{P}(W))\), with respect to \(\mathcal{P}(W)\), is defined as \(\mathcal{X}^{c}=\{X\in\mathcal{P}(W):X\notin\mathcal{X}\}\).

Let \(\Pi_{W}\coloneqq\{\boldsymbol{M}(\mathcal{X}):\mathcal{X}\subseteq\mathcal{P} (W)\}\) be the collection of the sub-collections of maximal intervals of \(\mathcal{P}(W)\). We will define the partial order \(\leqslant\) on the elements of \(\Pi_{W}\) by setting, \(\forall\boldsymbol{X},\boldsymbol{Y}\in\Pi_{W}\),

\[\boldsymbol{X}\leqslant\boldsymbol{Y}\iff\forall[A,B]\in\boldsymbol{X}, \exists[A^{\prime},B^{\prime}]\in\boldsymbol{Y}:[A,B]\subseteq[A^{\prime},B^{ \prime}].\]

The poset \((\Pi_{W},\leqslant)\) constitutes a complete Boolean lattice, with infimum, supremum and complement operations given, respectively, by

\[\boldsymbol{X}\cap\boldsymbol{Y}=\boldsymbol{M}(\mathcal{X}\cap\mathcal{Y}) \qquad\boldsymbol{X}\sqcup\boldsymbol{Y}=\boldsymbol{M}(\mathcal{X}\cup \mathcal{Y})\qquad\bar{\boldsymbol{X}}=\boldsymbol{M}(\mathcal{X}^{c})\]

for all \(\boldsymbol{X},\boldsymbol{Y}\in\Pi_{W}\), in which \(\boldsymbol{X}=\boldsymbol{M}(\mathcal{X})\) and \(\boldsymbol{Y}=\boldsymbol{M}(\mathcal{Y})\). These expressions follow since the mapping \(\boldsymbol{M}(\cdot)\), defined from \(\mathcal{P}(\mathcal{P}(W))\) to \(\Pi_{W}\), is a lattice isomorphism. The inverse of the mapping \(\boldsymbol{M}(\cdot)\) is the mapping \(\cup(\cdot)\). In particular, the least and the greatest element of \((\Pi_{W},\leqslant)\) are, respectively, \(\boldsymbol{M}(\
\(\theta,\lambda,\mu,...\) and collections of set operators by uppercase Greek letters \(\Psi,\Theta,\Gamma,\Lambda,\Delta,\Phi,\Omega,\Sigma,...\). The set \(\Psi\) of all the operators from \(\mathcal{P}(E)\) to \(\mathcal{P}(E)\) inherits the complete lattice structure of \((\mathcal{P}(E),\subseteq)\) by setting, \(\forall\psi_{1},\psi_{2}\in\Psi\),

\[\psi_{1}\leqslant\psi_{2}\iff\psi_{1}(X)\subseteq\psi_{2}(X),\forall X\in \mathcal{P}(E). \tag{3.1}\]

The supremum and infimum of a subset \(\Theta\subseteq\Psi\) of the complete lattice \((\Psi,\leqslant)\) satisfy

\[\left(\bigvee\Theta\right)(X)=\bigcup\{\theta(X):\theta\in\Theta\}\qquad \qquad X\in\mathcal{P}(E),\]

and

\[\left(\bigwedge\Theta\right)(X)=\bigcap\{\theta(X):\theta\in\Theta\}\qquad \qquad X\in\mathcal{P}(E),\]

respectively.

For any \(h\in E\) and \(X\in\mathcal{P}(E)\), the set

\[X+h\coloneqq\{x\in E:x-h\in X\}\]

is called the translation of \(X\) by \(h\). We may also denote \(X+h\) as \(X_{h}\) and, in special, \(X_{o}=X\) in which \(o\) is the origin of \(E\). Let \(X^{t}\) be the transpose of \(X\in\mathcal{P}(E)\) defined as

\[X^{t}=\{y\in E:y=-x,x\in X\}.\]

A set operator \(\psi\) is called _translation invariant_ (t.i) if, and only if, \(\forall h\in E\),

\[\psi(X+h)=\psi(X)+h\qquad\qquad\qquad X\in\mathcal{P}(E).\]

Let \(W\) be a finite subset of \(E\). A set operator \(\psi\) is called _locally defined within a window_\(W\) if, and only if, \(\forall h\in E\),

\[h\in\psi(X)\iff h\in\psi(X\cap W_{h})\qquad\qquad\qquad X\in\mathcal{P}(E).\]

Let \(\Psi_{W}\) denote the collection of t.i. operators locally defined within a window \(W\in\mathcal{P}(E)\) and let

\[\Omega=\bigcup_{\begin{subarray}{c}W\in\mathcal{P}(E)\\ |W|<\infty\end{subarray}}\Psi_{W}\]
be the subset of \(\Psi\) of all operators from \(\mathcal{P}(E)\) to \(\mathcal{P}(E)\) that are t.i. and locally defined within some finite window \(W\in\mathcal{P}(E)\). The elements of \(\Omega\) are called _\(W\)-operators_. For each \(W\in\mathcal{P}(E)\), the pair \((\Psi_{W},\leqslant)\) constitutes a finite sub-lattice of the lattice \((\Psi,\leqslant)\).

The kernel \(\mathcal{K}_{W}(\psi)\) of a \(W\)-operator \(\psi\) is the sub-collection of \(\mathcal{P}(W)\) defined by

\[\mathcal{K}_{W}(\psi)=\{X\in\mathcal{P}(W):o\in\psi(X)\} \psi\in\Psi_{W}. \tag{3.2}\]

The mapping \(\mathcal{K}_{W}\) from \(\Psi_{W}\) to \(\mathcal{P}(\mathcal{P}(W))\) defined by (3.2) constitutes a lattice isomorphism between the lattices \((\Psi_{W},\leqslant)\) and \((\mathcal{P}(\mathcal{P}(W)),\subseteq)\). The inverse of the mapping \(\mathcal{K}_{W}\) is the mapping \(\mathcal{K}_{W}^{-1}\) defined by

\[\mathcal{K}_{W}^{-1}(\mathcal{X})(X)=\{x\in E:X_{-x}\cap W\in \mathcal{X}\}\qquad\mathcal{X}\in\mathcal{P}(\mathcal{P}(W)),X\in\mathcal{P}( E).\]

As a consequence of this isomorphism, we have that, \(\forall\psi_{1},\psi_{2}\in\Psi_{W}\),

\[\mathcal{K}_{W}(\psi_{1}\wedge\psi_{2})=\mathcal{K}_{W}(\psi_{1})\cap\mathcal{ K}_{W}(\psi_{2})\quad\text{and}\quad\mathcal{K}_{W}(\psi_{1}\vee\psi_{2})=\mathcal{K}_{W }(\psi_{1})\cup\mathcal{K}_{W}(\psi_{2}).\]

See [9, Proposition 4.1] for more details.

Define by \(\nu\) and \(\iota\) the set operators

\[\iota(X)=X \nu(X)=X^{c}\]

for \(X\in\mathcal{P}(E)\), called, respectively, the identity and the complement operators, in which the complement of \(X\) is with respect to \(E\): \(X^{c}=\{x\in E:x\notin X\}\).

For \(A,B\in\mathcal{P}(E)\), the operations

\[A\oplus B=\bigcup_{b\in B}A_{b} \text{and} A\ominus B=\bigcap_{b\in B}A_{-b}\]

are called, respectively, _Minkowski addition_ and _subtraction_. For \(B\in\mathcal{P}(W)\), the t.i. set operators \(\delta_{B}\) and \(\epsilon_{B}\) defined by

\[\delta_{B}(X)=X\oplus B X\in\mathcal{P}(E)\]

and

\[\epsilon_{B}(X)=X\ominus B X\in\mathcal{P}(E)\]
are called, respectively, _dilation_ and _erosion_ by \(B\). The set \(B\) is called structural element.

Let \(A,B\in\mathcal{P}(W)\) be such that \(A\subseteq B\). The t.i. set operators \(\lambda_{[A,B]}^{W}\) and \(\mu_{[A,B]}^{W}\) defined by

\[\lambda_{[A,B]}^{W}(X)=\{x\in E:A\subseteq X_{-x}\cap W\subseteq B\}\qquad \qquad X\in\mathcal{P}(E)\]

and

\[\mu_{[A,B]}^{W}(X)=\left\{x\in E:X_{-x}\cap A^{t}\neq\emptyset \text{ or }\left[X_{-x}\cap W^{t}\right]\cup B^{t}\neq W^{t}\right\}\quad X\in \mathcal{P}(E)\]

are called, respectively, sup-generating and inf-generating operators. These operators are locally defined within, respectively, \(W\) and \(W^{t}\). The sup-generating and inf-generating operators can be decomposed in terms of erosions and dilations, respectively, by

\[\lambda_{[A,B]}^{W}(X)=\epsilon_{A}(X)\cap\nu\delta_{B^{tc}}(X)\qquad\qquad X \in\mathcal{P}(E) \tag{3.3}\]

and

\[\mu_{[A,B]}^{W}(X)=\delta_{A}(X)\cup\nu\epsilon_{B^{ct}}(X)\qquad\qquad X\in \mathcal{P}(E) \tag{3.4}\]

in which the complement of \(B\) is taken relative to \(W\). The operators \(\nu\delta_{B^{tc}}\) and \(\nu\epsilon_{B^{ct}}\) are called, respectively, anti-dilation and anti-erosion.

The dual operator of \(\psi\), denoted by \(\psi^{\star}\), is defined as

\[\psi^{\star}=\nu\psi\nu.\]

The next result, due to a specialization of the results in [4] proved in [9], presents two decompositions of a \(W\)-operator called canonical sup-decomposition and canonical inf-decomposition.

**Proposition 3.1**.: _Let \(\psi\) be a \(W\)-operator. Then \(\psi\) can be decomposed as_

\[\psi(X)=\bigcup\left\{\lambda_{[A,B]}^{W}(X):[A,B]\subset\mathcal{K}_{W}(\psi )\right\}\qquad\qquad X\in\mathcal{P}(E)\]

_and_

\[\psi(X)=\bigcap\left\{\mu_{[A^{t},B^{t}]}^{W^{t}}(X):[A,B]\subset \mathcal{K}_{W}(\psi^{\star})\right\}\qquad\quad X\in\mathcal{P}(E),\]

_called, respectively, canonical sup-decomposition and canonical inf-decomposition of \(\psi\)._
These decompositions are quite general, but there may exist a smaller family of sup-generating or inf-generating operators that represents a same operator. Indeed, let

\[\boldsymbol{B}_{W}(\psi)\coloneqq\boldsymbol{M}\left(\mathcal{K}_{W}(\psi)\right) \psi\in\Psi_{W}\]

be the collection of all maximal closed intervals contained in \(\mathcal{K}_{W}(\psi)\). We call \(\boldsymbol{B}_{W}(\psi)\) the _basis_ of \(\psi\) and obtain the following simplification of the decompositions in Proposition 3.1.

**Corollary 3.2**.: _Let \(\psi\) be a \(W\)-operator. Then \(\psi\) can be decomposed as_

\[\psi(X)=\bigcup\left\{\lambda_{[A,B]}^{W}(X):[A,B]\in\boldsymbol{B}_{W}(\psi)\right\} \qquad\qquad X\in\mathcal{P}(E)\]

_and_

\[\psi(X)=\bigcap\left\{\mu_{[A^{t},B^{t}]}^{W^{t}}(X):[A,B]\in \boldsymbol{B}_{W}(\psi^{\star})\right\}\qquad\quad X\in\mathcal{P}(E).\]

From Proposition 3.1 and Corollary 3.2 follow that \(W\)-operators are uniquely determined, or parametrized, by their kernel or their basis. As a consequence of the isomorphisms in Figure 1, a \(W\)-operator can also be represented by a Boolean function, as follows.

Let \(T\) be the mapping between \(\Psi_{W}\) and \(\mathfrak{B}_{W}\) defined by

\[T(\psi)(X)=\begin{cases}1,&\text{ if }o\in\psi(X)\\ 0,&\text{ otherwise.}\end{cases}\qquad\qquad\psi\in\Psi_{W},X\in\mathcal{P}(W).\]

The mapping \(T\) constitutes a lattice isomorphism between the complete lattices \((\Psi_{W},\leq)\) and \((\mathfrak{B}_{W},\leq)\), and its inverse \(T^{-1}\) is defined by

\[T^{-1}(f)(X)=\{x\in E:f(X_{-x}\cap W)=1\}\qquad f\in\mathfrak{B}_{W},X\in \mathcal{P}(E).\]

We note that underlying all these decomposition results are the isomorphisms between \((\Psi_{W},\leq),(\mathcal{P}(\mathcal{P}(W)),\leq),(\Pi_{W},\leq)\) and \((\mathfrak{B}_{W},\leq)\) depicted in Figure 1.

## 4. Composition of Operators in the Canonical Form

The basic operations between set operators are supremum, infimum, and composition. In this section, we summarize the main results of [9] regarding the basis of set operators obtained via such operations.
The first result are assertions about the window of the supremum, infimum, and composition of set operators. For any \(h\in E\) let

\[\tau_{h}(X) =X+h X\in\mathcal{P}(E)\]

be the _translation by \(h\) operator_.

**Proposition 4.1**.: _Let \(\psi\in\Psi_{W},\psi_{1}\in\Psi_{W_{1}}\) and \(\psi_{2}\in\Psi_{W_{2}}\) be t.i. operators locally defined within windows \(W,W_{1},W_{2}\in\mathcal{P}(E)\), respectively. The following hold:_

1. _The operator_ \(\psi\) _is locally defined within any window_ \(W^{\prime}\supseteq W\)_._
2. _The operators_ \(\psi_{1}\vee\psi_{2}\) _and_ \(\psi_{1}\wedge\psi_{2}\) _are t.i. and locally defined within the window_ \(W_{1}\cup W_{2}\)_._
3. _For any_ \(h\in E\)_,_ \(\tau_{h}\psi\) _is t.i. and locally defined within the window_ \(W-h\)_._
4. _For_ \(B\in\mathcal{P}(E)\)_, the operators_ \(\delta_{B}\psi\) _and_ \(\epsilon_{B}\psi\) _are t.i. and locally defined, respectively, within windows_ \(W\oplus B^{t}\) _and_ \(W\oplus B\)

Figure 1. The lattice isomorphisms between representations of W-operators.
_
* _The operator_ \(\psi_{2}\psi_{1}\) _is t.i. and locally defined within the window_ \(W_{1}\oplus W_{2}\)_._

From Proposition 4.1 follows that the collection \(\Omega\) of all t.i. and locally defined set operators is closed under finite composition, infimum, and supremum.

**Corollary 4.2**.: _The set \(\Omega\) of all translation invariant and locally defined set operators from \(\mathcal{P}(E)\) to \(\mathcal{P}(E)\) is closed under finite composition, infimum, and supremum._

The next result presents the basis of the supremum, infimum, and composition of set operators. See [9] for a proof.

**Proposition 4.3**.: _Let \(\psi\in\Psi_{W},\psi_{1}\in\Psi_{W_{1}}\) and \(\psi_{2}\in\Psi_{W_{2}}\) be t.i. operators locally defined within windows \(W,W_{1},W_{2}\in\mathcal{P}(E)\), respectively. The following hold:_

* \(\boldsymbol{B}_{W_{1}\cup W_{2}}(\psi_{1}\wedge\psi_{2})=\boldsymbol{B}_{W_{1 }\cup W_{2}}(\psi_{1})\sqcap\boldsymbol{B}_{W_{1}\cup W_{2}}(\psi_{2})\)__
* \(\boldsymbol{B}_{W_{1}\cup W_{2}}(\psi_{1}\vee\psi_{2})=\boldsymbol{B}_{W_{1} \cup W_{2}}(\psi_{1})\sqcap\boldsymbol{B}_{W_{1}\cup W_{2}}(\psi_{2})\)__
* \(\boldsymbol{B}_{W}(\nu\psi)=\bar{\boldsymbol{B}}_{W}(\psi)\)__
* \(\boldsymbol{B}_{W-h}(\tau_{h}\psi)=\boldsymbol{B}_{W}(\psi)-h\)__
* _For_ \(B\in\mathcal{P}(E)\)_,_ \(\boldsymbol{B}_{W\oplus B^{t}}(\delta_{B}\psi)=\bigsqcup_{b\in B}\boldsymbol{B }_{W\oplus B^{t}}(\tau_{b}\psi)\)__
* _For_ \(B\in\mathcal{P}(E)\)_,_ \(\boldsymbol{B}_{W\oplus B}(\epsilon_{B}\psi)=\bigsqcup_{b\in B^{t}} \boldsymbol{B}_{W\oplus B}(\tau_{b}\psi)\)__
* _Denoting_ \(\boldsymbol{B}_{W_{2}}(\psi_{2})=\{[A_{i},B_{i}]:i\in\mathfrak{I}\}\)_, then_ \[\boldsymbol{B}_{W_{1}\oplus W_{2}}(\psi_{2}\psi_{1})=\bigsqcup\bigbig{\{} \boldsymbol{B}_{W_{1}\oplus W_{2}}(\epsilon_{A_{i}}\psi_{1})\sqcap\bar{ \boldsymbol{B}}_{W_{1}\oplus W_{2}}(\delta_{B_{i}^{ct}}\psi_{1}):i\in \mathfrak{I}\}\]

## 5. Discrete Morphological Neural Networks

A Morphological Discrete Neural Network (DMNN) can be represented as a computational graph with vertices that compute either a \(W\)-operator, or one of the two basic supremum and infimum operations. A DMNN realizes the \(W\)-operator computed by its computational graph. We start by defining the Morphological Computational Graphs that represent DMNN. Then, we define a DMNN architecture and the space of \(W\)-operators realized by it, and
show that any \(W\)-operator may be non-trivially represented by a DMNN. We end this section showing that DMNN are universal representers of t.i and locally defined set operators.

### Morphological Computational Graph

Let \(\mathcal{G}=(\mathcal{V},\mathcal{E},\mathcal{C})\) be a _computational graph_, in which \(\mathcal{V}\) is a general set of vertices, \(\mathcal{E}\subset\{(\mathfrak{v}_{1},\mathfrak{v}_{2})\in\mathcal{V}\times \mathcal{V}:\mathfrak{v}_{1}\neq\mathfrak{v}_{2}\}\) is a set of directed edges, and \(\mathcal{C}:\mathcal{V}\rightarrow\Omega\cup\{\vee,\wedge\}\) is a mapping that associates each vertex \(\mathfrak{v}\in\mathcal{V}\) to a _computation_ given by either applying a t.i. and locally defined operator \(\psi\in\Omega\) or one of the two basic operations \(\{\vee,\wedge\}\).

For each \(\mathfrak{v}\in\mathcal{V}\) we denote by

\[\mathds{I}(\mathfrak{v})=\{\mathfrak{a}\in\mathcal{V}:(\mathfrak{a}, \mathfrak{v})\in\mathcal{E}\}\]

the vertices in \(\mathcal{V}\) connected with \(\mathfrak{v}\) by an edge ending in \(\mathfrak{v}\) (input vertices of \(\mathfrak{v}\)), and

\[\mathsf{O}(\mathfrak{v})=\{\mathfrak{a}\in\mathcal{V}:(\mathfrak{v}, \mathfrak{a})\in\mathcal{E}\}\]

as the vertices in \(\mathcal{V}\) connected with \(\mathfrak{v}\) by an edge starting in \(\mathfrak{v}\) (output vertices of \(\mathfrak{v}\)).

We say that \(\mathcal{G}\) is a Morphological Computational Graph (MCG) when the following conditions are satisfied.

**Axioms of Morphological Computational Graphs** A computational graph \(\mathcal{G}=(\mathcal{V},\mathcal{E},\mathcal{C})\) is a Morphological Computational Graph if, and only if, all the following conditions hold:

* **A1**: The directed graph \((\mathcal{V},\mathcal{E})\) is acyclic and the number of vertices is finite and greater than 2, i.e., \(2<|\mathcal{V}|<\infty\);
* **A2**: There exists a unique \(\mathfrak{v}_{i}\in\mathcal{V}\) with \(|\mathds{I}(\mathfrak{v}_{i})|=0\) and it computes the identity operator, i.e., \(\mathcal{C}(\mathfrak{v}_{i})=\iota\);
* **A3**: There exists a unique \(\mathfrak{v}_{o}\in\mathcal{V}\) with \(|\mathsf{O}(\mathfrak{v}_{o})|=0\) and it computes the identity operator, i.e., \(\mathcal{C}(\mathfrak{v}_{o})=\iota\);
* **A4**: If \(\mathcal{C}(\mathfrak{v})\in\Omega\), then \(|\mathds{I}(\mathfrak{v})|=1\);
* **A5**: If \(\mathcal{C}(\mathfrak{v})\in\{\vee,\wedge\}\), then \(|\mathds{I}(\mathfrak{v})|\geqslant 2\).
* **A6**: For all \(\mathfrak{v}\in\mathcal{V},\mathfrak{v}\neq\mathfrak{v}_{o}\), \(|\mathsf{O}(\mathfrak{v})|\geqslant 1\).
The computation of a vertex \(\mathfrak{v}\) in \(\mathcal{G}\) receives as input the output of the computation of the vertices in \(\mathds{I}(\mathfrak{v})\), and the output of its computation will be used as the input of the computation of the vertices in \(\mathds{O}(\mathfrak{v})\). We assume there is an input vertex \(\mathfrak{v}_{i}\), and an output vertex \(\mathfrak{v}_{o}\), that store the input, which is an element \(X\in\mathcal{P}(E)\), and output of the computational graph, respectively. These vertices cannot have, respectively, an edge ending and starting in them (**A2** and **A3**). The directed graph \((\mathcal{V},\mathcal{E})\) should be acyclic, so each computation is performed at most once in any path of \((\mathcal{V},\mathcal{E})\), and there should be at least three vertices in \(\mathcal{V}\) so it is not formed solely by the input and output vertices; there must be a finite number of vertices so the computation of \(\mathcal{G}\) is possible (**A1**).

On the one hand, if \(\mathcal{C}(\mathfrak{v})\in\Omega\), then the computation of \(\mathfrak{v}\) is given by applying a t.i. and locally defined set operator which has only one input, so it must hold \(|\mathds{I}(\mathfrak{v})|=1\) (**A4**). On the other hand, if \(\mathcal{C}(\mathfrak{v})\in\{\vee,\wedge\}\), then the computation of \(\mathfrak{v}\) is given by taking the infimum or the supremum of the output of at least two preceding computations, so it must hold \(|\mathds{I}(\mathfrak{v})|\geq 2\) (**A5**). Apart from the output vertex \(\mathfrak{v}_{o}\), all other vertices should have at least one edge starting in them, so their computation is the input of at least one other vertex (**A6**). Table 5.1 summarizes the types of vertices of an MCG.

Since the input of the vertex \(\mathfrak{v}_{i}\) is an element of \(\mathcal{P}(E)\), the output and the input of all computations performed by vertices in \(\mathcal{G}\) are elements of \(\mathcal{P}(E)\). Denoting by \(\psi_{\mathcal{G}}(X)\) the output of vertex \(\mathfrak{v}_{o}\) when the input of vertex \(\mathfrak{v}_{i}\) is \(X\in\mathcal{P}(E)\), we have that the MCG \(\mathcal{G}\) generates a set operator \(\psi_{\mathcal{G}}:\mathcal{P}(E)\to\mathcal{G}(E)\).

\begin{table}
\begin{tabular}{c c c c c c} \hline Symbol & Name & \(\mathcal{C}(\mathfrak{v})\) & \(|\mathds{I}(\mathfrak{v})|\) & \(|\mathds{O}(\mathfrak{v})|\) & Description \\ \hline \(X\) & Input vertex \(\mathfrak{v}_{i}\) & \(\iota\) & \(0\) & \(\geq 1\) & Receive and store the input \(X\in\mathcal{P}(E)\) of \(\mathcal{G}\) \\ \(\psi\) & Set operator vertex & \(\psi\in\Omega\) & \(1\) & \(\geq 1\) & Apply operator \(\psi=\mathcal{C}(\mathfrak{v})\in\Omega\) to its input \\ \(\psi\) & Supremum vertex & \(\vee\) & \(\geq 2\) & \(\geq 1\) & Take the supremum of its inputs \\ \(\psi\) & Infimum vertex & \(\wedge\) & \(\geq 2\) & \(\geq 1\) & Take the infimum of its inputs \\ \(\psi_{\mathcal{G}}\) & Output vertex \(\mathfrak{v}_{o}\) & \(\iota\) & \(1\) & \(0\) & Receive and store the output \(\psi_{\mathcal{G}}(X)\) of \(\mathcal{G}\) \\ \hline \hline \end{tabular}
\end{table}
Table 5.1. Types of vertices of a Morphological Computational Graph.
\(\mathcal{P}(E)\). Actually, it follows from Corollary 4.2 that \(\psi_{\mathcal{G}}\) is actually t.i. and locally defined within a window \(W_{\mathcal{G}}\).

**Proposition 5.1**.: _Let \(\mathcal{G}=(\mathcal{V},\mathcal{E},\mathcal{C})\) be a Morphological Computational Graph. Then \(\psi_{\mathcal{G}}\) is translation invariant and locally defined within a finite window \(W_{\mathcal{G}}\in\mathcal{P}(E)\)._

Proof.: Fix \(X\in\mathcal{P}(E)\) and let

\[\Omega_{\mathcal{G}}=\{\psi\in\Omega:\exists\mathfrak{v}\in\mathcal{V}\text{ s.t. }\mathcal{C}(\mathfrak{v})=\psi\}\subseteq\Omega\]

be the finite collection of t.i. and locally defined set operators applied by vertices in \(\mathcal{V}\). Since \(\psi_{\mathcal{G}}(X)\) is obtained by combining the set operators in \(\Omega_{\mathcal{G}}\) via the composition, supremum and infimum operations, and \(\Omega\) is closed under finite composition, infimum and supremum (cf. Corollary 4.2), it follows that \(\psi_{\mathcal{G}}\in\Omega\), and hence it is a t.i. and locally defined set operator. 

**Remark 5.2**.: _An algorithm to calculate a window \(W_{\mathcal{G}}\) of \(\psi_{\mathcal{G}}\) or its basis \(\boldsymbol{B}_{W_{\mathcal{G}}}(\psi_{\mathcal{G}})\) is a consequence of the results of [9] summarized in Propositions 4.1 and 4.3. The window or the basis may be computed via the computational graph \(\mathcal{G}\), but instead of applying the computations determined by \(\mathcal{C}\), one combines the windows or basis of the input vertices based on Propositions 4.1 and 4.3 to obtain the window or basis of the set operator defined as the output of each vertex. At the end of the computations, the window or basis stored in the output vertex will be that of \(\psi_{\mathcal{G}}\)._

We are in position to define the DMNN represented by an MCG.

**Definition 5.3**.: _Let \(\mathcal{G}=(\mathcal{V},\mathcal{E},\mathcal{C})\) be a Morphological Computational Graph. We define the Morphological Discrete Neural Network represented by \(\mathcal{G}\) as the translation invariant and locally defined set operator \(\psi_{\mathcal{G}}\)._

We present four examples of MCG which, respectively, trivially represents a \(\psi\in\Omega\), represents \(\psi\) via its canonical sup-generating or inf-generating decomposition, represents an alternate-sequential filter, and represents the composition of an alternate-sequential filter and a W-operator.

**Example 5.4** (Trivial DMNN).: Fix \(\psi\in\Omega\) and let \(\mathcal{G}\) be the MCG with \(\mathcal{V}=\{\mathfrak{v}_{i},\mathfrak{v},\mathfrak{v}_{o}\}\), \(\mathcal{E}=\{(\mathfrak{v}_{i},\mathfrak{v}),(\mathfrak{v},\mathfrak{v}_{o})\}\) and \(\mathcal{C}(\mathfrak{v})=\psi\). This MCG, depicted in Figure 2, is such that \(\psi=\psi_{\mathcal{G}}\) and illustrates that any \(\psi\in\Omega\) can be trivially represented by a DMNN.
**Example 5.5** (Sup-generating and inf-generating DMNN).: Let \(\psi\in\Psi_{W}\). Due to the canonical inf and sup-generating decomposition of \(\psi\) (cf. Proposition 3.1), it can be represented by a DMNN with a vertex for each element in \(\boldsymbol{B}_{W}(\psi)\), that applies the respective inf or sup-generating operator to the input \(X\in\mathcal{P}(E)\), and an infimum or supremum vertex that combines their output, respectively. The inf and sup-generating DMNN are represented in Figure 3. This example illustrates that any t.i. and locally defined set operator can be non-trivially represented by a DMNN.

**Example 5.6** (Alternate-sequential filters DMNN).: The DMNN are specially useful to represent operators that can be decomposed sequentially as the composition of set operators. A special class of such operators are the alternate-sequential filters (ASF) which are defined as the interleaved composition of openings and closings. Fixed a structural element \(B\in\mathcal{P}(E)\), the opening \(\gamma_{B}\) and the closing \(\phi_{B}\) are the set operators defined, respectively, as

\[\gamma_{B}=\delta_{B}\epsilon_{B} \phi_{B}=\epsilon_{B}\delta_{B}, \tag{5.1}\]

Figure 2. Trivial DMNN representation of \(\psi\in\Omega\).
that are, respectively, an erosion followed by a dilation and a dilation followed by an erosion. Openings and closings are increasing and idempotent set operators. The openings are anti-extensive, i.e., \(\gamma_{B}(X)\subseteq X\), and the closings are extensive, i.e., \(X\subseteq\phi_{B}(X)\). See [43, Section 5.4] for more details.

Let \(\gamma_{B_{1}},\phi_{B_{1}},\ldots,\gamma_{B_{n}},\phi_{B_{n}}\) be a sequence of \(n\) openings and \(n\) closings. The set operator \(\psi\) given by

\[\psi=\phi_{B_{n}}\gamma_{B_{n}}\cdots\phi_{B_{1}}\gamma_{B_{1}}\]

is called an alternate-sequential filter. Figure 4 presents three DMNN representations of \(\psi\) in which, respectively, the vertices are a composition of an opening and a closing, the vertices are openings or closings, and the vertices are erosions or dilations.

**Example 5.7** (Composition of an ASF and a W-operator).: Figure 5 presents a DMNN representation of a composition of an ASF \(\phi_{A}\gamma_{A}\) and a \(\psi\in\Psi_{W}\) with three elements in its basis. This example illustrates how elements of sequential and sup-generating architectures may be combined to obtain more complex DMNN.

The examples above illustrate the flexibility of a DMNN in representing any t.i. and locally defined set operator. Such a flexibility allows, for instance, the representation of \(\psi\) by a DMNN that is more efficiently computed
via an MCG \(\mathcal{G}\) or that has fewer _parameters_. Another feature of this flexibility is the possibility of defining a class of set operators through restrictions on the set of all MCG. Indeed, since the mapping \(\psi_{\mathcal{G}}\), from the collection of all MCG to \(\Omega\), is surjective, restrictions on the MCG structure may generate restrictions on \(\Omega\). In the next section, we formalize the restricted classes of MCG, which are the architectures of DMNN.

### DMNN Architectures

Let \(\mathcal{A}=(\mathcal{V},\mathcal{E},\mathcal{F})\) in which \(\mathcal{V}\) is a set of vertices, \(\mathcal{E}\subset\mathcal{V}\times\mathcal{V}\) is a set of ordered edges and \(\mathcal{F}\subseteq\left(\Omega\cup\left\{\vee,\wedge\right\}\right)^{ \mathcal{V}}\) is a collection of functions from \(\mathcal{V}\) to \(\Omega\cup\left\{\vee,\wedge\right\}\). We say that \(\mathcal{A}\) is the architecture of a DMNN if it satisfies the following condition.

**Axiom of Morphological Discrete Neural Network Architectures** A triple \(\mathcal{A}=(\mathcal{V},\mathcal{E},\mathcal{F})\) is a Morphological Discrete Neural Network architecture if, and only if, \((\mathcal{V},\mathcal{E},\mathcal{C})\) is a Morphological Computational Graph for all \(\mathcal{C}\in\mathcal{F}\).

A DMNN architecture is actually a collection of MCG with same graph \((\mathcal{V},\mathcal{E})\) and computation map \(\mathcal{C}\) in \(\mathcal{F}\). Since a DMNN architecture represents a collection of MCG, it actually represents a collection of t.i. and locally defined set operators (cf. Proposition 5.1). For an architecture \(\mathcal{A}=(\mathcal{V},\mathcal{E},\mathcal{F})\), let

\[\mathbb{G}(\mathcal{A})=\left\{\mathcal{G}=(\mathcal{V},\mathcal{E},\mathcal{ C}):\mathcal{C}\in\mathcal{F}\right\}\]
be the collection of MGC generated by \(\mathcal{A}\). We say that \(\mathcal{G}\in\mathbb{G}(\mathcal{A})\) is a realization of architecture \(\mathcal{A}\) and we define

\[\mathcal{H}(\mathcal{A})=\{\psi\in\Omega:\psi=\psi_{\mathcal{G}},\mathcal{G}\in \mathbb{G}(\mathcal{A})\}\]

as the collection of t.i. and locally defined set operators that can be realized by \(\mathcal{A}\).

We present three examples of DMNN architectures.

**Example 5.8** (Sup-generating DMNN architecture).: Figure 6 presents two examples of sup-generating architectures, which are characterized by the supremum of sup-generating set operators. In both examples, we consider the graph \((\mathcal{V},\mathcal{E})\) such that \(\mathcal{V}=\{\mathfrak{v}_{i},\mathfrak{v}_{1},\mathfrak{v}_{2},\mathfrak{v} _{3},\mathfrak{v}_{\vee},\mathfrak{v}_{o}\}\) and

\[\mathcal{E}=\{(\mathfrak{v}_{i},\mathfrak{v}_{1}),(\mathfrak{v}_{i},\mathfrak{ v}_{2}),(\mathfrak{v}_{i},\mathfrak{v}_{3}),(\mathfrak{v}_{1},\mathfrak{v}_{ \vee}),(\mathfrak{v}_{2},\mathfrak{v}_{\vee}),(\mathfrak{v}_{3},\mathfrak{v }_{\vee}),(\mathfrak{v}_{\vee},\mathfrak{v}_{o})\}.\]

The architecture \(\mathcal{A}_{1}=(\mathcal{V},\mathcal{E},\mathcal{F}_{1})\) is such that, for all \(\mathcal{C}\in\mathcal{F}\), \(\mathcal{C}(\mathfrak{v}_{i})=\mathcal{C}(\mathfrak{v}_{o})=\iota\), \(\mathcal{C}(\mathfrak{v}_{\vee})=\vee\) and

\[\mathcal{C}(\mathfrak{v}_{j})=\lambda_{[A,B]}^{W}\text{ with }A,B\in\mathcal{P}(W),A \subseteq B\qquad\qquad j=1,2,3,\]

which realizes the \(W\)-operators with at most three elements in their basis, that is,

\[\mathcal{H}(\mathcal{A}_{1})=\{\psi\in\Psi_{W}:|\boldsymbol{B}_{W}(\psi)| \leq 3\}\,.\]

Denoting

\[\Lambda_{W}=\{\lambda_{[A,B]}^{W}:A,B\in\mathcal{P}(W),A\subseteq B\}\]

as the sup-generating set operators locally defined within \(W\), it follows that

\[\mathcal{F}_{1}=\{\iota\}\times\Lambda_{W}\times\Lambda_{W}\times\Lambda_{W} \times\{\vee\}\times\{\iota\},\]

so \(\mathcal{F}_{1}\) is the Cartesian product of elements in \(\mathcal{P}(\Psi_{W})\cup\{\{\vee\},\{\wedge\}\}\). This means that, under this architecture, the computation of each vertex can be chosen independently of one another.

Denoting

\[\Sigma_{W}=\{\epsilon_{A}^{W}:A\in\mathcal{P}(W)\}\]

as the erosions with structural elements in \(\mathcal{P}(W)\), the architecture \(\mathcal{A}_{2}\) is such that

\[\mathcal{F}_{2}=\{\iota\}\times\Sigma_{W}\times\Sigma_{W}\times\Sigma_{W} \times\{\vee\}\times\{\iota\},\]
so it realizes the more restricted class of increasing \(W\)-operators with at most three elements in their basis, that is,

\[\mathcal{H}(\mathcal{A}_{2})=\left\{\psi\in\Psi_{W}:\psi\text{ is increasing},| \boldsymbol{B}_{W}(\psi)|\leq 3\right\},\]

which can be represented by the supremum of three erosions. Even though \(\mathcal{A}_{1}\) and \(\mathcal{A}_{2}\) have the same graph, \(\mathcal{H}(\mathcal{A}_{2})\subseteq\mathcal{H}(\mathcal{A}_{1})\) so \(\mathcal{A}_{2}\) is a restriction of \(\mathcal{A}_{1}\).

**Example 5.9** (Sequential DMNN architecture).: Figure 7 presents three examples of sequential DMNN architectures characterized by the absence of supremum and infimum vertices. The architectures \(\mathcal{A}_{1}\) and \(\mathcal{A}_{2}\) have the same graph \((\mathcal{V},\mathcal{E})\) with \(\mathcal{V}=\{\mathfrak{v}_{i},\mathfrak{v}_{1},\mathfrak{v}_{2},\mathfrak{v} _{3},\mathfrak{v}_{4},\mathfrak{v}_{o}\}\) and \(\mathcal{E}\) linking the vertices in sequence. For fixed windows \(W_{1},W_{2}\in\mathcal{P}(E)\), the architecture \(\mathcal{A}_{1}\) is such that

\[\mathcal{F}_{1}=\{\iota\}\times\Psi_{W_{1}}\times\Psi_{W_{1}}\times\Psi_{W_{2 }}\times\Psi_{W_{2}}\times\{\iota\}\]

Figure 6. Two DMNN architectures with the same graph that represent sup-generating decompositions. When we exchange a parameter by a dot, we mean that it is free, so \(\lambda^{W}\) represents any sup-generating operator locally defined within \(W\) and \(\epsilon^{W}\) represents any erosion locally defined within \(W\). Architecture \(\mathcal{A}_{1}\) realizes all \(\psi\in\Psi_{W}\) with at most 3 elements in the basis, i.e., \(|\boldsymbol{B}_{W}(\psi)|\leq 3\), while architecture \(\mathcal{A}_{2}\) realizes all \(\psi\in\Psi_{W}\) that can be written as the supremum of three erosions, which are actually the increasing operators in \(\Psi_{W}\) with at most three elements in their basis. See Figure 3 (a) for a realization of architecture \(\mathcal{A}_{1}\).
so it realizes the operators in \(\Psi_{W}\), with \(W=W_{1}\oplus W_{1}\oplus W_{2}\oplus W_{2}\), that can be written as the composition of two operators in \(\Psi_{W_{1}}\) composed with two operators in \(\Psi_{W_{2}}\), that is,

\[\mathcal{H}(\mathcal{A}_{1})=\left\{\psi\in\Psi_{W}:\psi=\psi^{\prime W_{2}} \psi^{\prime W_{1}}\psi^{W_{1}};\psi^{W_{i}},\psi^{\prime W_{i}}\in\Psi_{W_{i}},i=1,2\right\}.\]

This is another example in which the computation of the vertices in the architecture can be chosen independently, since \(\mathcal{F}_{1}\) is a Cartesian product.

In the architecture \(\mathcal{A}_{2}\), the functions \(\mathcal{C}\) in \(\mathcal{F}_{2}\) are such that

\[\begin{cases}\mathcal{C}(\mathfrak{v}_{i})=\mathcal{C}(\mathfrak{v}_{o})= \iota\\ \mathcal{C}(\mathfrak{v}_{1})=\gamma_{A},\mathcal{C}(\mathfrak{v}_{2})=\phi_{ A},\text{ for a }A\in\mathcal{P}(W_{1})\\ \mathcal{C}(\mathfrak{v}_{3})=\gamma_{B},\mathcal{C}(\mathfrak{v}_{4})=\phi_{ B},\text{ for a }B\in\mathcal{P}(W_{2})\end{cases}\]

so \(\mathcal{A}_{2}\) realizes the subclass of the ASF in \(\mathcal{H}(\mathcal{A}_{1})\), that is,

\[\mathcal{H}(\mathcal{A}_{2})=\left\{\psi\in\mathcal{H}(\mathcal{A}_{1}):\psi \text{ is an alternate-sequential filter}\right\}.\]

See Figure 4 for a realization of this architecture. In this example, \(\mathcal{F}_{2}\) is not a Cartesian product, so the computation of its vertices are not independent. Indeed, the structural element of the first and last pairs of opening and closing have the same structural element, so in this example the vertices share a parameter. However, this sub-collection of set operators could also be represented by the architecture \(\mathcal{A}_{3}\) in Figure 7 in which the interior vertices compute a composition of an opening and a closing with a same structuring element and the vertices do not share parameters. Even though \(\mathcal{H}(\mathcal{A}_{2})=\mathcal{H}(\mathcal{A}_{3})\), \(\mathcal{F}_{3}\) is a Cartesian product, so the computation of the vertices can be chosen independently.

This is another example of architectures with the same graph, but such that \(\mathcal{H}(\mathcal{A}_{3})=\mathcal{H}(\mathcal{A}_{2})\subseteq\mathcal{H} (\mathcal{A}_{1})\), so \(\mathcal{A}_{2}\) is a restriction of \(\mathcal{A}_{1}\). This is also an example of a DMNN that can be represented by two equivalent architectures.

**Example 5.10** (Sequential ASF and W-operator).: Figure 8 presents an example of an architecture which composes an ASF with a W-operator. This architecture has a graph \((\mathcal{V},\mathcal{E})\) such that \(\mathcal{V}=\{\mathfrak{v}_{i},\mathfrak{v}_{1},\mathfrak{v}_{2},\mathfrak{v}_ {3},\mathfrak{v}_{4},\mathfrak{v}_{\vee},\mathfrak{v}_{o}\}\) and

\[\mathcal{E}=\{(\mathfrak{v}_{i},\mathfrak{v}_{1}),(\mathfrak{v}_{1},\mathfrak{ v}_{2}),(\mathfrak{v}_{1},\mathfrak{v}_{3}),(\mathfrak{v}_{1},\mathfrak{v}_{4}),( \mathfrak{v}_{2},\mathfrak{v}_{\vee}),(\mathfrak{v}_{3},\mathfrak{v}_{\vee}),(\mathfrak{v}_{4},\mathfrak{v}_{\vee}),(\mathfrak{v}_{\vee},\mathfrak{v}_{ o})\}.\]

The architecture is such that, for all \(\mathcal{C}\in\mathcal{F}\), \(\mathcal{C}(\mathfrak{v}_{i})=\mathcal{C}(\mathfrak{v}_{o})=\iota\), \(\mathcal{C}(\mathfrak{v}_{\vee})=\vee\) and

\[\mathcal{C}(\mathfrak{v}_{1})=\phi_{A}\gamma_{A}\text{ with }A\in\mathcal{P}(W)\]
\[\mathcal{C}(\mathfrak{v}_{j})=\lambda_{[A_{j},B_{j}]}^{W}\text{ with }A_{j},B_{j}\in \mathcal{P}(W),A_{j}\subseteq B_{j}\qquad\quad j=2,3,4,\]

which realizes the composition of a one layer ASF and a \(W\)-operator with at most three elements in its basis. Observe that, denoting

\[\Gamma\Phi_{W}=\{\phi_{A}\gamma_{A}:A\in\mathcal{P}(W)\}\]

as the one layer ASF with structuring element in \(W\), in this example we have

\[\mathcal{F}=\{\iota\}\times\Gamma\Phi_{W}\times\Lambda_{W}\times\Lambda_{W} \times\Lambda_{W}\times\{\vee\}\times\{\iota\},\]

so \(\mathcal{F}\) is the Cartesian product of elements in \(\mathcal{P}(\Psi_{W})\cup\{\{\vee\},\{\wedge\}\}\), and the computation of each vertex can be chosen independently.

### DMNN are universal representers

The semantic expressiveness of DMNN allows to represent any collection of t.i. and locally defined set operators by a DMNN. This is the result of the next theorem.
**Theorem 5.11**.: _Let \(W\in\mathcal{P}(E)\) be a finite set. For any \(\Theta\in\mathcal{P}(\Psi_{W})\), there exists a Morphological Discrete Neural Network architecture \(\mathcal{A}_{\Theta}\) such that_

\[\mathcal{H}(\mathcal{A}_{\Theta})=\Theta.\]

Proof.: Fix a finite set \(W\in\mathcal{P}(E)\) and a sub-collection \(\Theta\in\mathcal{P}(\Psi_{W})\). We will present a sup-generating DMNN architecture that generates \(\Theta\). Consider the architecture \(\mathcal{A}_{\Theta}=(\mathcal{V},\mathcal{E},\mathcal{F}_{\Theta})\) with a graph \((\mathcal{V},\mathcal{E})\) such that

\[\mathcal{V}=\{\mathfrak{v}_{i},\mathfrak{v}_{1},\ldots,\mathfrak{v}_{2^{|W|-1} },\mathfrak{v}_{\vee},\mathfrak{v}_{o}\}\]

and

\[\mathcal{E}=\left\{(\mathfrak{v}_{i},\mathfrak{v}_{j}):j=1,\ldots,2^{|W|-1} \right\}\bigcup\left\{(\mathfrak{v}_{j},\mathfrak{v}_{\vee}):j=1,\ldots,2^{|W |-1}\right\}\bigcup\{(\mathfrak{v}_{\vee},\mathfrak{v}_{o})\}.\]

This graph is analogous to that of Figure 3 (a), but with \(2^{|W|-1}\) vertices computing sup-generating set operators instead of three.

For each \(\psi\in\Theta\), denote the elements in its basis by

\[\boldsymbol{B}_{W}(\psi)=\{\mathcal{I}_{1},\ldots,\mathcal{I}_{|\boldsymbol{B }_{W}(\psi)|}\}\]

and observe that \(|\boldsymbol{B}_{W}(\psi)|\leq 2^{|W|-1}\). Consider the function \(\mathcal{C}_{\psi}:\mathcal{V}\to\Psi_{W}\cup\{\vee,\wedge\}\) given by \(\mathcal{C}_{\psi}(\mathfrak{v}_{i})=\mathcal{C}_{\psi}(\mathfrak{v}_{o})=\iota\), \(\mathcal{C}_{\psi}(\mathfrak{v}_{\vee})=\vee\) and

\[\mathcal{C}_{\psi}(\mathfrak{v}_{j})=\begin{cases}\lambda_{j_{j}}^{W},&\text{ if }1\leq j\leq|\boldsymbol{B}_{W}(\psi)|\\ \emptyset,&\text{ if }j>|\boldsymbol{B}_{W}(\psi)|\end{cases}\]

Figure 8. Example of a DMNN architecture which composes a one layer ASF and a W-operator with at most three intervals in its basis.
for \(j=1,\ldots,2^{|W|-1}\), in which \(\emptyset\) stands for the constant set operator equal to \(\emptyset\). Observe that the MCG \(\mathcal{G}_{\psi}=(\mathcal{V},\mathcal{E},\mathcal{C}_{\psi})\) generates a W-operator \(\psi_{\mathcal{G}_{\psi}}\) satisfying \(\psi_{\mathcal{G}_{\psi}}=\psi\). Considering

\[\mathcal{F}_{\Theta}=\{\mathcal{C}_{\psi}:\psi\in\Theta\}\]

we have that

\[\mathcal{H}(\mathcal{A}_{\Theta})=\left\{\psi_{\mathcal{G}_{\psi}}:\psi\in \Theta\right\}=\Theta\]

as desired. 

**Remark 5.12**.: _We could readily obtain an inf-generating DMNN architecture that represents a given \(\Theta\in\mathcal{P}(\Psi_{W})\) following steps analogous to the proof of Theorem 5.11._

**Remark 5.13**.: _A sub-collection \(\Theta\in\mathcal{P}(\Psi_{W})\) may be represented by other DMNN architectures besides a sup-generating and an inf-generating architecture, as is the case of the sub-collections represented by the DMNN architectures in Examples 5.9 and 5.10. Theorem 5.11 established the existence of a DMNN architecture that represents \(\Theta\), but not its uniqueness, which clearly does not hold._

Although the sup-generating representation of a \(\Theta\in\mathcal{P}(\Psi_{W})\) via a DMNN derived on the proof of Theorem 5.11 is not in principle a new result, since it is a direct consequence of [4], the result of Theorem 5.11 is pragmatic since guarantees that any prior information about the set operator that best solves a given problem, which can be translated into a sub-collection \(\Theta\in\mathcal{P}(\Psi_{W})\) containing operators with properties believed to be satisfied by the best operator, may be expressed by a DMNN architecture.

## 6. Canonical Discrete Morphological Neural Networks

Dilations and erosions are the canonical operators, and the supremum, infimum and complement are the canonical operations, of Mathematical Morphology. Indeed, any W-operator can be represented by combining the supremum, infimum, and complement of compositions of erosions and dilations. This fact is a consequence of Corollary 3.2 and the representation of sup-generating and inf-generating operators by (3.3) and (3.4), respectively. Furthermore, openings, closings and ASF can also be simply represented by the composition of dilations and erosions (cf. (5.1)).
We define the Canonical Discrete Morphological Neural Networks (CDMNN) as those in which the computations are canonical operations or can be simply decomposed on canonical operators. For each finite subset \(W\in\mathcal{P}(E)\), denote

\[\begin{array}{ll}\Delta_{W}=\{\delta_{A}:A\in\mathcal{P}(W)\}&\Sigma_{W}=\{ \epsilon_{A}:A\in\mathcal{P}(W)\}\\ \Gamma_{W}=\{\gamma_{A}:A\in\mathcal{P}(W)\}&\Phi_{W}=\{\phi_{A}:A\in\mathcal{ P}(W)\}\\ \Gamma\Phi_{W}=\{\phi_{A}\gamma_{A}:A\in\mathcal{P}(W)\}&\Lambda_{W}=\left\{ \lambda_{[A,B]}:[A,B]\subseteq\mathcal{P}(W),A\subseteq B\right\}\\ \mathcal{M}_{W}=\left\{\mu_{[A,B]}:[A,B]\subseteq\mathcal{P}(W),A\subseteq B \right\}&\mathfrak{N}=\{\nu\}\end{array} \tag{6.1}\]

as the class of the dilations, erosions, openings, closings, one layer ASF, sup-generating, inf-generating and complement operators, respectively, with structuring elements in \(\mathcal{P}(W)\) or intervals in \(\mathcal{P}(\mathcal{P}(W))\).

**Definition 6.1**.: _A Morphological Discrete Neural Network architecture \(\mathcal{A}=(\mathcal{V},\mathcal{E},\mathcal{F})\) is canonical if the following holds:_

* _There exist two subsets of edges_ \(\mathcal{V}_{\vee},\mathcal{V}_{\wedge}\subseteq\mathcal{V}\) _such that, for all_ \(\mathcal{C}\in\mathcal{F}\)_,_ \[\begin{cases}\mathcal{C}(\mathfrak{v})=\vee,\forall\mathfrak{v}\in\mathcal{V} _{\vee}\\ \mathcal{C}(\mathfrak{v})=\wedge,\forall\mathfrak{v}\in\mathcal{V}_{\wedge}\\ \mathcal{C}(\mathfrak{v})\in\Omega_{\mathfrak{v}}\subseteq\Omega,\forall \mathfrak{v}\in\mathcal{V}_{\Omega},\end{cases}\] _in which_ \(\Omega_{\mathfrak{v}}\) _is a class of t.i. and locally defined operators and_ \(\mathcal{V}_{\Omega}:=\mathcal{V}\backslash\left(\mathcal{V}_{\vee}\cup \mathcal{V}_{\wedge}\right)\)_._
* _For every_ \(\mathfrak{v}\in\mathcal{V}_{\Omega}\) _there exists a finite subset_ \(W_{\mathfrak{v}}\in\mathcal{P}(E)\) _such that_ \[\Omega_{\mathfrak{v}}\in\{\Delta_{W_{\mathfrak{v}}},\Sigma_{W_{\mathfrak{v}}}, \Gamma_{W_{\mathfrak{v}}},\Phi_{W_{\mathfrak{v}}},\Gamma\Phi_{W_{\mathfrak{v}} },\Lambda_{W_{\mathfrak{v}}},\mathcal{M}_{W_{\mathfrak{v}}},\mathfrak{N}\}.\]

A special case of canonical DMNN is the unrestricted canonical DMNN, in which \(\mathcal{F}\) is a Cartesian product of \(\{\vee\},\{\wedge\}\) and the sets defined in (6.1).

**Definition 6.2**.: _A canonical Morphological Discrete Neural Network architecture \(\mathcal{A}=(\mathcal{V},\mathcal{E},\)\(\mathcal{F})\) is unrestricted if_

\[\mathcal{F}=\prod_{\mathfrak{v}\in\mathcal{V}_{\vee}}\{\vee\}\bigtimes\prod_{ \mathfrak{v}\in\mathcal{V}_{\wedge}}\{\wedge\}\bigtimes\prod_{\mathfrak{v}\in \mathcal{V}_{\Omega}}\Omega_{\mathfrak{v}}\subseteq\left(\Omega\cup\{\vee, \wedge\}\right)^{\mathcal{V}}.\]
The architectures in Figures 6 and 8, and the architectures \(\mathcal{A}_{2}\) and \(\mathcal{A}_{3}\) in Figure 7, are canonical since the vertices that compute the supremum are the same over all realizations of the architectures and the morphological operators computed by the remaining vertices are erosions, dilations, openings, closings, one layer ASF, sup-generating or inf-generating. Furthermore, these architectures, except \(\mathcal{A}_{2}\) in Figure 7, are unrestricted since the parameters of the operators, which are structural elements or intervals, are not shared among vertices. The architecture \(\mathcal{A}_{1}\) in Figure 7 is not canonical, since there are four vertices that compute general W-operators.

Observe that all vertices of a CDMNN compute either a canonical operation (supremum, infimum, or complement), or an operator that can be decomposed as the supremum, infimum, and complement of erosions and dilations, what justifies the _canonical_ nomenclature. Furthermore, any CDMNN could be represented by an MCG in which the vertices compute only erosions, dilations, supremum, infimum or complement, but that may share parameters. This fact is illustrated in Figure 4 in which a realization of a sequential CDMNN can be represented by the composition of two ASF that do not share parameters, or by the composition of dilations and erosions that share parameters. We chose the representation of CDMNN by MCG satisfying **C1** and **C2** in Definition 6.1 since it is more concise than a representation via erosions, dilations, supremum, infimum, and complement only, and allows the definition of unrestricted CDMNN when there is no parameter sharing.

### The lattice associated to a CDMNN architecture

Fix a canonical DMNN architecture \(\mathcal{A}=(\mathcal{V},\mathcal{E},\mathcal{F})\). We will consider a partial order \(\leq\) in \(\mathcal{F}\) based on the _parameters_ that represent the functions \(\mathcal{C}\in\mathcal{F}\). More precisely, each \(\mathcal{C}\in\mathcal{F}\) can be represented by a vector of sets and intervals that represent the structural elements of its vertices that compute erosions, dilations, openings, closings and one layer ASF, and the intervals of its vertices that compute inf-generating and sup-generating operators, and the collection \(\mathcal{F}\) inherits the partial order of the inclusion of sets and intervals.

For example, if each \(\mathcal{C}\in\mathcal{F}\) is represented by a vector \((A_{1}^{\mathcal{C}},\ldots,A_{p}^{\mathcal{C}})\in\mathcal{P}(W)^{p},p\geq 1\), of sets, then

\[\mathcal{C}_{1}\leq\mathcal{C}_{2}\iff A_{j}^{\mathcal{C}_{1}}\subseteq A_{j} ^{\mathcal{C}_{2}},\forall j=1,\ldots,p,\]

and \(\mathcal{F}\) inherits the partial order of the inclusion of its parameters. ASF architectures (cf. \(\mathcal{A}_{2}\) and \(\mathcal{A}_{3}\) in Figure 7) and increasing sup-generating architectures (cf. \(\mathcal{A}_{2}\) in Figure 6) are examples in which the functions in
may be parameterized by a vector of sets, which represent the structuring elements of erosions, openings, or closings. As another example, if each \(\mathcal{C}\in\mathcal{F}\) is represented by a vector \(([A_{1}^{\mathcal{C}},B_{1}^{\mathcal{C}}],\ldots,[A_{p}^{\mathcal{C}},B_{p}^{ \mathcal{C}}])\in\mathcal{P}(\mathcal{P}(W))^{p},p\geq 1\), of intervals, then

\[\mathcal{C}_{1}\leq\mathcal{C}_{2}\iff[A_{j}^{\mathcal{C}_{1}},B_{j}^{ \mathcal{C}_{1}}]\subseteq[A_{j}^{\mathcal{C}_{2}},B_{j}^{\mathcal{C}_{2}}], \forall j=1,\ldots,p, \tag{6.2}\]

and \(\mathcal{F}\) inherits the partial order of the inclusion of its parameters. Supergenerating architectures (cf. \(\mathcal{A}_{1}\) in Figure 6) are examples in which the functions in \(\mathcal{F}\) may be parameterized by a vector of intervals, which represent the intervals of the sup-generating operators. Finally, if each \(\mathcal{C}\in\mathcal{F}\) is represented by a vector \(([A_{1}^{\mathcal{C}},B_{1}^{\mathcal{C}}],\ldots,[A_{p_{I}}^{\mathcal{C}},B_ {p_{I}}^{\mathcal{C}}],C_{1}^{\mathcal{C}},\ldots,C_{p_{S}}^{\mathcal{C}})\in \mathcal{P}(\mathcal{P}(W))^{p_{I}}\times\mathcal{P}(W)^{p_{S}},p_{I},p_{S}\geq 1\), of intervals and sets, then

\[\mathcal{C}_{1}\leq\mathcal{C}_{2}\iff\begin{cases}[A_{j}^{\mathcal{C}_{1}},B _{j}^{\mathcal{C}_{1}}]\subseteq[A_{j}^{\mathcal{C}_{2}},B_{j}^{\mathcal{C}_{2 }}],&\forall j=1,\ldots,p_{I}\\ C_{j}^{\mathcal{C}_{1}}\subseteq C_{j}^{\mathcal{C}_{2}},&\forall j=1,\ldots,p_ {S}.\end{cases}\]

The architecture in Figure 8 is an example of this case, in which each \(\mathcal{C}\in\mathcal{F}\) is represented by \((A,\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3})\). The set \(A\) is the structuring element of the one layer ASF, and the intervals are the parameters of the three sup-generating operators.

Therefore, for any CDMNN architecture, \(\mathcal{F}\) inherits a partial order \(\leq\) from that of the structuring elements (sets) of the openings, closings, dilations, erosions and ASF, and from that of the intervals of the sup-generating and inf-generating operators, that it computes.

The poset \((\mathcal{F},\leq)\) is not, in general, isomorphic to \((\mathcal{H}(\mathcal{A}),\leq)\) since the mapping \(\psi_{\cdot}\), that maps each function \(\mathcal{C}\in\mathcal{F}\) to the operator \(\psi_{\mathcal{C}}\in\mathcal{H}(\mathcal{A})\) generated by the MCG \(\mathcal{G}=(\mathcal{V},\mathcal{E},\mathcal{C})\), is not injective when two realizations of the architecture \(\mathcal{A}\) generate the same set operator. This is the case, for example, of the architecture \(\mathcal{A}_{1}\) in Figure 6 in which an operator \(\psi\) is generated by all realizations of \(\mathcal{A}_{1}\) where the union of the intervals of the sup-generating operators is equal to its kernel \(\mathcal{K}_{W}(\psi)\) (cf. Proposition 3.1). Actually, \(\mathcal{F}\) is usually an overparametrization of \(\mathcal{H}(\mathcal{A})\).

Although the representation of the operators in \(\mathcal{H}(\mathcal{A})\) by \(\mathcal{F}\) is not unique and \((\mathcal{F},\leq)\) is not isomorphic to \((\mathcal{H}(\mathcal{A}),\leq)\), it has the advantage that the elements and partial order of \(\mathcal{F}\) are completely known a priori, since \(\mathcal{F}\) is fixed and the partial order is that of inclusion of sets/intervals, while the elements of \(\mathcal{H}(\mathcal{A})\) and its partial order may need to be computed. Therefore, training the DMNN by minimizing an empirical loss in \((\mathcal{F},\leq)\) to obtain a
set operator that _fits_ empirical data may be computationally cheaper than minimizing this loss in \(\mathcal{H}(\mathcal{A})\) directly, since its elements and partial order should be computed (see Remark 7.1 for more details.). This observation points to the fact that a DMNN is a tool, or a _computational machine_, to learn set operators in a fixed collection \(\Theta=\mathcal{H}(\mathcal{A})\) and not a learning model in itself.

The suboptimal minimization of an empirical loss in \((\mathcal{F},\leq)\) could be performed via a greedy algorithm that runs through this poset by locally minimizing the loss. This algorithm depends on the definition of the neighborhoods of \((\mathcal{F},\leq)\).

### Neighborhoods of \((\mathcal{F},\leq)\)

In view of the discussion above, we define the neighborhood of \(\mathcal{C}\in\mathcal{F}\) as the points in \(\mathcal{F}\) at a distance one from it. The poset \((\mathcal{F},\leq)\) generates a directed acyclic graph whose vertices are \(\mathcal{F}\) and the edges connect every pair of subsequent elements, which are such that \(\mathcal{C}_{1}\leq\mathcal{C}_{2}\) and if \(\mathcal{C}_{1}\leq\mathcal{C}\leq\mathcal{C}_{2},\mathcal{C}\in\mathcal{F}\), then either \(\mathcal{C}_{1}=\mathcal{C}\) or \(\mathcal{C}_{2}=\mathcal{C}\), with orientation from \(\mathcal{C}_{1}\) to \(\mathcal{C}_{2}\). In this setting, the distance between elements \(\mathcal{C}_{1},\mathcal{C}_{2}\in\mathcal{F}\), with \(\mathcal{C}_{1}\leq\mathcal{C}_{2}\), denoted by \(d(\mathcal{C}_{1},\mathcal{C}_{2})=d(\mathcal{C}_{2},\mathcal{C}_{1})\), is the length of the shortest path from \(\mathcal{C}_{1}\) to \(\mathcal{C}_{2}\).

**Definition 6.3**.: _The neighborhood in \(\mathcal{F}\) of each \(\mathcal{C}\in\mathcal{F}\) is defined as_

\[N(\mathcal{C})=\left\{\mathcal{C}^{\prime}\in\mathcal{F}:d(\mathcal{C}, \mathcal{C}^{\prime})=1\right\}.\]

We exemplify \(\mathcal{F}\) and its neighborhoods for an ASF architecture, a sup-generating architecture and the composition of an ASF and a W-operator.

**Example 6.4**.: Let \(\mathcal{A}\) be the ASF architecture \(\mathcal{A}_{3}\) in Figure 7. In this example, \(\mathcal{F}\) is isomorphic to the Boolean lattice \(\mathcal{P}(W)^{2}\) and an element \((A,B)\in\mathcal{P}(W)^{2}\) realizes the ASF with two pairs of openings and closings in which the first has structuring element \(A\) and the second \(B\). Denote by \(\mathcal{C}_{A,B}\in\mathcal{F}\) the element of \(\mathcal{F}\) associated to \((A,B)\). We have that

\[N(\mathcal{C}_{A,B})=\left\{\mathcal{C}_{C,B}\in\mathcal{F}:d(C,A)=1\right\} \cup\left\{\mathcal{C}_{A,C}\in\mathcal{F}:d(C,B)=1\right\},\]

in which \(d(C,A)\) and \(d(C,B)\) are the respective distance in \(\mathcal{P}(W)\), so a neighbor of \(\mathcal{C}_{A,B}\) is obtained by adding or removing one point from \(A\) or \(B\). This is an example in which the poset \((\mathcal{F},\leq)\) is actually a Boolean lattice, which is partially depicted in Figure 9.
**Example 6.5**.: Let \(\mathcal{A}\) be the sup-generating architecture \(\mathcal{A}_{1}\) in Figure 6. In this example, \(\mathcal{F}\) is isomorphic to a subset of the Boolean lattice \(\mathcal{P}(\mathcal{P}(W))^{3}\) and each element \((\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3})\) of this subset represents the sup-generating MCG given by the supremum of three sup-generating operators with intervals \((\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3})\). Denote by \(\mathcal{C}_{\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3}}\in\mathcal{F}\) the element of \(\mathcal{F}\) associated to \((\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3})\). We have that

\[N(\mathcal{C}_{\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3}}) =\{\mathcal{C}_{\mathcal{I},\mathcal{I}_{2},\mathcal{I}_{3}}\in \mathcal{F}:d(\mathcal{I},\mathcal{I}_{1})=1\}\cup\{\mathcal{C}_{\mathcal{I}_{ 1},\mathcal{I},\mathcal{I}_{3}}\in\mathcal{F}:d(\mathcal{I},\mathcal{I}_{2})=1\}\] \[\quad\cup\left\{\mathcal{C}_{\mathcal{I}_{1},\mathcal{I}_{2}, \mathcal{I}}\in\mathcal{F}:d(\mathcal{I},\mathcal{I}_{3})=1\right\},\]

in which \(d(\mathcal{I},\mathcal{I}_{j}),j=1,2,3\), is the respective distance in the poset of the intervals in \(\mathcal{P}(\mathcal{P}(W))\), so a neighbor of \(\mathcal{C}_{\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3}}\) is obtained by adding or removing a certain point from one extremity of one of its three intervals. \(\blacksquare\)

**Example 6.6**.: Let \(\mathcal{A}\) be the architecture in Figure 8. In this example, \(\mathcal{F}\) is isomorphic to a subset of the Boolean lattice \(\mathcal{P}(W)\times\mathcal{P}(\mathcal{P}(W))^{3}\) and each element \((A,\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3})\) of this subset realizes the MCG given by the composition of a one layer ASF with structuring element \(A\) and the supremum of three sup-generating operators with intervals \((\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3})\). Denote by \(\mathcal{C}_{\mathcal{A},\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3}}\in \mathcal{F}\) the element of \(\mathcal{F}\) associated to \((A,\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3})\). We have that

\[N(\mathcal{C}_{A,\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3 }})= \{\mathcal{C}_{B,\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3}} \in\mathcal{F}:d(A,B)=1\}\cup\left\{\mathcal{C}_{\mathcal{A},\mathcal{I}, \mathcal{I}_{2},\mathcal{I}_{3}}\in\mathcal{F}:d(\mathcal{I},\mathcal{I}_{1})=1\right\}\] \[\quad\cup\left\{\mathcal{C}_{\mathcal{A},\mathcal{I}_{1},\mathcal{ I},\mathcal{I}_{3}}\in\mathcal{F}:d(\mathcal{I},\mathcal{I}_{2})=1\right\}\cup \left\{\mathcal{C}_{\mathcal{A},\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}} \in\mathcal{F}:d(\mathcal{I},\mathcal{I}_{3})=1\right\},\]

in which the distances are on the respective posets of sets and intervals, so a neighbor of \(\mathcal{C}_{A,\mathcal{I}_{1},\mathcal{I}_{2},\mathcal{I}_{3}}\) is obtained by adding or removing one point from the structuring element \(A\) or from one extremity of one of its three intervals. \(\blacksquare\)

## 7. Training Canonical Discrete Morphological Neural Networks

A training algorithm for a CDMNN should receive an architecture and a sample of pairs of input and target sets, and return a realization of the architecture that well _approximates_ the set operation applied to the input sets to obtain the respective target set. For a \(N\geq 1\), let

\[\mathcal{D}_{N}=\{(X_{1},Y_{1}),\ldots,(X_{N},Y_{N})\}\]

be a sample of \(N\) input sets \(X\) and target sets \(Y\). We assume there exists a finite set \(F\in\mathcal{P}(E)\) such that \(X_{j},Y_{j}\subseteq F,j=1,\ldots,N\). For example, if
\(E=\mathbb{Z}^{2}\) and \(X,Y\) represent binary images with \(d\times d\) pixels, then we could consider \(F=\{-d/2,\ldots,d/2\}^{2}\).

It is assumed that each \(Y\) is, apart from a random noise, obtained from \(X\) by applying a set operator \(\psi^{\star}\in\Omega\). Fixed a DMNN architecture \(\mathcal{A}\), the main objective of the learning is to estimate \(\psi^{\star}\) by a \(\hat{\psi}\in\mathcal{H}(\mathcal{A})\) which, we hope, is such that \(\hat{\psi}\approx\psi^{\star}\).

The main paradigm of learning is empirical risk minimization [47], in which \(\hat{\psi}\) is obtained by minimizing the empirical loss incurred when \(\hat{\psi}(X)\) is employed to approximate \(Y\) in sample \(\mathcal{D}_{N}\). Common losses in this setting are the absolute loss and the intersection of union loss. The absolute loss is defined as

\[\ell_{a}(X,Y;\psi)=\frac{|\{x\in F:x\in(Y^{c}\cap\psi(X))\cup(Y\cap[\psi(X)]^{c })\}|}{|F|}, \tag{7.1}\]

that is the proportion of the points in \(F\) which are in \(Y\) but not in \(\psi(X)\) or that are in \(\psi(X)\) but not in \(Y\). The intersection of union (IoU) loss is defined as

\[\ell_{IoU}(X,Y;\psi)=1-\frac{|Y\cap\psi(X)|}{|Y\cup\psi(X)|},\]

that is the proportion of points in \(Y\cup\psi(X)\) that are not in \(Y\cap\psi(X)\). The IoU loss is more suitable for form or object detection tasks, while the absolute loss is suitable for general image transformation tasks. When the loss function is not of importance, we denote it simply by \(\ell\).

Fix an architecture \(\mathcal{A}=(\mathcal{V},\mathcal{E},\mathcal{F})\) and, for each \(\mathcal{C}\in\mathcal{F}\), denote by \(\psi_{\mathcal{C}}:=\psi_{\mathcal{G}}\) as the set operator generated by MCG \(\mathcal{G}=(\mathcal{V},\mathcal{E},\mathcal{C})\). We define the mean empirical loss of each realization \(\mathcal{C}\in\mathcal{F}\) of the DMNN architecture \(\mathcal{A}\) as

\[L_{\mathcal{D}_{N}}(\mathcal{C})=\frac{1}{N}\sum_{j=1}^{N}\ell(X_{j},Y_{j}; \psi_{\mathcal{C}}).\]

The optimal minimization of \(L_{\mathcal{D}_{N}}\) in \(\mathcal{F}\) is a highly combinatorial problem whose complexity is exponential on the number \(|\mathcal{V}|\) of computational vertices, specially when \(\mathcal{F}\) is the Cartesian product of subsets of Boolean lattices, as is the case of unrestricted CDMNN. To circumvent the computational complexity, we propose an iterative algorithm that performs a greedy search of \(\mathcal{F}\) and returns a _local minimum_ of \(L_{\mathcal{D}_{N}}\) in \(\mathcal{F}\) that, although it may not be a minimizer of \(L_{\mathcal{D}_{N}}\), may be suitable for the application at hand. The
proposed algorithm is the instantiation of a U-curve algorithm, that was initially proposed to minimize U-shaped functions in Boolean lattices [3, 18, 36, 37]. The proposed algorithm is a lattice version of the gradient descent algorithm (GDA) [39], and we call it the _lattice gradient descent algorithm_ (LGDA). As in the GDA, we may add stochasticity to meaningfully decrease the problem complexity and do not get stuck on bad local minimums.

In the following sections, we present the details of the LGDA and its stochastic version (SLGDA).

### Lattice Gradient Descent Algorithm for training CDMNN

The LGDA performs an iterative greedy search of \(\mathcal{F}\), at each step jumping to the point in the neighborhood of the current point with the least mean empirical loss, and stopping after a predefined number of steps (epochs). This algorithm is analogous to the gradient descent algorithm to minimize differentiable functions in \(\mathbb{R}^{p},p\geq 1\), since both algorithms go, at each time, to the direction with the least function value. In the gradient descent algorithm, this direction is opposed to the function gradient, while in the LGDA this direction is a chain of \((\mathcal{F},\leq)\) that passes through the current point that contains its neighbor with least mean empirical loss.

The LGDA algorithm is formalized in Algorithm 1. It is initialized at a point \(\mathcal{C}\in\mathcal{F}\) and a predetermined number of training epochs is fixed. The initial point is stored as the point with minimum empirical loss visited so far. For each epoch, \(\mathcal{C}\) is updated to a point in its neighborhood with the least empirical loss. If this point has an empirical loss lesser than that of the point with minimum loss visited so far, the current point is stored as the minimum. After all epochs, the algorithm returns the visited point with minimum empirical loss.

```
1:\(\mathcal{C}\in\mathcal{F}\), Epochs
2:\(L_{min}\gets L_{\mathcal{D}_{N}}(\mathcal{C})\)
3:\(\widehat{C}\leftarrow\mathcal{C}\)
4:for run \(\in\{1,\ldots,\text{Epochs}\}\)do
5:\(\mathcal{C}\leftarrow\mathcal{C}^{\prime}\) s.t. \(\mathcal{C}^{\prime}\in N(\mathcal{C})\) and \(L_{\mathcal{D}_{N}}(\mathcal{C}^{\prime})=\min\{L_{\mathcal{D}_{N}}(\mathcal{ C}^{\prime\prime}):\mathcal{C}^{\prime\prime}\in N(\mathcal{C})\}\)
6:if\(L_{\mathcal{D}_{N}}(\mathcal{C})<L_{min}\)then
7:\(L_{min}\gets L_{\mathcal{D}_{N}}(\mathcal{C})\)
8:\(\widehat{C}\leftarrow\mathcal{C}\)
9:return\(\widehat{\mathcal{C}}\)
```

**Algorithm 1** Lattice Gradient Descent Algorithm for training a CDMNN.
**Remark 7.1**.: _On the one hand, since the poset \((\mathcal{F},\leq)\) is known a priori, for any \(\mathcal{C}\in\mathcal{F}\) the set \(N(\mathcal{C})\) is known so the complexity of minimizing \(L_{\mathcal{D}_{N}}\) in \(N(\mathcal{C})\) should be \(|N(\mathcal{C})|\mathcal{O}(L_{\mathcal{D}_{N}})\), in which \(\mathcal{O}(L_{\mathcal{D}_{N}})\) is the computational complexity of \(L_{\mathcal{D}_{N}}\). On the other hand, if the LGDA algorithm were applied directly on poset \((\mathcal{H}(\mathcal{A}),\leq)\), fixed a \(\psi\in\mathcal{H}(\mathcal{A})\), the computation of its neighborhood in \((\mathcal{H}(\mathcal{A}),\leq)\) would be problem-specific and could have a complexity that is not linear on the number of neighbors. Therefore, sub-optimally minimizing the empirical loss in \(\mathcal{F}\) via the LGDA should be less computationally complex than doing so in \(\mathcal{H}(\mathcal{A})\)._

Although the returned DMNN parameter \(\widehat{\mathcal{C}}\) may not be a minimizer of \(L_{\mathcal{D}_{N}}\) in \(\mathcal{F}\), it may have a low enough mean empirical loss and well approximate the actual minimizer. Furthermore, Algorithm 1 may be run starting from many initial points \(\mathcal{C}\) and lead to distinct local minimums \(\widehat{\mathcal{C}}\), with mean empirical loss tending to that of the minimizer as more initial points are considered. We illustrate the LGDA algorithm in a sequential architecture.

**Example 7.2** (Training an ASF architecture).: Consider the ASF architecture \(\mathcal{A}_{3}\) in Figure 7 for which \(\mathcal{F}\) is isomorphic to the Boolean lattice \(\mathcal{P}(W)^{2}\) (cf. Example 6.4). In Figure 9 we present selected elements of this Boolean lattice when \(E=\mathbb{Z}^{2}\) and \(W=\{-1,0,1\}^{2}\) is the three by three square centered at the origin of \(E\). The number on top of the elements in Figure 9 is the mean empirical loss in a sample \(\mathcal{D}_{N}\) of the set operator generated by the respective realization of the architecture. The colored edges represent the path of the LGDA starting from the empty sets after three epochs. The edges of paths that remove points from the structuring elements were omitted for a better visualization.

In this example, each element in \(\mathcal{F}\) has 18 neighbors, which are obtained by adding or removing a point from one of its two sets, so the complexity of each step of the LGDA is at most eighteen times the complexity of applying the realized set operator to each input point in sample \(\mathcal{D}_{N}\) and comparing the result with the respective target set to compute the mean empirical loss. \(\blacksquare\)

Even though the LGDA does not perform an exhaustive search of \(\mathcal{F}\), Algorithm 1 may be too complex and may not be feasible to solve practical problems. Furthermore, it may get stuck in local minimums or realize a periodical path, visiting the same points multiple times. Indeed, since at each step it jumps to the neighbor with the least empirical loss, it may jump back to the previous point if it is the neighbor with the least empirical loss,
and keep jumping between these two points during the remaining epochs. Inspired by the success of stochastic gradient descent algorithms, we propose the Stochastic Lattice Gradient Descent Algorithm (SLGDA) to decrease the computational complexity of the LGDA and mitigate the risk of getting stuck at local minimums.

Figure 9. Selected elements in the lattice \((\mathcal{F},\leq)\) of the ASF architecture \(\mathcal{A}_{3}\) in Figure 7 when \(E=\mathbb{Z}^{2}\) and \(W=\{-1,0,1\}^{2}\). The number on top of the elements is the mean empirical loss of the set operator realized by them, and the colored edges represent the path of the LGDA starting from the empty sets after three epochs. The edges pointing to sets obtained by removing a point from a set were omitted for a better visualization. The returned element \(\hat{\mathcal{C}}\) is outlined in green.
### Stochastic Lattice Gradient Descent Algorithm for training CDMNN

The LGDA has two computational bottlenecks: the cost of calculating \(L_{\mathcal{D}_{N}}(\mathcal{C})\) and the number of neighbors in \(N(\mathcal{C})\). In order to calculate \(L_{\mathcal{D}_{N}}(\mathcal{C})\) it is necessary to compute the graph \((\mathcal{V},\mathcal{E},\mathcal{C})\) for all the \(N\) inputs \(\{X_{1},\ldots,X_{N}\}\). Since it may be expensive to compute this graph, specially if the dimensionality of \(X\) is too great1, the calculation of \(L_{\mathcal{D}_{N}}\) may be an impeditive of Algorithm 1 for great values of \(N\). Moreover, if the number of neighbors of each point \(\mathcal{C}\in\mathcal{F}\) is too great, then Algorithm 1 may not be computable since at each step it should calculate the mean empirical loss of every point in a neighborhood. We propose the SLGDA to circumvent these bottlenecks by considering sample batches to calculate the empirical loss and by sampling neighbors of a point at each batch. We also expect with this algorithm to avoid periodical paths and getting stuck at local minimums.

Footnote 1: We define the dimensionality of \(X\) as the size \(|F|\) of \(F\).

The SLGDA is formalized in Algorithm 2. The initial point \(\mathcal{C}\in\mathcal{F}\), a batch size2\(b\), the number \(n\) of neighbors to be sampled at each step, and the number of training epochs is fixed. The initial point is stored as the point with minimum empirical loss visited so far. For each epoch, the sample \(\mathcal{D}_{N}\) is randomly partitioned in \(N/b\) batches \(\{\tilde{\mathcal{D}}_{b}^{(1)},\ldots,\tilde{\mathcal{D}}_{b}^{(N/b)}\}\). For each batch \(\tilde{\mathcal{D}}_{b}^{(j)}\), \(n\) neighbors of \(\mathcal{C}\) are sampled and \(\mathcal{C}\) is updated to the sampled neighbor with the least empirical loss \(L_{\tilde{\mathcal{D}}_{b}^{(j)}}\), that is calculated on the sample batch \(\tilde{\mathcal{D}}_{b}^{(j)}\). Observe that \(\mathcal{C}\) is updated at each batch, so during an epoch, it is updated \(N/b\) times. At the end of each epoch, the empirical loss \(L_{\mathcal{D}_{N}}(\mathcal{C})\) of \(\mathcal{C}\) on the whole sample \(\mathcal{D}_{N}\) is compared with the loss of the point with the least empirical loss visited so far at the end of an epoch, and it is stored as this point if its empirical loss is lesser. After the predetermined number of epochs, the algorithm returns the point with the least empirical loss on the whole sample \(\mathcal{D}_{N}\) visited at the end of an epoch.

Footnote 2: We assume that \(N/b\) is an integer to easy notation. If this is not the case, the last batch will contain less than \(b\) points.

The computational complexity of each epoch of Algorithm 2 is of order \(N/b\left[n\mathcal{O}(L_{\tilde{\mathcal{D}}_{b}^{(j)}})\right]\)

\(+\)\(\mathcal{O}(L_{\mathcal{D}_{N}})\) so it is controlled by the batch size \(b\) and the number of sampled neighbors \(n\). The SLGDA could be applied to find an initial point for the LGDA, or when the LGDA gets stuck at a local minimum or on a periodical
path. Moreover, the LGDA and SLGDA may be combined by, for example, taking sample batches, but considering all neighbors of a point without sampling. In the next section, we illustrate the algorithms on an applied example.

## 8. Boundary recognition of digits with noise

In this section, we apply the SLGDA and LGDA to train CDMNN to recognize the boundary of noised digits. The algorithms were implemented in \(\mathbf{R}\)[35] and are available as a _package_ at [https://github.com/dmarcondes/DMNN](https://github.com/dmarcondes/DMNN). The basic morphological operators are calculated by the functions in the **mmand** package [14]. The training was performed on a personal computer with processor 13th Gen Intel Core i7-1355U x 12 and 16 GB of ram. The calculation of the empirical loss of the neighbors in \(N(\mathcal{C})\) or \(\tilde{N}(\mathcal{C})\) was parallelized in 12 cores.

The training sample is composed of ten pairs of \(56\times 56\) images, one of each digit from 0 to 9, and the validation sample is composed of another ten pairs of \(56\times 56\) images, one of each digit from 0 to 9. The input images are black and white digits with pepper and salt noise, and the output images are the boundary of the input digit. The input and output images in the validation sample are presented in Figure 13.
We trained ten CDMNN architectures, which we denote by the operators computed in their layers. We use the notation \(kSGd\) to mean a layer that computes the supremum of \(k\) sup-generating operators locally defined within \(W_{d}\coloneqq\{-(d-1)/2,\ldots,(d-1)/2\}^{2}\) and we denote by \(ASFd\) a layer that calculates an ASF with structuring element in \(\mathcal{P}(W_{d})\). For example, we denote by \(16SG3\) the architecture given by the supremum of \(16\) sup-generating operators locally defined within \(W_{3}=\{-1,0,1\}^{2}\) and by \(ASF3-16SG3\) the architecture whose output is the supremum of \(16\) sup-generating operators locally defined in \(W_{3}\) applied to the output of an ASF with structuring element in \(\mathcal{P}(W_{3})\). The ten considered architectures are presented in Table 8.2 and illustrated in Figure 10. In the figure, we omitted the operators parameters and the orientation of the graph, that is always from vertex \(X\) to vertex \(\psi\), for a better visualization.

The ten architectures were trained for \(1,000\) epochs with the SLGDA sampling \(10\) neighbors and considering batch sizes of \(1,5\) and \(10\) (whole sample). We considered the IoU loss function and the parameters were initialized so each vertex compute an operator given by a random perturbation of the identity operator. We considered the same initial point of each architecture for the SLGDA with batch sizes of \(1,5\) and \(10\). Finally, when more than one sampled neighbor had a same least empirical loss in a step of the algorithm, the next point of the algorithm was uniformly sampled from these neighbors.

The results are presented in Table 8.2. First, we observe that the architectures with higher mean IoU loss on the validation sample are those in which there are operators locally defined within \(W_{5}\). In these cases, the class of operators generated by the architecture is more complex and the respective poset \((\mathcal{F},\leq)\) has more points, so more samples and more epochs should be necessary to properly train these more complex architectures. It is also interesting to note that, for example, even though the architectures ASF3-16SG3-16SG3 and ASF3-16SG5 generate W-operators locally defined within a same window, the performance of ASF3-16SG3-16SG3 was significantly better, since it had a lesser validation loss. This can be explained by the fact that the collection of W-operators generated by ASF3-16SG3-16SG3 is more restricted than that generated by ASF3-16SG5, so fewer epochs and samples are necessary to properly train it.

Figure 11 presents, for each architecture and batch size, the mean empirical IoU at each epoch. We see in this figure and in Table 8.2 that there were cases in which the minimum was visited in later epochs and others in which it was visited in early epochs. On the one hand, when the batch size
equals 5 or 10, the empirical IoU usually decreases abruptly from time to time until it reaches the minimum visited and, once a low value of the empirical loss is attained, it does not vary significantly in later epochs. On the other hand, when the batch size is 1, the empirical IoU decreases quickly in the early epochs and is highly unstable during later epochs, coming back to high values and not significantly decreasing the empirical loss. Indeed, apart from the architecture ASF3-8SG5, the minimum when the batch size is 5 or 10 was achieved, with few exceptions, between epochs \(700\) and \(1,000\), while the other epochs are still
when the batch size was 1 the minimum was achieved at as early as the epoch 133.

The lowest validation loss was obtained when training with a batch size of 1 for two architectures, and with a batch size of 5 and 10 for four architectures each, and the lowest validation loss overall was obtained for the architecture ASF3-16SG3-16SG3 trained with a batch size of 1. The \(1,000\) training epochs took from around 7 to 27 minutes, and training with a batch size of 1 took longer in all cases.

The trained CDMNN that obtained the lesser validation loss (ASF3-16SG3-16SG3 with \(b=1\)) was fine trained via the LGDA for another 100 epochs with batch sizes of 1, 5 and 10 (whole sample). Considering the CDMNN trained via the SLGDA as the initial point, the LGDA took around 21 minutes to fine train this architecture during 100 epochs, but achieved a lesser training and validation losses for all batch sizes, as presented in Table 8.3. The lowest validation loss was achieved with the whole sample as a batch, that is the LGDA described in Algorithm 1, and the total training time

Figure 11. Mean empirical IoU at each epoch of the SLGDA for each architecture and batch size.
of this architecture was around 48 minutes. We see in Figure 12 a behavior analogous to that of Figure 11, since the empirical loss with batch sizes of 5 and 10 decreased abruptly during the training, while that of a sample batch size of 1 was highly unstable during training.

We also retrained the ASF3-16SG3-16SG3 architecture from scratch via the LGDA with batch sizes of \(1,5\) and \(10\) during \(1,000\) epochs and obtained

\begin{table}
\begin{tabular}{l r r r r r r} \hline Arch & b & \(L_{\mathcal{D}_{N}}(\widehat{\mathcal{C}})\) & Val. loss & Total time (m) & Time to min (m) & Epochs to min \\ \hline

[MISSING_PAGE_POST]

 \hline
**asf3\_16sg3\_16sg3** & **1** & **0.052** & **0.066** & **26.649** & **26.571** & **997** \\ asf3\_16sg3\_16sg3 & 5 & 0.082 & 0.099 & 17.961 & 9.579 & 533 \\ asf3\_16sg3\_16sg3 & 10 & 0.086 & 0.097 & 17.045 & 13.765 & 807 \\ \hline asf3\_16sg5 & 1 & 0.259 & 0.261 & 27.297 & 21.517 & 792 \\ asf3\_16sg5 & 5 & 0.130 & 0.141 & 17.423 & 14.271 & 823 \\ asf3\_16sg5 & 10 & 0.169 & 0.175 & 16.945 & 15.193 & 899 \\ \hline asf3\_8sg3\_8sg3 & 1 & 0.108 & 0.115 & 20.514 & 12.466 & 609 \\ asf3\_8sg3\_8sg3 & 5 & 0.144 & 0.157 & 11.784 & 8.525 & 726 \\ asf3\_8sg3\_8sg3 & 10 & 0.053 & 0.070 & 11.076 & 8.969 & 815 \\ \hline asf3\_8sg5 & 1 & 0.406 & 0.409 & 20.920 & 17.521 & 840 \\ asf3\_8sg5 & 5 & 0.400 & 0.404 & 12.189 & 1.872 & 162 \\ asf3\_8sg5 & 10 & 0.279 & 0.283 & 11.513 & 8.322 & 727 \\ \hline \end{tabular}
\end{table}
Table 8.2. Results of the training of ten CDMNN architectures to recognize the boundary of digits with noise by the SLGDA sampling 10 neighbors and considering sample batches of size \(b=1,b=5\) and \(b=10\), and the IoU loss. For each architecture and batch size, we present the minimum empirical loss, the empirical loss on the validation sample of the trained CDMNN, the total training time, the time it took to visit the minimum and the epochs it took to visit the minimum.
the results in Table 8.3. The training epochs took at least 3 hours to complete, and both the training and validation loss of the trained DMNN were higher than that obtained via the SLGDA and by refining the SLGDA result via the LGDA. In this example, there was no gain in training via the LGDA and the best result was attained by refining via the LGDA the CDMNN trained via the SLGDA.

The image predicted by the fine trained CDMNN ASF3-16SG3-16SG3 with a batch size of 10 for each input image in the validation sample is presented in Figure 13. As expected from prior information about the problem at hand, an architecture that applies an ASF at the first layer should have a better performance than architectures that do not, since an ASF has the property of removing noise. We see in Figure 13 that the first layer of the trained CDMNN is indeed removing the noise. After this noise removal, the second layer, given by a W-operator represented by the supremum of 16 sup-generating operators, is crudely recognizing the boundary. The third layer, also given by a W-operator represented by the supremum of 16 sup-generating operators, is refining the boundary of the digit roughly recognized by the first W-operator, obtaining a good visual result.

\begin{table}
\begin{tabular}{l c c c c c c c} \hline \hline Type & b & \(L_{\mathcal{D}_{N}}(\mathcal{\bar{C}})\) & Val. loss & Epochs & Total time (m) & Time to min (m) & Epochs to min \\ \hline Refine & 1 & 0.046 & 0.052 & 100 & 22.618 & 10.999 & 49 \\ Refine & 5 & 0.041 & 0.051 & 100 & 20.942 & 12.780 & 61 \\
**Refine** & **10** & **0.040** & **0.049** & **100** & **21.057** & **19.562** & **93** \\ \hline Retrain & 1 & 0.073 & 0.084 & 1000 & 229.884 & 218.805 & 952 \\ Retrain & 5 & 0.076 & 0.089 & 1000 & 236.037 & 180.437 & 820 \\ Retrain & 10 & 0.251 & 0.265 & 1000 & 206.915 & 184.376 & 895 \\ \hline \hline \end{tabular}
\end{table}
Table 8.3. Results of the fine training of the CDMNN architecture ASF3-16SG3-16SG3 via 100 epochs of the LGDA starting from the parameters trained by the SLGDA with batch size of 1 and of retraining the CDMNN architecture ASF3-16SG3-16SG3 from scratch via \(1,000\) epochs of the LGDA starting from a random perturbation of the identity operator. The fine training and retraining were performed considering sample batches of size \(b=1,b=5\) and \(b=10\), and the IoU loss. For each training type and batch size, we present the minimum empirical loss, the empirical loss on the validation sample of the trained CDMNN, the number of training epochs, the total training time, the time it took to visit the minimum and the epochs it took to visit the minimum.
## 9. Discussion

### Main contributions

The method proposed in this paper merges the classical heuristic design of morphological operators with the estimation of parameters via machine learning. The method proposes the definition of a class of W-operators through a DMNN architecture and the training of its parameters through a discrete stochastic combinatorial optimization algorithm analogous to the stochastic gradient descent algorithm. An important characteristic of this approach is that the class of W-operators can be quite general (e.g., all W-operators with at most \(k\) elements in the basis) or specialized (e.g., filters and granulometric filters) according to expected properties of the target operator, i.e., prior information. The semantic expressed by algebraic properties of classes of operators is a differential relative to other methods, such as deep neural networks. Some benefits of the proposed approach are: smaller sample complexity, interpretation of the designed operator and smaller computational complexity (due to constraints on the class of operators and the stochasticity of the training algorithm). The semantics of the designed operator being comprehensible open doors for further research in the context of DMNN.

Figure 12. Mean empirical IoU at each epoch of the LGDA when fine training and retraining the architecture ASF3-16SG3-16SG3 for each batch size.
More specifically, this paper formalizes the DMNN and proposes lattice gradient descent algorithms to train CDMNN. Although CDMNN are a special case of classical designs of set operators, that combine erosions and dilations via composition, infimum, supremum and complement, its formalization enabled a general algorithm to learn W-operators from data via a greedy search of a lattice. Furthermore, the CDMNN are transparent by design and fully interpretable, since the basis of the operators realized by them can be computed and from it their properties can be deduced. Finally, prior information about the problem at hand can be inserted into a CDMNN architecture to obtain better results and to account for features of the domain of application.

### Algorithmic and application perspectives

We have not exhausted the study of DMNN for binary image analysis, but rather presented its main features, and we leave many important questions for future research. First,

Figure 13. Input and output images in the validation sample, images predicted by the fine trained ASF3-16SG3-16SG3 architecture, image obtained after applying the ASF3 layer of this architecture and image obtained after applying the ASF3-16SG3 layers of this architecture.
the LGDA and SLGDA are not exclusive to train CDMNN and can be readily generalized to any DMNN that is parameterized by a vector of sets and intervals, or any other object contained in a lattice or a poset. Nevertheless, the complexity of the algorithm may increase when \((\mathcal{F},\leqslant)\) does not have a lattice structure, as can be the case of restricted CDMNN, since the computation of the neighborhoods \(N(\mathcal{C})\) may be costly. An interesting topic for future research is, based on prior information and domain knowledge, to design specific DMNN to solve problems of interest and implement efficient algorithms based on the LGDA for their training.

An efficient implementation of the general LGDA and SLGDA in Algorithms 1 and 2 to train CDMNN is also a topic for future research. The implementation of an algorithm to calculate the window and the basis of an MCG, as discussed in Remark 5.2, is also necessary. Once an efficient implementation is available, it would be interesting to further study empirical features illustrated in the application. For instance, it is necessary to better understand the effect of the architecture complexity and the batch size on the generalization quality of the trained CDMNN in order to build optimized architectures and properly select hyperparameters such as the number of epochs and batch size.

### Possible extensions

We believe the DMNN could be extended to represent a broader class of morphological operators in more general complete lattices. For instance, the canonical decomposition results of [4] were extended by [5] for general complete lattices and could in theory be the foundation of a DMNN architecture. In this instance, it may be necessary to combine the LGDA with a continuous optimization algorithm since the operators may not be represented by parameters in a lattice, but rather by a set of parameters that can be decomposed into a lattice of subsets of parameters. For example, for gray-scale images, the parameters of a vertex may be the window on which its operator is locally defined and the function representing the structural element whose domain is the window. The LGDA could be applied to select the window, while another algorithm would have to learn the structural element. The extension of DMNN to gray-scale images is a promising line of research which we pretend to follow.

The main bottlenecks to extending DMNN to solve more general image processing problems are the definition of a lattice algebra under which the problem can be solved via a lattice operator and the development of practical algorithms to train DMNN under this lattice algebra. For example, if one
could develop a lattice algebra for RGB images (see [2, 34, 45] for examples of possible algebras) and design image transformation operators as lattice operators, then the results of [5] could be applied to define the architectures of a DMNN, and if one could develop algorithms to train them, then they could be applied to solve state-of-the-art problems. Such an extension seems a giant leap now, but having a controllable and interpretable analogue of deep learning for general image transformation tasks would be a major advance and even if MM methods cannot attain this degree of generalization, some insights and important results may be achieved along the way. Such a possibility is a motive in itself to further study MM and DMNN extensions.

### Prior information and Neural Architecture Search

The quality of a DMNN is associated with the correct design of its architecture, in the sense of it representing operators that approximate a target operator, and with the efficiency of its training from both a computational and sample complexity perspective. Therefore, from an algebraic perspective, it is necessary to better understand how desired classes of operators can be efficiently represented by unrestricted CDMNN architectures since they can be more efficiently trained. Furthermore, it is necessary to properly insert prior information into the architecture, so it represents a collection of operators _compatible_ with the problem being solved, on which it is statistically possible, in the sense of statistical learning theory [47], to learn with the available sample size.

However, when strong prior information is not available, it may not be possible to properly design a DMNN architecture, and should be learned from data. A state-of-the-art topic in deep learning is architecture selection, or Neural Architecture Search (NAS) [17], whose methods are mainly based on computation demanding procedures to optimize the architecture based on data within an automatic machine learning (AutoML) paradigm [20]. Such an automatic approach would be incompatible with MM, since it does not take into account prior information and the properties of morphological operators.

A true MM method for architecture selection should, based on prior information about the problem at hand, consider a set of candidate DMNN architectures and then select one of them based on data. In some instances, the available prior information may not be enough to properly build one architecture, but may suffice to design a collection of candidate architectures that should be evaluated on data to select the _best_ one. These architectures
should generate collections of operators with increasing complexity, and selecting them should also be a mean of avoiding over-fitting and controlling the generalization quality of the learned architecture. If these candidate architectures could be themselves organized in a lattice, then they could be selected by a LGDA algorithm. The study of lattice-based architecture selection methods is an important line of research to control the complexity of the architecture relative to the sample size and obtain better practical results when strong prior information is absent. This is a line of research we are currently following.

### Impact to Mathematical Morphology

Mathematical Morphology is a classical paradigm for representing non-linear lattice transformations and had been a state-of-the-art method for image analysis, from the 1960s until recently, when it was overshadowed by the success of deep learning techniques. However, even though established MM methods cannot compete with deep learning from a performance point-of-view, MM has the great advantage of being a mathematically grounded image processing theory from which one can build methods that are completely controllable and interpretable, characteristics that deep learning lacks in general. Therefore, we argue, resonating the arguments of [1], that one should not disregard deep learning techniques, that are extremely useful and have many qualities, and expect to obtain state-of-the-art methods based solely on classical MM methods, but should rather rethink MM in view of modern learning techniques. The method proposed in this paper follows this research agenda.

We believe that the DMNN is a _true_ MM method since it retains the control over the design and interpretability of results of classical MM methods, which is an advantage over CNN. For instance, even though CNN can easily solve virtually any problem of binary image analysis, they cannot, in general, be controlled to represent a restricted class of operators based on prior information or be interpreted to understand the properties of the learned operator. Both these tasks are natural to DMNN, since its architecture can be specified via the MM toolbox to represent any class of operators, and, once it is trained, the basis of the operator can be computed and its properties can be fully known. Therefore, the DMNN are better than CNN from a semantic point of view. Since, from an algorithmic perspective, the SLGDA makes the training of DMNN scalable, they are a viable mathematically grounded practical method which ought to be further explored.
Besides providing a path to bring MM to the deep learning era, this paper also merges two, sometimes competing, paradigms of MM: heuristic design and automatic design via machine learning. The advocates of the heuristic approach have argued that the machine learning approach did not take into account strong prior information and did not have as much control over the operator design, while the advocates of the machine learning paradigm have argued that machine learning methods were necessary to scale MM applications and obtain good practical results via a less time-consuming approach. In hindsight, we believe that both arguments are valid and hope with the DMNN approach to unite these paradigms and help to regain the relevance of MM in the deep learning era.

## Acknowledgments

D. Marcondes was funded by grants #22/06211-2 and #23/00256-7, Sao Paulo Research Foundation (FAPESP), and J. Barrera was funded by grants #14/50937-1 and #2020/06950-4, Sao Paulo Research Foundation (FAPESP).
