# YOLO-PGC: A Tomato Maturity Detection Algorithm Based on Improved YOLOv11
## 4 Experiments  
### Tomato Ripeness Dataset  
This study focuses on the detection of tomato ripeness, specifically targeting two common varieties grown in China: monochromatic and strip-shaped fruits. The dataset was designed to facilitate the recognition of red-ripe and orange-turning tomatoes. These exhibit distinct color and texture differences, serving as good experimental samples.  
Data collection took place between July and August 2023 at two commercial tomato plantations, one located in Weifang City, Shandong Province--Shouguang City (36.86\({}^{\circ}\) N, 118.73\({}^{\circ}\) E), and another in Qingzhou City (36.69\({}^{\circ}\) N, 118.47\({}^{\circ}\) E). These sites are both characterized by warm temperate monsoon climate, fertile soil, and abundant sunlight, making them typical examples of major tomato-growing regions. The data were collected under varying environmental conditions, including different illumination (e.g., intense midday sunlight and overcast light), complex backgrounds (e.g., weeds, supports, orchard foliage), and partial fruit occlusion scenarios. These conditions were selected to ensure that the dataset could capture the diversity of real-world agricultural environments.  
Images were captured using a handheld smartphone (Redmi K70), which was stabilized by a handheld gimbal to minimize shake and motion blur. This setup ensured stable and high-quality images despite the dynamic field environment. A variety of angles and distances were used to capture images, ensuring comprehensive coverage of tomato at various ripening stages. Each image had a resolution of 3000 \(\times\) 3000 pixels, providing sufficient detail for accurate ripeness analysis.  
The dataset includes 850 images of fully ripened red tomatoes and 760 images of half-ripened orange tomatoes. After data collection, frames were sampled at 20-frame intervals using the OpenCV library. Valid frames were manually screened and added to the dataset, achieving multiscale dataset expansion. Python scripts were used to adjust the image resolution to 1920 \(\times\) 1080 pixels for standardization, resulting in a final dataset of 1536 images (Figure 5).  
For the labeling process, LabelImg software (v.1.8.0) was used to annotate the images in YOLO format. Tomatoes were classified into six categories based on their visible characteristics and ripeness stages:  
* 0: b_fully_ripened (bottom fully ripened)
* 1: b_half_ripened (bottom half ripened)
* 2: b_green (bottom green)
* 3: t_fully_ripened (top fully ripened)
* 4: t_half_ripened (top half ripened)
* 5: t_green (top green).  
Tomatoes were classified into the \"bottom\" and \"top\" categories based on the visible stem scar orientation. If the stem scar faced downward or away from the camera, then the tomato was labeled as \"bottom\" (b), whereas if the scar faced upward or toward the camera it was labeled as \"top\" (t). This classification method is crucial for accurately assessing ripeness, as ripening patterns differ between the stem and blossom ends of the tomato.  
Tomatoes that were irrelevant to ripeness categories, such as unripened, diseased, or damaged fruits, were excluded in order to maintain the dataset's quality and relevance. The final dataset was split into a training set (1228 images) and validation set (308 images) using an 8:2 ratio, ensuring an even distribution across categories to optimize model training and generalization.