## 2 Materials and Methods  
To develop the proposed method, 50 diatom images taken from the public data Automatic Diatom Identification and Classification (ADIAC) project were used [12]. The mathematical algorithms to tune the segmentation methods were developed using Matlab. The software was implemented in an Intel core i7-4500U 1.8 GHz computer with 1.6 GB RAM running under Windows 8.1. The method will become publicly available through the lab webpage [[http://www.gatv.ssr.upm.es/~jmm/PST_8989776.zip](http://www.gatv.ssr.upm.es/~jmm/PST_8989776.zip)]([http://www.gatv.ssr.upm.es/~jmm/PST_8989776.zip](http://www.gatv.ssr.upm.es/~jmm/PST_8989776.zip)). The methods commonly used to segment phytoplankton usually require some parameters to be fixed by the user before their analysis and classification. The segmentation result is generally a binarised image where the background appears in black and the foreground in white or vice versa. The resulting images, obtained with different values, are usually compared between them or with a ground truth image, i.e., the image produced by an expert. This comparison is made to find values that make it possible to obtain the best segmentation. As shown in Figure 1, by varying a parameter within a range of values in a segmentation method (Canny), results move from under-segmented images (Figure 1B,C) to over-segmented ones (Figure 1E,F), passing through an intermediate value where the best possible result is obtained (Figure 1D). It can be seen that changes between successive under-segmented and over-segmented images are more abrupt compared to those produced between images closer to the optimal result. This behaviour is expected because the optimal result seeks to get closer to what is actually seen in the original image. The under-segmented and over-segmented results correspond to the farthest valuesfrom the optimum. In these results, true edges or regions are eliminated (under-segmentation) or false ones are produced (over-segmentation), introducing the abrupt changes observed between them. Therefore, if two successive under-segmented images are compared, the first one will be less under-segmented than the next one. Assuming that the first image is the ground truth, we will have a high number of false positives and a low number of false negatives. Similarly, when comparing two successive over-segmented images, the first one will be less over-segmented than the second one. In this case, if the first image is the ground truth, we will then have a low number of false positives and a high number of false negatives. It must be mentioned that this observation is valid in diatom and phytoplankton typical images, where segmentation is developed to detect the shapes of the organisms. However, this is not valid in images where textures or complex background are observed. Based on this premise, the following method for tuning parameters is proposed. Let \(T\Big{(}I,\overrightarrow{p}\Big{)}\) represent the transformation of an image \(I\) into a binary one as a result of a segmentation algorithm given a certain number \(r\) of parameters, i.e., \(\overrightarrow{p}=\{p_{1},\ p_{2},\ldots p_{r}\}\). In the binary image, level 1 represents the object of interest, and level 0 the background. Therefore, an r-dimensional solution space \(P^{r}\subseteq\mathbb{R}^{r}\) generated by the transformation \(T\Big{(}I,\overrightarrow{p}\Big{)}\) can be defined. In the solution space, each coordinate is given by a parameter and each point of the space represents a binary image. Considering image segmentation as an optimization problem, the best solution can be found by maximizing a similarity function or minimizing a distance used as cost function \(\Psi\) in \(P^{r}\). In this way, the best solution can be found by sweeping the solution space, while evaluating the cost function  
Figure 1: (**A**) Original image taken from the public data Automatic Diatom Identification and Classification (ADIAC) project.