## 3 Materials and Methods
### HSV Colour Space Model Approach  
An approach based on histograms from the HSV colour space was developed as an alternative to DL models for tomato classification. All the scripts used throughout this process are authorship and were created from scratch through Spyder (see [[https://www.spyder-ide.org/](https://www.spyder-ide.org/)]([https://www.spyder-ide.org/](https://www.spyder-ide.org/)), accessed on 25 October 2021). The developed HSV colour space model and the scripts can be found in the following GitHub repository: [[https://github.com/gerfsm/HSV_Colour_Space_Model](https://github.com/gerfsm/HSV_Colour_Space_Model)]([https://github.com/gerfsm/HSV_Colour_Space_Model](https://github.com/gerfsm/HSV_Colour_Space_Model)) (accessed on 25 October 2021). In order to build the model, images of 10 tomatoes from each ripeness class were selected. To add some variability, half of the images come from the AgRobTomato Dataset and the other from the RipTomato Dataset, as they present different perspectives of the fruits. The AgRobTomato Dataset offers a farther perspective, while in the RipTomato Dataset the fruits are closer. The first step was to extract the RoI from the images. All the images were labelled using the annotation tool CVAT and the coordinates of the annotation bounding box were used to segment the image and extract the RoI. The next step was to convert the RoI images from RGB to HSV colour space. The RGB colour information is usually much noisier than the HSV information. Thus, using only the Hue channel makes a computer vision algorithm less sensitive, if not invariant, to problems like lighting variations. The image's colour space conversion was performed through the function \"cv.cvtColor()\" (see [[https://docs.opencv.org/4.5.2/df/d9d/tutorial_py_colorspaces.html](https://docs.opencv.org/4.5.2/df/d9d/tutorial_py_colorspaces.html)]([https://docs.opencv.org/4.5.2/df/d9d/tutorial_py_colorspaces.html](https://docs.opencv.org/4.5.2/df/d9d/tutorial_py_colorspaces.html)), accessed on 13 June 2021) from OpenCV [69]. For each HSV image, a colour histogram was generated focusing only on the Hue channel. OpenCV was used to extract the colourimetric data from the RoI. Different applications use different scales to represent the HSV colour space. For the Hue values, OpenCV uses a  
Figure 4: Workflow of the performed methods to reach the trained DL models. scale ranging between 0 and 179. Since the interest is focused on analysing the region of colours that a tomato can display, the entire colour spectrum is unnecessary. Therefore, the location of the origin for the Hue parameter was changed, giving the histogram a seemingly normal distribution. Through Matplotlib [70], the function \"matplotlib.pyplot.hist\" (see [[https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html)]([https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hist.html)), accessed on 22 July 2021) was used to plot the H-spectrum histogram. In this case, the function parameter \"density\" was set to \"True\", which causes a probability density to be drawn and returned. It was preferred to use all the bins in the range to get as accurate a model as possible. Each bin displays the bin's raw count divided by the total number of counts and the bin width so that the area under the histogram integrates to 1. Although the segmentation technique used is faster and easier to implement, it can be noted that the RoI covers the object to be classified and some of the background, which slightly affects the results obtained. In some cases, the background makes the data look multimodal, i.e., there is more than one \"peak\" data distribution. Trying to fit a multimodal distribution with a unimodal (one \"peak\") model will generally give a poor fit and lead to incorrect classifications. Gaussian mixture model was used to overcome this problem.