## 2 Materials and Methods
### Computer Vision Software for Image Processing
#### 2.3.2 Self-Developed Software to Process Black Gordal Color Images  
In parallel, an application was developed in the MATLAB R2022b environment, consisting of two scripts [45]. Figure 8 presents a diagram of the workflow of the first script. Figure 6: Counts, percentages, and orientation ranges for each olive category (normal, _tilted_, boat, and other cases). The subsequent analysis considers only olives in the normal and boat orientations, as these two classes account for the operational performance of the line. Figure 7: Representative raw images captured on the feed chain immediately upstream of the pitting station. Olives whose major axis is aligned with the awl—i.e., in the correct orientation for pitting—are enclosed by a green frame, whereas fruits whose major axis lies perpendicular to the awl, exhibiting the so-called boat orientation and therefore unsuitable for pitting, are marked with a red frame. * Binarization. A graphical user interface implemented in MATLAB (Figure 9) performs HSV-based segmentation and orientation detection on each olive [46; 47]. HSV was selected for its robustness to illumination changes, its intuitive two-parameter tuning, and the negligible conversion software cost of a single cv::cvtColor call. The image processing stage follows the pipeline summarized in Figure 8 and detailed in Algorithm 1. Each RGB frame is first converted to HSV; a binary mask M is obtained by applying fixed thresholds on the three channels (Equation (1)). The mask is refined through an erosion-dilation-erosion sequence with circular structuring elements of radii r\({}_{1}\), r\({}_{2}\), and r\({}_{3}\) (Equation (2)), after which the largest connected component is retained and internal holes are filled. The central moments of this blob are then computed and the olive's major axis orientation \(\theta\) is calculated from Equation (3), while the pixel area A is obtained by direct summation. All threshold limits (\(H_{min}\), \(H_{max}\), \(S_{min}\), \(S_{max}\), \(V_{min}\), \(V_{max}\)) and kernel radii are read from a calibration file, so no manual tuning is required at run time. The complete MATLAB implementation of Algorithm 1 is provided in the script **binarize2d.m** (Code S1 in the Supplementary Materials). Figure 8: Workflow of the MATLAB application. Figure 9: Workflow of the MATLAB application: (**a**) image captured from the processing line, (**b**) pixel value decomposition commands based on HSV, (**c**) initial segmentation, (**d**) erosion and dilation commands, (**e**) final segmentation with identification of the major axis orientation. \[ \begin{split}&\mathit{mask}(x,y)\\ &=\left\{\begin{aligned} 1&\mathit{H}_{min}\leq H(x,y) \leq H_{max}&\ \land\ S_{min}\leq S(x,y)\leq S_{max}\land V_{min}\leq V_{(x,y)}\leq V_{max}\\ &\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad\qquad 0\,\mathit{otherwise}\end{aligned}\right.\end{split}  \tag{1}\]  
\[ \begin{split}\mathit{Erode}(M,SE_{r})=\left\{p\Big{|}SE_{r}+p \subseteq M\right\};\quad\mathit{Dilate}(M,SE_{r})=\left\{\,p\Big{|}(SE_{r})^{V} +p\cap M\
eq\varnothing\right\}\end{split}  \tag{2}\]  
\[ \begin{split}\theta=\frac{1}{2}\cdot tan^{-1}\left(\frac{2\cdot J _{xy}}{J_{xx}-J_{yy}}\right);\qquad A=\sum_{x,y}mask(x,y)\end{split}  \tag{3}\]  
The morphological segmentation separates olive pixels from the conveyor background, exploiting intensity differences caused by highlights and shadows in an otherwise low-contrast scene. The algorithm determines the extreme HSV values--Hmin, Hmax, Smin, Smax, Vmin, and Vmax--within the largest blob (Figure 8(b)). These limits are then applied to the original frame to obtain an initial mask that outlines the fruit (Figure 8(c)). The threshold values and the three morphological radii are automatically written to \"settings.txt\". Additionally, the mask is refined with three morphological operations--erosion, dilation, and a second erosion--to remove background noise and to close gaps inside the olive produced by over-illumination or shadow artefacts (Figure 8(d)).