DOI: 10.3303/CET24114139 Paper Received: 9 May 2024; Revised: 4 October 2024; Accepted: 7 December 2024 Please cite this article as: Ambrus B., Nyéki A., Teschner G., Moldvai L., 2024, The Effect of Illumination on HSV Colour Segmentation for Ripe Tomatoes based on Machine Vision, Chemical Engineering Transactions, 114, 829-834 DOI:10.3303/CET24114139 CHEMICAL ENGINEERING TRANSACTIONS VOL. 114, 2024 A publication of The Italian Association of Chemical Engineering Online at www.cetjournal.it Guest Editors: Petar S. Varbanov, Min Zeng, Yee Van Fan, Xuechao Wang Copyright © 2024, AIDIC Servizi S.r.l. ISBN 979-12-81206-12-0; ISSN 2283-9216 The Effect of Illumination on HSV Colour Segmentation for Ripe Tomatoes based on Machine Vision Bálint Ambrus, Anikó Nyéki, Gergely Teschner, László Moldvai* Department of Biosystem and Precision Technology, Széchenyi István University, Vár square 2. Mosonmagyaróvár, Hungary moldvai.laszlo.attila@sze.hu In agriculture, computer vision and image processing are essential for monitoring crops and controlling robots and actuators. In this work, the detection of ripe tomato fruit was the main aim. During the tomato-ripping process, the green tomato turns to red in several color stages (Ambrus et al., 2024). While the chlorophyll concentration decreases, the lycopene concentration increases. The sugar and the acid increase parallel to lycopene. The RGB camera can capture the process but needs to convert HSV color space to identify the tomato. The successful identification depends on the direct illumination volume. The experiment contains 4 ripe tomatoes and 15 different artificial illumination levels. The measurements show that the results are similar to or constantly above 3,000 lx illumination. However, under 3,000 lx, the detected size of tomatoes looks smaller and smaller depending on the weakness of illumination. Around 1,600 lx, it is possible to measure only half of the real size of the tomato. It shows that using the right amount of light is crucial to precise measurement in HSV color space. This research highlights the critical importance of proper illumination in ensuring accurate image analysis for tasks like industrial tomato segmentation. It emphasizes the need for adaptable lighting solutions, particularly in varying weather conditions, and the balance between adequate light and energy efficiency. 1. Introduction Today, precision agriculture boasts numerous innovations. Agriculture now utilizes drones for monitoring and spraying, as well as agricultural robots, both small and large, capable of autonomous operation. These robots can perform various tasks, including weeding, monitoring, spraying chemicals, and harvesting crops and products, all with precision and selectivity. To accomplish these tasks, advanced Computer Vision (CV) systems backed by big databases and neural networks are needed. Once images are captured using cameras, the initial step involves identifying the relevant parts within them. For instance, when monitoring tomatoes to estimate yield or cropping times, it's essential to locate the ripe tomatoes in the images. However, this requires understanding some fundamental aspects first. Known that unripe tomatoes are green, while ripe tomatoes are red. However, upon taking photos of tomatoes, a variety of green shades and numerous red-colored tomatoes were discovered, as well as some that were almost white or even orange. The tomatoes used are the same type but at different stages of ripeness. Upon reviewing the images, it has been identified that there are some additional challenges. Some tomatoes were in direct sunlight, while others were in shadow or partial shade. Furthermore, weather conditions varied from sunny to cloudy, and the amount of sunlight differed between morning and afternoon. It's crucial to comprehend and address these circumstances. This brief study employed spotlights with adjustable illumination and captured photos of four ripe tomatoes in a controlled environment. The aim was to understand how illumination affects tomato segmentation methods. This understanding is vital because, ultimately, the segmentation results will guide the actions of robots and actuators in fields and greenhouses. By analyzing how adjustable illumination impacts segmentation accuracy, the research highlights the need for advanced vision systems that can adapt to environmental variables. The novelty lies in addressing these specific challenges and enhancing the reliability of robotic systems for tasks such as 829 yield estimation and harvesting in both fields and greenhouses. The research demonstrates the influence of adjustable illumination on segmentation accuracy, emphasizing the need for advanced vision systems capable of adapting to varying environmental conditions. The novelty of this study lies in addressing these specific challenges and improving the reliability of robotic systems for critical applications such as yield estimation and harvesting in both field and greenhouse environments. The research establishes a specific illumination threshold of 3,000 lx as crucial for the accurate segmentation of ripe tomatoes, a parameter that has not been widely investigated in the context of practical agricultural robotics applications. 2. State of the art When tomatoes are green, they contain a lot of chlorophyll, giving them that classic green hue. As tomatoes ripen, the chlorophyll starts to fade away, making way for other important chemicals like lycopene. Lycopene is another one of those carotenoids, and it's what makes ripe tomatoes turn that vibrant red. Understanding these chemical dynamics is essential for optimizing agricultural practices and enhancing tomato cultivation efficiency. Following the chemical background, the next step involves gaining a deeper understanding of the physics of color. The sun emits a full spectrum of light, and tomatoes absorb and reflect certain wavelengths of this spectrum. This absorption is directly related to the presence of chemicals within the tomato. Numerous studies prove the effectiveness of non-destructive tests based on computer vision in the field of vegetable and fruit classification in the food industry and precision agriculture. Souraya et al. (2017) discussed the assessment of olive ripening using computer vision, where RGB images were converted to the Lab color space. However, the HSV color space has become more commonly used in recent years. The characteristics of tomato color are widely used as a good indicator for recognizing the ripeness level (Selvaraj et al., 2013), which is also related to sugar content, acidity, and flavor (Li et al., 2008). That is why color characteristics are widely used to evaluate the quality of the crop. In this case, the color characteristics of each pixel in the images come from three components: red, green, and blue. However, the RGB component is not as standardized as it should be. Atsushi et al. (2015) tested five different cameras with tomatoes under both natural and artificial light, revealing that even the same tomatoes in identical lighting conditions can produce varying RGB values depending on the camera used. In our study, we utilized a single camera and varied the illumination. The captured RGB images needed to be converted to another color space, and algorithms were required to accurately measure the color and shape of the tomatoes. Malik et al. (2018) presented the HSV scene-based algorithms for ripe tomato detection and used the Watershed segmentation method to separate clustered fruits from each other. Their approach, focused on identifying red tomatoes for a harvesting robot, achieved a detection accuracy of up to 81.6% in a real tomato field under uneven illumination and complex backgrounds. In that study, uneven illumination was present but was neither measured nor assessed for its impact on the results. In real-life conditions, illumination variations resemble the effect of saturation in images. This observation led to the next study, where Mohamadi et al. (2004) converted RGB images of tomatoes into HSV and YCbCr color spaces to segment ripe tomatoes and calculate their center coordinates based on a threshold value. Their study examined RGB, HSI, and YCbCr color spaces and concluded that the RGB and HSI color spaces were more effective for distinguishing tomatoes from the background when Saturation > 0.50. However, they did not account for varying illumination levels. In contrast, the focus of our study was to determine the optimal illumination threshold to enhance segmentation accuracy. Accurate camera calibration is also very important for digital imaging, especially when metric information is needed (Gao and Fin, 2013). In many machine vision applications, this is a crucial step to accurately determine the relationship between an image of an object and its physical size by performing a calibration process. In relation to the developed robot, the technical Hungarian design patent awarded (application title: Field and Horticultural Monitoring Device, applicant: Széchenyi István University, case number: U2300124) revealed through prior novelty research conducted before the submission that the described modular robot and the technology applied on it are not yet available on the market in such a complex form. 3. Material and method The hypothesis was that lighting conditions, particularly illumination, can significantly influence the image processing procedure and have a major impact on segmentation. The assumption was that there may be a threshold, below or above which segmentation becomes inefficient or ineffective. The hypothesis posits that lighting conditions, specifically illumination, play a critical role in the image processing workflow and can significantly affect segmentation accuracy. The proposition was that an optimal illumination threshold exists, beyond which segmentation becomes either inefficient or ineffective. This threshold was expected to delineate the boundaries where image analysis for tasks such as tomato segmentation achieves maximum effectiveness, with suboptimal lighting conditions impairing the segmentation process. The most important feature of the image 830 segmentation procedures was the determination of color space data of the appropriate value for the purpose of creating an accurate selection. HSV values were used during the study. To determine the values, the images of the tomato crop were used under different lighting conditions using histograms representing the separate channels of the images. During the experiment, 15 images were taken under identical settings of 4 ripe tomato samples collected from the greenhouse trial. For the image capture, a Canon EOS 1100D DSLR camera with the following settings for each image: 4,272×2,848 pixel resolution, ISO 800 sensitivity, 1/1000 s shutter speed, f/4.6 aperture value, and 32 mm focal length. The images were taken in front of a white background with continuously adjustable artificial lighting provided by a 1000 W studio lamp (Figure 1b). Thanks to the light source of the studio lamp, the emitted light had a continuous spectrum distribution, similar to sunlight. The regulation was controlled by a toroidal transformer. The 15 images corresponded to 15 different lighting values, which were measured using a BH1750 light intensity sensor operated via an Arduino Nano platform. The characteristic colors of the image were extracted from the histograms, and the HSV values of these colors were used to determine the segmentation intervals. With the help of this data, the optimal color interval and the limit values of the illumination can also be determined, and the segmentation according to the best colors can be realized. The process's main steps are in Figure 1a). a) b) Figure 1: The main process steps (a), The experimental circumstance. The lamp and the 4 tomatoes on white paper (b) 4. Results During the investigation, 15 pictures were taken with the same settings of 4 ripe tomato samples collected from the greenhouse experiment. The Canon EOS 1100d DSLR camera was used to take the pictures, with the same settings for each picture. The completed images included 15 types of illumination values (Figure 2), the measurement of which used the BH1750 light intensity. Figure 2: Light intensity in the 15 images case An OpenCV-based technique was used to process the images, which extracted the five different color characteristics of the image and the HSV values of these colors from the images. Some of the colors characterized the white part of the background, while the other two colors focused on the color of the tomato. Figures 3 and 5 illustrate the values of these two colors. Figures 4 and 6 show the color characteristic. 831 Figure 3: The first dominant color characteristic of ripe tomatoes and their HSV values Figure 4: The characteristic of the first dominant color Figure 5: The second dominant color characteristic of ripe tomatoes and their HSV values Figure 6: The characteristic of the second dominant color Using the minimum and maximum values of HSV, the values of the segmentation interval can be determined (Table 1), which means the typical H-S-V summers of ripe tomatoes. 832 Table 1: The HSV interval established for ripe tomatoes H S V Low values 0 62 0 Height values 15 255 255 Using the color segmentation interval determined based on Table 1, determined the size of the selected areas in pixels on each image under illumination using a machine vision algorithm and fitted the best-fitting circle to it (Figures 7 and 8). a) b) Figure 7: The relationship between 11,935.42 lux lighting, selected surface elements (a), and fitted circles (b) a) b) Figure 8: The relationship between 1,635.83 lux lighting, selected surface elements (a), and fitted circles (b) Based on the results, it can be concluded that the size of the designated area begins to decrease sharply at values lower than 3,000 lx, and at 1,600 lx, approximately half of the real area is no longer marked by the procedure (Figure 9). Figure 9: The size of the area selected during the segmentation process as a function of illumination Due to the incorrect designation, the position and number of the fitted circles are no longer sufficient for the appropriate level of crop estimation at values lower than 3,000 lx illumination. During sunny weather, there is enough light as the sun shines with an intensity of approximately 100,000 lx. Such conditions ensure ample illumination even in shaded areas, where roughly 20,000 lx of light is still available. These differences in light intensity between sunlit and shaded areas show the need to account for variations in illumination when making validations or measurements. Ensuring – if possible - consistent lighting conditions aid in obtaining reliable and precise results across different circumstances. During cloudy weather, the typical light intensity decreases significantly to only around 1,000-2,000 lx. For industrial tomato 833 segmentation, a minimum illumination of 3,000 lx is necessary to ensure accurate results. However, from an energy-saving perspective, lighting levels between 3,000 to 4,000 lx are sufficient. There is no justification for using stronger lighting, as it would only result in unnecessary energy consumption without providing significant benefits in terms of segmentation accuracy. In this case, 3,000 lx serves as a suitable choice for illumination. However, it's important to acknowledge that different cameras have varying sensitivities, meaning that slightly different values may be obtained with different cameras 5. Conclusions The intensity of illumination holds significant importance in terms of accurate evaluation. Consequently, capturing images for analysis during overcast or rainy conditions may not yield optimal results due to the diminished illumination. However, if there is a need to utilize the system during early morning, evening, or nighttime, artificial lighting becomes essential. Implementing artificial illumination ensures consistent and adequate light levels for accurate image-making and analysis regardless of the time of day or the actual weather conditions. This highlights the importance of adaptable lighting solutions to maintain the reliability and effectiveness of the system across various environmental conditions and operational hours. If don’t have an artificial lighting solution, then the robot can work on special weather cases. Sometimes it is not a problem. Striking a balance between adequate illumination for precise segmentation and optimizing energy usage is key to achieving efficient and sustainable industrial tomato processing. Additionally, it's worth considering that most cameras are equipped with automatic shutter speeds. This means that they measure the light and, in low-light conditions, keep the shutter open for a longer duration, allowing light to enter overall. This feature may enable the robots and cameras to operate even in cloudy weather conditions. However, long shutter speeds can result in blurry images, particularly in scenarios involving moving robots or stationary cameras capturing wind-blown plants. Achieving the right balance between adequate exposure and preventing motion blur is essential for ensuring the quality of captured images across different environmental conditions and operational scenarios. The key point is to calibrate your camera systems before specific assessments to ensure stable and reliable operation. Acknowledgments The research was carried out by the "Precision Bioengineering Research Group", supported by the "Széchenyi István University Foundation". The research was conducted within the framework of the Cooperative Doctoral Program (KDP) Doctoral Student Scholarship. We would like to express our gratitude to the Ministry of Culture and Innovation and the National Research, Development and Innovation Office for their support. References Ambrus B., Teschner G., Kovács A.J., Neményi M., Helyes L., Pék Z., Takács S., Alahmad T., Nyéki A., 2024, Field-grown tomato yield estimation using point cloud segmentation with 3D shaping and RGB pictures from a field robot and digital single lens reflex cameras. Heliyon, DOI: 10.1016/j.heliyon.2024.e37997. Atsuchi H., Ken-Ichiro S., Takaharu K., 2015, Quantitative surface color measurement of tomato fruit using illuminating spectral information of natural lighting. Chemical Engineering Transactions, 44, 163–168, DOI: 10.3303/CET1544028. Gao D., Yi, Fin F., 2013, Computing a complete camera lens distortion model by planar homography. Optics & Laser Technology, 49, 95–107, DOI: 10.1016/j.optlastec.2012.12.004. Li H.Y., Shi Z., Webster R., Triantafilis J., 2008, Mapping the three-dimensional variation of soil salinity in a rice- paddy soil. Geoderma, 195–196, 31–41, DOI: 10.1016/j.geoderma.2012.11.005. Malik M.H., Zhang T., Li H., Zhang M., Shabbir S., Saeed I., 2018, Mature Tomato Fruit Detection Algorithm Based on improved HSV and Watershed Algorithm. IFAC-PapersOnLine, 51, 431–436. Mohamadi H., Alimardani R., Omid M., 2011, Detection of red ripe tomatoes on stem using Image Processing Techniques. Journal of American Science, 7(7): 376-379. Selvaraj A., Shebiah N., Ananthi S., Varthini S.V., 2013, Detection of unhealthy region of plant leaves and classification of plant leaf diseases using texture features. Agricultural Engineering International: The CIGR e-journal ,15(1), 211-217. Souraya B., Bruno B., Jose B., Antonio F., Giuseppe Z., 2017, The assessment of olive ripening using computer vision system. Chemical Engineering Transactions, 58, 355–360, DOI: 10.3303/CET1758060. 834