**3. Image Acquisition and Processing**

Thanks to the large number of contexts in which digital image processing has been successfully in experimentation, its use has also increased in medicine that is becoming highly dependent on it and represents fundamental pillars of modern diagnosis [38–42].

The images of the smears used in this experimentation, supplied by the Policlinico di Bari, have been acquired with a Samsung Galaxy S6 Edge smartphone with a 16 Mpixel digital rear camera, with a photo resolution of 5312 × 2988 pixels and an aperture of F / 1.9. A specific smartphone adapter was also used, as shown in Figure 2. The system proposed here is based on image enhancement, segmentation, and morphological processing [43], which allows for the extraction of the cells present in the photo acquired by the smartphone camera and will be dealt with in this paper shortly.

**Figure 2.** Image acquisition.

#### *3.1. Image Enhancement*

There are several definitions of image enhancement in the literature but the one that best fits the context states that this process allows for the improvement of the quality and information contained in an original image before it is processed [44–46]. The result of this pre-process represents an improved image that highlights some features more relevant than others both for the visual and automated systems, which otherwise would not be visible in the original image; therefore, an image will be easier to interpret in certain contexts.

Image enhancement involves several aspects of an image: those that will be dealt with in this work concern brightness (or luminance), contrast (the difference between the pixel of higher and lower intensity), and saturation.

In Figure 3, the effects of image enhancement techniques on an image of nasal cells with low brightness and contrast are evident. The central image appears sharper and this brings many advantages, as the cells appear more visible and highlighted due to the increased contrast. The image on the right is too bright and needs the so-called gamma correction.

**Figure 3.** Image Enhancement. Original image (on the left); image with contrast enhancement (in the center); image with brightness enhancement (on the right) that needs gamma-correction.

Gamma correction hides brightness defects in an image using a non-linear function based on the following transformation:

$$
\rho = \left(\frac{I}{255}\right)^Y \cdot 255\tag{1}
$$

where the γ is called gamma and the I and O values indicate the input value of the pixel and the output value of the non-linear function, respectively. This correction is often used to manipulate contrast in medical images, especially to highlight specific characteristics in an image with low lighting and low contrast.

#### *3.2. Image Segmentation*

Image segmentation partitions a digital image into a finite number of different regions, where region means a set of interconnected pixels. A significant number of image segmentation techniques allow the partitioning of a digital image [12,47], some of which have been considered in this project.

Images from the whole smear were taken and analyzed, as explained above, in smaller regions, called fields. In terms of pixels, all fields have the same size. Many attempts were made to choose an optimal dimension of each digital image to speed up processing—ultimately, the fields were resized to 1024 × 768 pixels, which proved to be a fair compromise.

Cell extraction was essentially based on the chromatic characteristics of cells, especially nuclei. For example, neutrophils show a blue-violet core, eosinophils show pink granules, and lymphocytes show a very large nucleus of blue color. Mean Shift filtering makes an image with color gradients and fine-grain texture flattened. In order to set up the system to recognize images of slides prepared with different techniques in the future, experiments were conducted here using grayscale images for the segmentation phase based on the Otsu algorithm. Then, morphological operations and the watershed algorithm were applied, followed by labeling, marking the different "objects" with different shades of color to facilitate subsequent classification. The Canny algorithm was considered as an alternative in rare cases when watershed provides unsatisfying results (e.g., split cells). In these cases, giving the responsibility to the user to manually adjust thresholds, segmentation showed better results than watershed. Of course, this option is considered a marginal one.
