# A Low-Cost Automated Digital Microscopy Platform for Automatic Identification of Diatoms
## 2 Materials and Methods
### Automatic Slide Scanning
The variance of Laplacian has demonstrated its feasibility to validate in-focus diatom observation in such a way that the focus is much better when its calculated value is higher for the image [31; 33; 34; 54; 55; 56]. The Laplacian operator \(\Delta\) is calculated by convoluting the \(3\times 3\) kernel \(\mathcal{L}\) over the image \(I(m,n)\) (with \(m,n\) being the width and height in pixels of the image \(I\)). Then: \[\Delta(I)=I(m,n)*\mathcal{L}\] (1) with \(\mathcal{L}\) being: \[\mathcal{L}=\left[ \begin{array}{ccc}0&1&0\\ 1&-4&1\\ 0&1&0\end{array} \right]\] (2) After applying the operator \(\Delta\) to an \(m\times n\) image, a new array is obtained. Then, the value of the variance \(\Phi\) is computed for this new array by using the following equations: \[\Phi_{m,n}=\sum_{i}^{m}\sum_{j}^{n}\left[\left|\Delta I(i,j)\right|-\overline {\Delta I}\right]^{2}\] (3) with \(\overline{\Delta I}\) being the average of the Laplacian: \[\overline{\Delta I}=\frac{1}{m\times n}\sum_{i}^{m}\sum_{j}^{n}\left|\Delta I\right|\] (4) Based on the focus value (e.g., variance of Laplacian), it is necessary to define a strategy to reach the optimal focal position (\(\mathcal{Z}\)) after an X-Y stage motion. The first type of strategies is based in a global search over a stack of images focused at different distances to select the image with the maximum focus value (i.e., the best focused image). These strategies find the best focused image and also allow fusing a selected sub-stack to obtain a final all-in-focus image. This possibility is  
Figure 6: Different sequential scanning strategies: (**a**) following a snake-by-row path, (**b**) row-by-row path, and (**c**) based on ROIs following the next closest path. very interesting in microscopy to obtain better quality on images with several acquired ROIs at different focal planes [9; 13; 35]. However, these strategies are not appropriate when the response is time critical and the computing resources are quite limited. For automatic sequential scanning, this constitutes a valid approach since usually, there is very limited defocusing between consecutive patches; hence, a limited focal stack size usually includes the interesting images. Other types of strategies are motivated by reducing the time and stack size to find the image with the best focus (e.g., maximizing the number of ROIs in focus). These strategies are based on optimization methods to estimate some extreme point of a function (e.g., maximum of a focus function) [32; 35; 36; 57]. * Stitching: This is the process carried out to obtain an image composed by several images with overlapping FOVs. In digital microscopy, the automatic scanning is followed by the stitching of individual patches [28; 29]. This combined process is accomplished in three stages: (1) feature extraction, (2) image registration, and (3) blending of patches. * Preprocessing: This step consists of a set of operations applied over the image in order to mitigate the undesired effects of different sources of noise (e.g., thermal, electronic, etc.) affecting the digital image sensor and the appearance of undesirable artifacts in the image due to illumination, dust, debris, and so on. Usually, there are several types of imperfections with negative effects on microscopic images. The first type is independent of the observed specimens, and they are related to: the optical systems applied, illumination (e.g., dust particles on surfaces, uneven illumination), and noise affecting the image sensors. To remove the mentioned artifacts, the most typical operations carried out are those of [7; 14]: (A) Noise reduction: This is usually achieved by Gaussian filters when noise can be modeled with a Gaussian distribution. Multiple types of denoising filters have been developed depending on the necessity to preserve specific image features (e.g., edges) [37; 39].