# Vision-Based Sorting Systems for Transparent Plastic Granulate
## Materials and Methods
### Methods
#### 2.2.2 Image Processing  
Before processing, the image was captured and stored in a buffer. The images were processed with delay to save time. This means that, while one image was captured, the other was processed. In classic processing, the image would be captured and processed immediately. Thus, the time it took to capture a camera image and transfer the image to a computer was lost. This time would be difficult to save in real-time applications of image processing. The overall image processing was separated into two main parts. These were the localization and classification of the granules. At localization, the originally captured images were reduced to 37% of their original size, as shown in Figure 3a, to speed up the image processing time. Then, the RGB green color extraction was performed and the correct brightness was set, as shown in Figure 3b. We then applied a Modified Sauvola threshold [36; 37], which makes a binary image with only granules, and some small regions which do not represent granules, as shown in Figure 3c. The processed image was sent to a filter to remove small regions of the image that did not represent granules, as shown in Figure 3d. Finally, the Particle Analysis method from LabVIEW National Instruments software was carried out, which gave us the \(x\) and \(y\) coordinates of the granules that were in the image. The \(x\) and \(y\) coordinates of the granules represented the center of mass of the object in the image. The Particle Analysis method takes some time to implement but it is critical to the operation of the sorter. At the conveyor's full speed, image processing took up to 100 ms. The actual time needed for processing depended on the number of particles in the image. Image capture, granule localization and classification were performed during this time. When a new image capture was triggered, the image capture was started, and the previous image was processed. Thus, the image capture and the processing were performed in parallel. The image buffer and image minimization saved 92 ms in image processing time. Without the implementation of the described procedure, the total image processing time would have been almost 200 ms. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Number** & **Class** & **Accept/Reject** \\ \hline
1 & Clean & Accept \\
2 & Blur & Reject \\
3 & Black dots & Reject \\
4 & More black dots & Reject \\
5 & Dark & Reject \\
6 & Pink & Reject \\
7 & Green & Reject \\
8 & Yellow & Reject \\
9 & Material mix & Reject \\ \hline \hline \end{tabular}
\end{table} 
Table 1: List of used samples. Only granules which were completely transparent and error-free were accepted. Therefore, a color classifier was used. All the granules found in the image were examined by the classifier. The granule location data from Particle Analysis were taken, and the granule image was cut at the granule location and sent to the classifier. The cropped image size was \(40\times 40\) pixels. Each cropped image was converted to the HSL color space. Then, the hue, saturation, and luminance histograms of the color sample were calculated. The hue and saturation histograms each contained 256 values, and the luminance histogram was reduced to 8 values. Combined, the 520 hue, saturation, and luminance values produced a high-resolution color feature vector. Because very fast real-time processing is required, the dimensions of the feature vector were reduced using a dynamic mask. A reduced color feature vector contains 128 hue and saturation values and 8 luminance values--for a total of 136 values--and represents the input to the classifier. By suppressing the luminance histogram into eight values (12.5% reduction), the algorithm accentuated the color information for the sample. Color feature vector of granule image was sent to color classifier, which was based on the \(k\)-NN algorithm. This is a statistical method for classification based on the nearest neighbor [38].