# Deep Morphological Anomaly Detection Based on Angular Margin Loss
## 4 Proposed Method
### Morphological Image Processing
#### 4.1.1 Erosion and Dilation  
The erosion at any location \((x,y)\) of image \(\mathbf{A}\) by a kernel \(\mathbf{b}\) is the _minimum_ value of \(\mathbf{A}\) in the region covered by \(\mathbf{b}\) when the central point of \(\mathbf{b}\) is at \((x,y)\). If \(\mathbf{b}\) is an \(S\times T\) kernel, obtaining the erosion at a pixel requires obtaining the smallest of the \(ST\) values of  
**A** included in an \(S\times T\) region determined by the kernel when its origin was at that point. Mathematically, the erosion is defined as follows:  
\[[\textbf{A}\ominus\textbf{b}](x,y)=\min_{(s,t)\in\textbf{b}}\{\textbf{A}(x+s,y+t)\}, \tag{5}\]  
where \([\textbf{A}\ominus\textbf{b}]\) denotes the erosion of **A** with filter **b**, and \(\textbf{A}(x,y)\) denotes the \((x,y)\) pixel in image **A**, and \((s,t)\) is the \((s,t)\) pixel in filter **b**. Notably, the origin points in **A** and **b** are defined as the top-left corner pixel and central pixel, respectively. Because the erosion calculates the minimum pixel value of **A** in every neighborhood of \((x,y)\) coincident with **b**, it is expected that the size of bright features will be reduced, and the size of dark features will be increased. The third column in Figures 2 and 3 show the eroded images of the \"normal\" and \"abnormal\" samples, respectively, in the \"tile\" class of MVTec. From these figures, it can be seen that the erosion process enlarges the dark features of an image. Additionally, it was found that the shape of the extracted features from the morphological transformation depends on the form of the kernel. If a vertical-shaped filter is used, the erosion causes the dark region to enlarge vertically.  
In contrast, the dilation at any location \((x,y)\) of image **A** by a kernel **b** is the maximum value of **A** in the region covered by **b** when the origin of **b** is at \((x,y)\). The dilation transformations can be defined as follows:  
\[[\textbf{A}\oplus\textbf{b}](x,y)=\max_{(s,t)\in\textbf{b}}\{\textbf{A}(x+s,y+t )\}, \tag{6}\]  
where \([\textbf{A}\oplus\textbf{b}]\) denotes the dilation of **A** with filter **b**. In contrast to the erosion process, dilation increases the size of bright features and decreases the size of the dark features. The second column in Figures 2 and 3 show the dilated figures of \"normal\" instances and  
Figure 2: Morphologically transformed “normal” images in the “tile” class of MVTec [5]: (first column) the original “normal” image; (second column) dilated “normal” images; (third column) eroded “normal” images; (fourth column) morphological gradient of “normal” images; (first row) except the top left image) “normal” images morphologically transformed with [13; 13] kernel; (second row) images transformed with [13; 1] kernel; (third row) images transformed with [13; 1] kernel. [5, \(T\)] is an \(S\times T\) kernel, where \(S\) and \(T\) are the width and height of the filter, respectively.  
the anomalies in the MVTec \"tile\" class, respectively. It is evident from these images that dilation has the opposite effect of erosion.