## 2 Materials and Methods
### Tomato Detection Algorithm
* Image Binary Inversion  
After detecting the fruit edge, the obtained image is still not ready to be used for the edge subtraction (Figure 5) since the binary image of the fruit contours is inverted (Figure 8a). In addition, segmentation based on size was carried out (Figure 8b) to eliminate the small regions that remained inside the contours, making them more defined. * Segmentation based on color 1 (Figure 9) to obtain a separated region for each mature tomato that appears in the image. Figure 8: (**a**) Binary inversion; and (**b**) size segmentation. * Edge subtraction (Figure 10): next, we applied the logical AND function on Figures 8b and 9b. The result was a new binary image where the region, or regions, representing the total ripe surface, appears divided into regions that already represent individual ripe tomatoes (Figure 10b). * Color-Based Segmentation 2: Obtaining Separate Regions. The subsequent processing stage (Figure 11a) was to perform a new segmentation based on color (segmentation in color--2), in order to achieve a binary image in which each ripe tomato appears represented by a single region, separated from the rest of the regions (Figure 11b). This task is quite complicated, since ripe tomatoes often appear in the image superimposed on one another, or so close to each other that their regions come together. The difficulty lies in the fact that ripe tomatoes are all practically the same color, which makes it very difficult to obtain a separate region for each of them. Nonetheless, the tomatoes appear much brighter in their central area, and darker as we get closer to the edges. This makes it easier for us to carry out a color-based segmentation in which only the central part of the ripe tomato is detected, meaning that the tomatoes appear represented by separate regions even if they overlap (Figure 11b). Figure 10: (**a**) Segmentation based on color 1; and (**b**) edge subtraction (Figures 8b and 9b). Figure 9: (**a**) Original image; and (**b**) segmentation based on color 1 (the whole ripe surface is obtained). The objective of segmentation based on size is to eliminate all of these regions, keeping only those that represent the ripe tomatoes in the foreground. It also removes regions that belong to ripe tomatoes cut off by the edge of the image (Figure 13b). As we can see, two size-based segmentations were needed. The first segmentation (Figure 13c) to remove little regions, and the second to remove the regions that are less than half the size of the largest region (Figure 13d). In this way, the fact that no ripe tomato appears in the image is no longer a problem. * Representation of the regions (Figure 14): this shows the user which regions obtained after the segmentation based on size represent the possible \"collectible\" tomatoes. To achieve this we computed the convex area of Figure 13d. Not all of these will be so, since it will depend on whether their peduncles are visible or not from the perspective from which the image was taken. Figure 14: (**a**) Original image; and (**b**) convex area of Figure 13d. Figure 5.0 (**a**) Figure 12b; (**b**) edge removal of image objects; (**c**) segmentation based on size 1; and (**d**) segmentation based on size 2.