# A Portable Optical Sensor for Microplastic Detection: Development and Calibration
## 3 Results and Discussion
### Microscopy and Image Processing  
The microscope verifies microplastics in the samples. Depending on the experimental requirements, the sensor can operate in two modes: microscope then light source, or light source then microscope. It is a digital Chiciris model with USB 2.0 connectivity offering 50\(\times\) to 1000\(\times\) magnification. Its portability and ability to seamlessly integrate Raspberry Pi 4 make it suitable for field and controlled laboratory applications.  
In microscope mode, the sample is first focused, and an image of the area of interest is captured. The image is then processed using a series of algorithms designed to detect microplastics based on their morphological characteristics. The initial step involves applying a grayscale filter to the image. This transformation converts the RGB (red, green, blue) color channels into a single-channel grayscale representation using the following equation:  
\[Gray=0.6R+0.3G+0.1B \tag{6}\]  
Equation (6) is the grayscale conversion equation.  
The grayscale value is calculated by combining the red, green, and blue channels, weighted by coefficients that sum to one. This ensures that the image keeps proper brightness and contrast. However, it should be noted that this method has inherent limitations. The coefficients must be between zero and one, and their sum must equal one.  
The next step is binarization, which turns the pixel values into zero or one based on a set threshold. Noise is removed using morphological operations, starting with closing and followed by opening. The cleaned binary image is subtracted from the original to emphasize object borders, which are further improved with Canny edge detection. Skeletonization refines the edges, creating a clearer outline of the detected structures.  
After completing the image-processing stage, microplastics are detected. Objects in the processed image are segmented using chain code to outline their boundaries. These segmented objects are then analyzed based on parameters such as color, fractal dimension, centroid distance, width, and height. The topology summary focuses on four main types--fragments, pellets, fibers, and flakes--since they are the most common and easiest to identify [43]. The implemented methods include the following:  
* **Gray filter application:** we apply a gray filter to the initial images;
* **Gaussian filter application:** we use a Gaussian filter to smooth the images;
* **Binarization:** we binarize the images to distinguish microplastics from the background;
* **Morphological operations:** we perform closing and opening operations to refine shapes and remove noise;
* **Dilation and erosion:** before skeletonization, we apply dilation followed by erosion to remove smaller objects from the image;
* **Edge detection:** We detect edges by subtracting the binarized image after applying a closing operation. This process is efficient and less computationally expensive, making it suitable for processing on a Raspberry Pi;
* **Skeletonization:** We apply skeletonization to all objects in the image to accurately analyze their structure;
* **Chain code application:** after skeletonization, we apply chain code to count the number of objects within the image;
* **Morphology determination:** we use polynomial approximation and fractal dimension analysis to determine the morphology of each object within the image, which makes it easier to classify them.  
These methods help identify and describe the microplastics based on their shape, creating a solid foundation for further research and use in environmental monitoring.