DOI: 10.3303/CET24113001 Paper Received: 9 June 2024; Revised: 12 August 2024; Accepted: 16 October 2024 Please cite this article as: Garcillanosa M.M., Cumpas H.I.L., Racelis J.M., Tolentino A.P.A., 2024, Color-based Detection and Classification of the Quality of Lactuca Sativa L. on Vertical Indoor Farming Using Artificial Neural Network for Image Processing, Chemical Engineering Transactions, 113, 1-6 DOI:10.3303/CET24113001 CHEMICAL ENGINEERING TRANSACTIONS VOL. 113, 2024 A publication of The Italian Association of Chemical Engineering Online at www.cetjournal.it Guest Editors: Jeng Shiun Lim, Bohong Wang, Guo Ren Mong, Petar S. Varbanov Copyright © 2024, AIDIC Servizi S.r.l. ISBN 979-12-81206-14-4; ISSN 2283-9216 Color-based Detection and Classification of the Quality of Lactuca Sativa L. on Vertical Indoor Farming Using Artificial Neural Network for Image Processing Mae M. Garcillanosa*, Hannah Isabel L. Cumpas, Jayrendex M. Racelis, Arvin Peter A. Tolentino Mapúa Malayan Colleges Laguna, Electronics Engineering, Cabuyao, Laguna, Philippines mmgarcillanosa@mcl.edu.ph With the increase in urbanization, environmental pollution has increased and has taken a toll on the quality of Lactuca Sactiva L. or lettuce produced in the country. Vertical indoor farming (VIF) is one of the viable solutions in this problem. However, the crops indoor should have enough nutrients and proper lighting as they would receive outdoors to achieve optimal growth. This research aims to develop an algorithm that would detect and classify the quality of Lactuca Sactiva L. in a vertical indoor farm based on its color property. It was done by first collecting the images of the crop every 30 min the whole planting cycle of the lettuce in the VIF. The images that were gathered were classified manually into two categories: healthy and unhealthy and was eventually used as a training data sets. The second phase was the application and validation of the generated model in the VIF for another planting cycle which got an accuracy of 88 %. The final stage was to implement the validated model in another planting cycle which resulted to an accuracy of 96 %. The overall system was then implemented in the three-layer VIF as the trigger to the LED lights. When the system sees “healthy” -the LED is turned off, when it sees “unhealthy” -the LED is turned on and is set to the minimum required hours of exposure. The implementation of this system to the VIF is one of the factors that contributed to the optimal growth of Lactuca Sactiva L. which further resulted in a greener leaves and reduced harvest time. 1. Introduction The Philippines is an agricultural country with a land area of 300,000 Mm3, 97,000 Mm3 or 47 % of which are considered agriculture. However, according to Marcos (2023), rapid urbanization and rampant land conversion of prime agricultural lands have significantly reduced the amount of land available for food production which resulted in lower farm output across different commodities. With the increase in urbanization, environmental pollution has also increased and has taken a toll on the quality of Lactuca Sativa L., or lettuce, produced in the country. Vertical Indoor farming (VIF) is one of the solutions in the urbanization and environmental problem here in the Philippines. It is being implemented in some of the urban areas of Singapore (Song et al., 2022), China (Zhou et al., 2022), and Switzerland (Avgoustaki and Xydis, 2020). It has proven its feasibility however, achieving optimal growth in VIF post some challenges. The crops should have enough nutrients and proper lighting as they would receive in the outdoors, as light is a significant factor in the growth of plants for photosynthesis. If not enough lighting is achieved, the quality of the plant is affected and that reflects on the color of the leaves. Traditionally, the health of the crop is monitored manually by the naked eye. However, it requires time and expertise which is a disadvantage for a working professional who does not specialize in the production of Lactuca Sativa L. Therefore, a functional and automatic detection and classification of the quality of lettuce is significant in vertical indoor farming. This research thus aims to develop an algorithm that would detect and classify the quality of Lactuca Sactiva L. in a vertical indoor farm based on its color property. Recent advancements in image processing and artificial intelligence, particularly artificial neural networks (ANNs), have revolutionized agricultural practices by providing robust tools for crop monitoring and quality assessment as seen in the works of plant leaf disease classification 1 (Dubey and Choubey, 2024), indoor vertical farming (Garcillanosa et al., 2023 ) and plant disease identification (Perumal et al., 2024). Color-based detection and classification using ANNs offer a precise and non-invasive method to evaluate the quality of lettuce. This approach leverages the capability of neural networks to analyze complex visual patterns and discern subtle differences in color, which are indicative of various quality parameters such as freshness, ripeness, and the presence of diseases or deficiencies. Research has demonstrated the effectiveness of using ANNs for image processing in agricultural applications. For instance, studies have shown that neural networks can accurately classify plant health status based on color variations in images as reported in the works of Patel (2020), and Sharma and Jain (2019). By integrating these technologies into vertical indoor farming systems, growers can achieve real-time monitoring and make informed decisions to optimize crop production and quality. This integration not only enhances the efficiency of farming operations but also contributes to sustainable agricultural practices by minimizing resource use and reducing waste. 2. Materials and methods This part discusses the following: hardware implementation, image processing, and prototype simulation. 2.1 Hardware Implementation The hardware part includes the installation of an 8-megapixel camera connected to raspberry-pi microcontroller in each layer of the vertical indoor farm rack. Shown in Figure 1, orientation of the camera in each layer of the VIP and the connections and peripherals of the raspberry-pi microcontroller. The camera is positioned at the top-right corner at an angle just enough for the camera to fully capture the three lettuces on a layer. The angle of the camera is fixed and therefore the variations in leaf orientation were not considered. This is however what we will consider in our future work so to address possible incomplete segmentation problems and inaccurate feature extractions. The microcontroller is powered by 5 Vdc, the input is the image captured by the camera, and has three different outputs: white LED (flash for the camera), green LED (healthy lettuce), and the red LED (unhealthy lettuce). The dame VIF rack was used as reported in Garcillanosa et al. (2023). (a) (b) Figure 1: (a) Placement of cameras in the VIF rack, (b) peripherals of the raspberry-pi microcontroller 2.2 Image Processing Pre-processing of the image is a must to prepare the input test image to be classified using machine learning. Python IDLE, an integrated development environment (IDE) for the programming of python, was implemented to generate the code. Figure 2 shows the system architecture for the image processing and the number of training data sets used to be able to generate an acceptable model. (a) (b) Figure 2: (a)System architecture for the image processing, (b) Training data sets used (3480-healthy, 840- unhealthy) 8-MP Camera 2 The captured data by the camera undergo the pre-processing, image segmentation, and feature extraction. The extracted feature is used as a data set in training the model. Specifically, the classification-prediction ANN which is a subset of feed-forward ANN was used in the training. The proponents used 512 hidden layers at a learning rate of 0.90. K-ramdom sampling was also used for the validation due to its versatility especially in the manipulation of the hyperparameters. Initially, a high number of samples and hidden layers were used which resulted in a learning rate of 0.66 only. The model was further optimized by adjusting the number of hidden layers and by adjusting the number of samples to meet the best possible learning rate of 0.90. Once the model is generated, it was loaded as the brain of the microcontroller that autonomously classifies the crop if it’s healthy or not. 2.3 Preprocessing The collected images from the VIF for the whole duration of growing of the lettuce was manually annotated and eventually was subjected to pre-processing, segmentation, and feature extraction. The pre-processing method used in this study is called image color filtering. Color filtering is needed to get the wanted part of the image, in this case, the region of the lettuce. The method will allow to pass the hues of the wanted color (yellow to green). Making a spectral bandpass filter is necessary for this filtering process. Shown in Figure 3a is a bandpass filter plot that allows to pass the yellow (minimum hue: 10) and green wavelengths (maximum hue: 75) on the image. Figure 3b is the sample of an actual pre-processed image using color filtering. This is the result of allowing the frequencies of yellow and green to bypass and eliminating other frequencies from the image. allows to pass the yellow (minimum hue: 10) and green wavelengths (maximum hue: 75) of the image. Figure 3: (a) Spectral bandpass filter for filtering yellow and green on an image, (b) Sample of preprocessed image using color filtering In image segmentation, the filtered image will be converted to a meaningful image that will make it easy to analyze. The technique that we used is Binary Large Object detection (Blob) which proves its effectiveness in the report of Young et al. (2020). This technique has allowed the region of lettuce to be classified and converted from pixels to binary image. This distinguished the highlighted region of the image (lettuce) from the background (soil). Feature extraction is where the analyzation from segmented images happens. The color histogram feature is one effective technique that can be use after blob detection. A histogram is a graphical representation for the pixels of an image. The details of the binary image based on the colors, Red, Blue, and Green (RGB) values, will have a binary pixel as its own definite value. Having the graph would help to classify the lettuce easily. (b) (a) 3 Hue Value H u e A m o u n t (N o rm a liz e d ) H u e A m o u n t (N o rm a liz e d ) H u e A m o u n t (N o rm a liz e d ) Hue Value Based on the histogram and segmented image, the model will predict if the lettuce is healthy or not. This classification is done through a machine learning approach. The model that we used is the Artificial Neural Network (ANN) since according to studies, this model has high accuracy when it comes to detection. In this mathematical model, feeding a training data set is necessary for the machine to learn like a human brain. The output of the processed image served as the input node of the model. It was linked to the process node, also called hidden nodes, as a classifier algorithm on artificial neural network. The hidden nodes have been calibrated for error rate so to give an accurate output. The classifier determines the health status of the lettuce. If green hue has the highest point in every image in comparison to the amount of yellow hue, then we classify it as healthy. But when it says otherwise, then we classify it as unhealthy. See Figure 4 for the difference for each classification. Light emitting diodes (LEDs) are used to indicate the state of the crop, an illuminated green LED implies a healthy lettuce, otherwise a red LED would illuminate. With the help of preliminary data, the model has a validation accuracy of 88 % which is enough for it to use as classification algorithm. (a) (b) Figure 4: Hue amount for (a) Healthy lettuce, (b) Unhealthy lettuce 2.4 Implementation This part has been subdivided into three phases: training, validation, and system evaluation. The parameter to be measured in the overall system is its accuracy. The first phase of the implementation part is gathering training data sets and training the classifier. A camera module in the VIF was used to capture images that would integrate as training data for the classifier. Image acquisition took place every 30 min for the whole plant cycle. The reason behind the time interval is to allow the system to have enough data for learning. The captured images were manually classified and annotated by the researchers into healthy (3,480 images) and unhealthy (840 images) class. The basis of the manual visual inspection and classification was through the guidance of an Agriculturist specializing in the cultivation of lettuce. We are also aware that this can introduce subjectivity and bias, hence, we further validate the data by measuring the hue value as part of the pre-processing technique, this was discussed in Section 2.3. The second phase of implementation is the application and validation of the model. This phase is where the model was implemented completely on the vertical indoor farm for a whole plant cycle, that is why another set of lettuce was planted on the rack for the validation of the data. The efficiency of the image processing methods and the accuracy of the classifier were evaluated, and based on the parameters below, the following were computed: sensitivity of 97 %, specificity of 66 %, and accuracy of 91 %. The last phase was to evaluate the efficiency of the overall system in the VIF. The parameters that were used to determine the efficiency of an algorithm are sensitivity, specificity, and accuracy. These parameters are determined by the values of true positive and false positive. To check the accuracy, sensitivity, and specificity of the image processing technique, the proponents used the Eq(1) to (3): 𝑆𝑒𝑛𝑠𝑖𝑡𝑖𝑣𝑖𝑡𝑦 = 𝑇𝑃 𝑇𝑃+𝐹𝑁 (1) 𝑆𝑝𝑒𝑐𝑖𝑓𝑖𝑐𝑖𝑡𝑦 = 𝑇𝑁 𝑇𝑁+𝐹𝑃 (2) 𝐴𝑐𝑐𝑢𝑟𝑎𝑐𝑦 = 𝑇𝑃+𝑇𝑁 𝑇𝑃+𝐹𝑃+𝑇𝑁+𝐹𝑁 (3) Where TP is True Positive (correctly segmented as foreground), TN is True Negative (correctly detected as background), FP is False Positive (falsely segmented as foreground) and FN is False Negative (falsely detected as background). 0.10 0.08 0.06 0.02 0.00 0.04 0 1000 2000 3000 4000 0.10 0.08 0.06 0.02 0.00 0.04 0 1000 2000 3000 4000 4 The system was installed in each layer of the VIF, for a total of three layers. It was operated autonomously inside the vertical indoor farm rack until the day of harvest. An accuracy of 96 % was measured during the system evaluation. 3. Results and discussions The designed classifier serves as the processing unit that turns on and off the LED system of the VIF. If the system detects that the lettuce is in ‘healthy’ condition, the LED lights will be turned off to maintain its healthy condition. However, if the status of the lettuce that was classified was ‘unhealthy’, the LED lights would turn on with an exposure time set to six hours only. After six hours from the first detection, the system will again check the condition of the lettuce based on its color, and the process will take place all over again -off when healthy, on when not healthy. Implementing this system in the VIF made the harvest time of the lettuce to only 30 d (in the VIF rack) compared to the typical harvest time of 45 d (outdoor farming). The average size of the harvested lettuce is about 5.7 % bigger than the without this model as reported in the previous work of Garcillanosa et al., 2023. The performance of the system was tested and got the accuracy of 96 %, from which 600 data was gathered and 576 of these data were correctly predicted by the machine. Figure 5 shows a sample image that shows (a) healthy and (b) unhealthy. (a) (c) Figure 5: (a) and (b) Healthy lettuce, (c) Unhealthy lettuce To further verify the accuracy of the prediction, the hue values were measured. Figure 6 shows the graphical representation of hue amount versus the hue value of the predicted lettuces. Figure 6: Graphical representation of hue amount versus the hue value during the third phase data collection (b) (d) 5 The data that were considered in the graph was the summary of hue value gathered on each pixel for all input data. Clearly, the graph shows that the hue value was plotted in between 0 to 75, in which theoretically is the hue value of yellow and green. Meaning, the filtering works accordingly and the processing based on color was indeed within the range of yellow and green only. 4. Conclusions In conclusion, the implementation of color-based detection and classification for assessing the quality of Lactuca Sativa L. (lettuce) in vertical indoor farming using artificial neural networks (ANNs) for image processing presents a promising advancement in precision agriculture. This approach leverages the power of ANNs to accurately identify and classify various quality parameters based on color variations, which are indicative of the health and maturity of the lettuce. By utilizing image processing techniques, this method provides a non- invasive, efficient, and scalable solution for real-time monitoring of crop quality. The integration of such technologies in vertical indoor farming can lead to optimized resource usage, enhanced yield quality, and reduced labor costs. Moreover, the automation of quality control processes ensures consistent and reliable product standards, which are critical for meeting market demands and consumer expectations. The research highlights the potential of combining artificial intelligence with precision agriculture to create more sustainable and productive farming practices especially in places where urbanization is pervasive. The classification-prediction ANN validated its advantage in the health classification of the lettuce in a VIF. Furthermore, K-ramdom sampling was also effectively utilized for validation and demonstrated the versatility of this technique in the manipulation of hyperparameters within an ANN-based framework. Future work could expand on this foundation by incorporating additional parameters such as texture and shape analysis, integrating multi-spectral imaging, and refining the neural network models for even higher accuracy. Overall, this study demonstrates that advanced image processing and machine learning techniques are invaluable tools in the pursuit of modernizing agriculture and improving food production systems. References Avgoustaki D. D., Xydis, G., 2020, Indoor vertical farming in the Urban nexus context: Business growth and resource savings. Sustainability (Switzerland), 12(5). Dubey R. K., Choubey, D. K., 2024, An efficient adaptive feature selection with deep learning model-based paddy plant leaf disease classification. Multimedia Tools and Applications, 83(8), 22639–22661. Garcillanosa M. M., Batino Jr. Z. M., Gabuyo E. A., Mojica T. L., Mundo M. A. D., Impelido D. G., Sison, P. A. A, 2023, Efficient and Low-Cost Method of Smart Indoor Vertical Farming for Lactuca sativa L. with Machine Learning. Chemical Engineering Transactions, 106, 535–540. Patel S. et al., 2020, Application of Artificial Neural Networks for Plant Health Monitoring. Journal of Agricultural Science and Technology, 22(3), 645–657. Perumal V.K., Supriyaa T., Santhosh P.R., Dhanasekaran S., 2024, CNN based plant disease identification using PYNQ FPGA’, Systems and Soft Computing, 6, 200088. Senator Imee R. Marcos, 2023, An Act Mandating the Preservation and Protection of Agricultural Lands in the Philippines, and for other Purposes. 19th Congress of the Philippines, accessed 10.06.2024. Sharma R., Jain, A., 2019, Color-based Image Analysis for Quality Assessment of Agricultural Products using Neural Networks. Computers and Electronics in Agriculture, 162, 425–432. Song S., Hou Y., Lim R. B. H., Gaw L. Y. F., Richards D. R., Tan H. T. W., 2022, Comparison of vegetable production, resource-use efficiency and environmental performance of high-technology and conventional farming systems for urban agriculture in the tropical city of Singapore. Science of the Total Environment, 807. Young A., Mahan J., Dodge W., Payton P., 2020, Blob-based AOMs: A method for the extraction of crop data from aerial images of cotton, Agriculture (Switzerland), 10(1). Zhou H., Specht K., Kirby C. K., 2022, Consumers’ and Stakeholders’ Acceptance of Indoor Agritecture in Shanghai (China), Sustainability (Switzerland), 14(5). 6 Color-based Detection and Classification of the Quality of Lactuca Sativa L. on Vertical Indoor Farming Using Artificial Neural Network for Image Processing