## Materials and Methods
### Image Preprocessing
#### 2.3.2 Gray Monochrome Conversion and Image Binarization (Thresholding)  
Conversion of an arbitrary color image to grayscale is not a unique procedure in general, as a different weighting of the color channels can effectively represent the effect of shooting black-and-white film. A common strategy is to use the principles of photometry and colorimetry to calculate the grayscale values so as to have the same relative luminance (i.e., the density of luminous intensity per unit area in a given direction) as the original color image. Given the RGB intensities (i.e., values in the range \(0\div 255\) for the RGB24 file format or normalized to \(0\div 1\)) provided by the three channels \(R\), \(G\), and \(B\), the luminance \(Y\) is defined as a weighted sum of these components. In this analysis, the coefficients from the ITU-R Recommendation BT.601 standard, revision 7 [50] are taken, so as to find:  
\[Y=0,299\;\;R\;+\;0,587\;\;G\;+\;0,114\;\;B \tag{10}\]  
Figure 3: First (**a**) and thousandth (**b**) frames of the video. Notice how the image (b) is out of focus and the center of the screw is translated upwards. N.B., The selected \(x\) coordinate goes from left to right, while the \(y\) coordinate goes from the top to the bottom, differently from the standard.  
The formula reflects the eye color photoreceptors sensitivity, which has a maximum in the green-light region. Notice that, in general, human-perceived luminance is commonly referred to as brightness, while luma is the luminance of an image as displayed by a monitor.  
The so obtained grayscale image is displayed in Figure 4a.  
Once the gray monochrome image is obtained, thresholding is implemented. The goal of thresholding is to classify pixels as either dark (0) or light (1) to produce a black and white (i.e., binary) image based on the luminance information.  
In its simplest implementation, the threshold is a constant set by the user, and the pixels' luminance is compared against this value. An automatic selection of the threshold was implemented by [PERSON] [51] as a Fisher's Discriminant Analysis performed on the intensity histogram. [PERSON]'s threshold is then determined by minimizing intra-class intensity variance, or equivalently, by maximizing inter-class variance (N.B., the two classes are obviously dark vs. light).  
Nevertheless, illumination changes in the image can lead to a bad classification. In this case, an adaptive threshold such as the [PERSON]'s could perform much better [52]. The idea is to use a local threshold which can vary within the image as it is adapted to the average of surrounding pixels. Typically, a moving window of approximately 1/8 th of the size of the image is used for computing the local mean intensity. Matlab implementation [52] also allows to tune the threshold using a scalar \"sensitivity\" in the range \(0\div 1\): high sensitivity value leads the thresholding of more pixels as foreground (i.e., class 1, light), at the risk of including some background pixels (i.e., class 0, dark).  
Thresholding, in fact, is commonly used to separate foreground objects from their background, reinforcing the action of the image cropping.  
Comparing Figure 4c to Figure 4b, the robustness of [PERSON]'s adaptive thresholding to illumination changes is highlighted. Furthermore, it can be noticed that the circle in the image background is removed, improving the robustness to background changes and clutter.  
Figure 4: (**a**) Original grayscale: Grayscale conversion of the first frame of the video (Figure 3a) using luminance [50]; (**b**) Otsu threshold: Comparison of [PERSON]’s thresholding [51]; (**c**) Adaptive thresholding (Bradley) [52; 53] with sensitivity: 0,99; (**d**) Not-Sobel filtering [54; 55] applied to the grayscale image in (a).