# Automated Surface Defect Inspection Based on Autoencoders and Fully Convolutional Neural Networks
## 2 The Proposed Algorithm
### The Operations of AE and FCN  
The proposed algorithm is not restricted to any specific types of AEs and FCNs. However, for demonstration purposes, design examples of AE and FCN are revealed in Figures 4 and 5 and Tables 2 and 3. Based on the examples, the operations of each network are then presented.  
```
1:A trained AE \(F\).
2:A trained FCN \(G\).
3:An inspection target \(X\).
4:Thresholds \(T_{i},i=1,...,N\).
5:Initialize \(\mathcal{C}\leftarrow\emptyset\).
6:Compute \(Y=F(X)\) by (4).
7:Compute \(\{Y(1),...,Y(N)\}=G(Y)\) by (5).
8:Separate \(X\) into blocks \(\{x\}\).
9:Find \(y\) from \(Y\) for each \(x\in X\).
10:Form \(X(i)=\{x:y\in Y(i)\}\), \(i=1,...,N\), by (6)
11:for\(i\gets 1,N\)do
12:repeat
13:Get a block \(x\) from \(X(i)\).
14:Compute \(D(x,y)\), the L2 distance between \(x\) and \(y\).
15:if\(D(x,y)>T_{i}\)then
16:\(\mathcal{C}\leftarrow\mathcal{C}+x\).
17:endif
18:until All blocks \(x\in X(i)\) are searched.
19:endfor
20:return\(\mathcal{C}\)
```  
**Algorithm 1** Proposed quality inspection of surfaces algorithm.  
An important aspect of the AE shown in Figure 4 is that it is based solely on convolutional layers. The fully connected layers are not included. This is beneficial for reducing the number of weights and computation complexities of the algorithm. Furthermore, the convolution operations are able to effectively extract local features of input images.  
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Convolution Layers** & **Conv 1** & **Conv 2** & **Conv 3** & **Conv 4** & **Conv 5** \\ \hline Number of & & & & & \\ Input Chan. & 1 & 16 & 32 & 32 & 16 \\ \hline Number of & & & & & \\ Output Chan. & 16 & 32 & 32 & 16 & 1 \\ \hline Activation & & & & & \\ Function & ReLU & ReLU & ReLU & ReLU & ReLU \\ \hline \hline \end{tabular}
\end{table}
Table 2: Details of the convolution layers of the AE.  
\begin{table}
\begin{tabular}{c c c c c c c c c c c} \hline \hline
**Convolution Layers** & **Conv 1** & **Conv 2** & **Conv 3** & **Conv 5** & **Conv 6** & **Conv 7** & **Conv 8** & **Conv 9** & **Conv 10** & **Conv 11** \\ \hline Number of & & & & & & & & \\ Input Chan. & 1 & 64 & 64 & 128 & 128 & 256 & 256 & 128 & 128 & 64 & 64 \\ \hline Number of & &  
Therefore, the reconstructed images are less sensitive to the variations of global features such as positions of objects on the test images. This could be beneficial for reducing the efforts for alignment.  
The example of the FCN network shown in Figure 5 is used for image segmentation. As revealed in Figure 5, the FCN network is actually a simplified version of the U-Net [20]. It contains the analysis operations for feature extraction and synthesis operations for producing the segmented images. In addition to convolution operations, the U-Net also contains max-pooling, up-sampling, and concatenation operations so that features at different resolutions can be captured for image segmentation. It can be observed from Table 3 that the activation function at the final layer is the Softmax. The FCN produces \(N\) binary output images \(B_{1},...,B_{N}\). Each binary image \(B_{i}\) serves as a mask revealing the region \(Y(i)\). That is, all the locations of pixels in \(B_{i}\) with value 1 indicate the area covered by \(Y(i)\).