
Industries that use fruits as raw materials must, at some point in the process, classify them to discard the unsuitable ones and thus ensure the quality of the final product. To produce mango nectar, it is necessary to ensure that the mango is mature enough to start the extraction of the nectar; however, sorting thousands of mangoes may require many people, who can easily lose attention and reduce the accuracy of the result. Such kind of decision can be supported by current Artificial Intelligence techniques. The theoretical details of the processing are presented, as well as the programming code of the neural network using SCILAB as a computer language; the code includes the color extraction from mango images. SCILAB programming is simple, efficient and does not require computers with large processing capacity. The classification was validated with 30 images (TIF format) of Manila variety mango; the mangoes were placed on a blue background to easily separate the background from the object of interest. Four and six mangoes were used to train the neural network. This application of neural networks is part of an undergraduate course on artificial intelligence, which shows the potential of these techniques for solving real and concrete problems.
Citation: Eduardo Castillo-Castaneda. Neural network training in SCILAB for classifying mango (Mangifera indica) according to maturity level using the RGB color model[J]. STEM Education, 2021, 1(3): 186-198. doi: 10.3934/steme.2021014
[1] | Eduardo Castillo-Castaneda . Neural network training in SCILAB for classifying mango (Mangifera indica) according to maturity level using the RGB color model. STEM Education, 2021, 1(3): 186-198. doi: 10.3934/steme.2021014 |
[2] | Lotfi Romdhane, Mohammad A. Jaradat . Interactive MATLAB based project learning in a robotics course: Challenges and achievements. STEM Education, 2021, 1(1): 32-46. doi: 10.3934/steme.2021003 |
[3] | Isidro Max V. Alejandro, Joje Mar P. Sanchez, Gino G. Sumalinog, Janet A. Mananay, Charess E. Goles, Chery B. Fernandez . Pre-service teachers' technology acceptance of artificial intelligence (AI) applications in education. STEM Education, 2024, 4(4): 445-465. doi: 10.3934/steme.2024024 |
[4] | Soheila Garshasbi, Brian Yecies, Jun Shen . Microlearning and computer-supported collaborative learning: An agenda towards a comprehensive online learning system. STEM Education, 2021, 1(4): 225-255. doi: 10.3934/steme.2021016 |
[5] | Elena Guerra . The contribution of critical thinking to STEM disciplines at the time of generative intelligence. STEM Education, 2024, 4(1): 71-81. doi: 10.3934/steme.2024005 |
[6] | Mahmoud Elkhodr, Ergun Gide, Robert Wu, Omar Darwish . ICT students' perceptions towards ChatGPT: An experimental reflective lab analysis. STEM Education, 2023, 3(2): 70-88. doi: 10.3934/steme.2023006 |
[7] | Samah Hatem Almaki, Nofouz Mafarja, Hamama Mubarak Saif Al Mansoori . Teacher well-being and use of artificial intelligence applications and tools: Moderation effects of leadership support in inclusive classroom. STEM Education, 2025, 5(1): 109-129. doi: 10.3934/steme.2025006 |
[8] | Sasha Nikolic, Zach Quince, Anna Lidfors Lindqvist, Peter Neal, Sarah Grundy, May Lim, Faham Tahmasebinia, Shannon Rios, Josh Burridge, Kathy Petkoff, Ashfaque Ahmed Chowdhury, Wendy S.L. Lee, Rita Prestigiacomo, Hamish Fernando, Peter Lok, Mark Symes . Project-work Artificial Intelligence Integration Framework (PAIIF): Developing a CDIO-based framework for educational integration. STEM Education, 2025, 5(2): 310-332. doi: 10.3934/steme.2025016 |
[9] | Falguni P. Desai, Piyush S. Desai, Fatma Sonmez Cakir, Bhavna T. Naik, Riaz A. Tai . Studying the impact of government's employability enhancement drive Finishing School on tribal students of a college in the South Gujarat region in India. STEM Education, 2024, 4(2): 106-126. doi: 10.3934/steme.2024007 |
[10] | Arosh S. Perera Molligoda Arachchige, Kamel Chebaro, Alice J. M. Jelmoni . Advances in large language models: ChatGPT expands the horizons of neuroscience. STEM Education, 2023, 3(4): 263-272. doi: 10.3934/steme.2023016 |
Industries that use fruits as raw materials must, at some point in the process, classify them to discard the unsuitable ones and thus ensure the quality of the final product. To produce mango nectar, it is necessary to ensure that the mango is mature enough to start the extraction of the nectar; however, sorting thousands of mangoes may require many people, who can easily lose attention and reduce the accuracy of the result. Such kind of decision can be supported by current Artificial Intelligence techniques. The theoretical details of the processing are presented, as well as the programming code of the neural network using SCILAB as a computer language; the code includes the color extraction from mango images. SCILAB programming is simple, efficient and does not require computers with large processing capacity. The classification was validated with 30 images (TIF format) of Manila variety mango; the mangoes were placed on a blue background to easily separate the background from the object of interest. Four and six mangoes were used to train the neural network. This application of neural networks is part of an undergraduate course on artificial intelligence, which shows the potential of these techniques for solving real and concrete problems.
For many years, artificial intelligence has been presented as a complex field, understandable only by expert programmers and mathematicians. However, such thinking runs contrary to the basic principle of artificial intelligence: letting computers solve complex problems or repetitive tasks of human beings. The main purpose of the application presented in this paper is to demonstrate that a neural network can be easily developed (theoretically and practically) in a public access programming language such as SCILAB to solve a concrete problem. This application is part of an artificial intelligence course taught to second year students of undergraduate Engineering Systems programs.
Industries that use fruits as raw materials must, at some point in the process, classify them to discard the unsuitable ones and thus ensure the quality of the final product. To extract mango (Mangifera indica) nectar, it is necessary to classify it into three categories: mature, medium, or green. The reason is that only the mature mango (with a suitable level of sugar) can be used for nectar extraction; the green mango is stored for more days and the medium mango is refrigerated and returns to the sorting process two days later [1]. In many nectar factories, the classification is done manually, that is, the mangoes are unloaded from the truck and placed on a conveyor belt where a group of employees separate the mangoes manually, using touch and considering their appearance (particularly the color), see Fig. 1.
Manual classification can be too subjective and therefore unreliable, employees can make mistakes during selection; it is a simple task but requires high levels of concentration over long periods of time. Also, a poor mango classification will reduce the quality of the extracted nectar. Another important situation for the employees, is that repetitive muscle movements can cause tendon inflammation, then injury and disability. Fortunately, automation and artificial intelligence (AI) can provide a solution to this problem and assist people in these types of repetitive tasks.
AI is the ability of computer programs to generate conclusions from the observation of some variables [3], it has been developed under that name since the 70's, its growth is linked to the evolution of computers, their processing and storage capacity. Today, the high performance of computers is used to assist people to perform complex, dangerous, and repetitive tasks, in environments not suitable for human beings. In the 70's, the progress of AI was limited by the low processing and storage capacity of computers, but today, AI applications are multiplying rapidly, and have become accessible to professionals in any field [4]. The computer performs the "observation of variables" through sensors, which have also become accessible due to their low cost. For example, digital cameras, which are photosensitive sensors that convert light into electrical signals, have achieved very high performance at very low cost.
A computer program, which implements an AI application, must include the stages indicated in Fig. 2. To begin, we must define an objective by answering the question: What result do I want to obtain from the program? In addition, we must determine the best set of variables to achieve that goal. Considering the mango classification, the objective is "identify to which of the three categories, green, medium, or mature, a mango belongs". The variables to achieve this objective can be sugar level, smell, texture, or color; in this work we chose the color since it allows to classify mango without contact, assuming a high correlation with the level of maturity [1].
The Fig. 3 shows that there is an evident correlation between color and maturity level of a mango since mature ones turn yellow.
From the objective and the variables, stage 1 is to acquire data (numerical values) of the selected variables, that is, the mango color. In stage 2, a model must be proposed to process the data, that is, a model that correlates the mango color with one of the three categories. In stage 3, the program must generate a forecast based on the data entered and the proposed model, that is, determine the category to which each mango belongs. At the end, in stage 4, the program must compare the result with the true mango category and learn from the error, that is, a person or a system evaluates the result obtained by the program and decides whether the classification is correct or not; the error obtained is combined with new data (to adjust the model) and the process starts again. The most complex stage is to propose a correct model; There are different ways to generate a model in AI, the best known are [5]: Expert Systems, Decision Trees, and Artificial Neural Networks (ANN). In this paper we present a solution based on ANN.
The proposed solution is based on the correlation that exists between the color of a fruit and its level of maturity, which has been widely used in other research works on fruit maturity [6, 7]. In this way, it is possible to identify maturity level of mangoes from their color, without having to measure sugar levels or texture, which are the commonly used off-line methods. Furthermore, to make AI techniques accessible to a greater number of people, we use SCILAB as computer platform to extract color and to program the neural network as well as its training phase.
For humans, identifying a green mango from a yellow (ripe) one is relatively simple since we were trained during childhood. However, humans can make mistakes when colors are similar, for example, to identify different shades of green. In contrast, a computer program can identify colors with extreme precision and repeatability, thousands of times. To achieve this goal, the computer only requires an image of the object acquired through a conventional camera and a computer program for processing.
The type of lighting selected to illuminate the object during image acquisition should not generate glare or shadows since both situations modify the true color of the object [8].
Before extracting the color, the object of interest (mango) must be separated from the background, this process is known as segmentation [9]. This separation is simplified by choosing a uniform background providing enough contrast between background and object. As an example, Fig. 4 shows an image segmentation to separate the airplane from the background (clouds and sky). The interest object appears on white (1 or true) and the rest on black (0 or false).
Color cameras have an array of sensors, each sensor transduces the intensity (amplitude) of three wavelengths that correspond to the colors Red, Green and Blue, known as the RGB (Red, Green, Blue) model. The computer handles each element of the sensor under a digital form (a pixel), which is characterized by the numerical values corresponding to the intensity of each RGB component. Each component can take 256 different values, in the range of [0, 255]. Fig. 5 shows some examples of colors and their corresponding RGB values.
In this way, a computer is capable of handling 256x256x256 different shades of color, that is, 16, 777, 216 different colors in a fast, accurate and repeatable way. In a computer program, a color image is represented by three NxM matrices (one for each RGB component), where N and M are the number of pixels, horizontal and vertical, respectively.
To extract the color from a mango, the SCILAB program starts by reading an image and separating it from the background. The image 'c7-b.tif' is read and assigned to variable a, the original image is shown in Fig. 6a.
The RGB components are then separated and assigned to the variables aR, aG and aB. The blue background corresponds to values greater than 71 for the blue component (aB), this value is assigned to the variable BgV. Values less than BgV for aB component correspond to mango color. With this value, a mask is created (logical variable MaskObj) that will be true (1) when the corresponding pixel is less than BgV or false (0) when it is greater than or equal to BgV, the image corresponding to the mask is shown in the Fig. 6b. This mask is applied to each RGB component to generate a new image, named b, where the background will have been removed (RGB components equal to zero), Fig. 6c shows the object separated from the background.
To extract the color of the object, the averages of the three RGB components (variables AvR, AvG, AvB) are calculated for all the pixels belonging to the object (variable NpixObj), Fig. 6d shows a color rectangle equivalent to the average values of the mango. The Fig. 6e presents the SCILAB code to extract the average color from an image of a mango; the corresponding computation time is 490 ms, under Windows 10, using a desk computer running at 1.6 GHz.
An ANN is a set of artificial neurons based on the mathematical model of the perceptron (artificial neuron) proposed in 1958 by F. Rosenblatt [10]. As Fig. 7 shows, the perceptron is composed of:
●
●1 neuron with an associated activation function named
●
●1 output variable
In this model, the output is given by:
y=ϕ(S) |
where
S=∑ni=1wixi |
The most common form of the activation function is the sigmoid function whose output values are in the range [0, 1]:
ϕ(S)=11+e−S |
In general, the input values must be normalized, within [0, 1] or [-1, 1], to reduce inconsistencies caused by variables with different units. Then, the output variable will also have values within [0, 1]. An ANN is composed of layers, for many applications only three layers are required: an input layer (with
To classify the mango according to color, 3 input variables (each RGB component) and 1 output variable are required. The output will have a value between 0 and 1, where 1 will mean green mango and 0 will mean mature mango. The Fig. 8 shows the three-layer ANN used to solve the mango classification problem using a hidden layer of 3 neurons.
In this case, the weights are represented by two matrices
X1x3=[x1x2x2], |
Y1x1=y1, |
W3x3=[w1,1w1,2w1,3w2,1w2,2w2,3w3,1w3,2w3,3]andV3x1=[v1,1v2,1v3,1] |
In this way, the values of the neurons in the hidden layer are easily calculated by multiplying the vector of input variables
Z1x3=[z1z2z3]=ϕ(X⋅W) |
It should be noted that the weighted sum
Y1x1=y1=ϕ(Z⋅V) |
For example, let us consider the mango of figure 6a, where the average RGB components are (AvR, AvR, AvB) = (207, 158, 5). To normalize the values, they must be divided by 255, which is the greatest value they can take. These normalized values form the vector of input variables of the ANN:
X1x3=[207/255158/2555/255]=[0.81180.61960.0196] |
Furthermore, for a first approximation, the values of the matrices
The result obtained from the previous code is
As shown in the diagram of Fig. 2, the ANN must learn from error, this is known as training, which consists of calculating the best values for the elements of the matrices
The most common algorithm for ANN training is known as backpropagation [11] which consists of calculating the error of the
E=12(Y−Yc)2 |
where
E(W)=12ϕ((Xc⋅W)−Yc)2 |
where
dEdW=(Y−Yc)ϕ'Xc=ADW |
Where
ϕ'=d(11+e−S)dS=ϕ(1−ϕ) |
The previous equation can be separated into two parts, the layer error
EY=(Y−Yc)ϕ'andADW=EY⋅Xc |
Then, for each iteration of the algorithm, the current value of matrix
Wk+1=Wk−ADW, |
where η is named the learning rate, it purpose is to accelerates the search. The current speed of computers allows an ANN to be trained in a matter of seconds, even when thousands of iterations are required to reach error values close to zero.
When the ANN also has a hidden layer, the best value must also be calculated for the matrix of weights
EY=(Y−Yc)ϕ'andEZ=(EY⋅V)ϕ' |
Furthermore, the adjustments for each matrix are given by:
ADW=Xc⋅EZandADV=Z⋅EY |
The SCILAB code corresponding to the ANN training is presented in Fig. 11. For instance, the values of the input and output variables are not yet related to the mango classification, they are shown only as an example. The initial values for the matrices
To validate the SCILAB programs, a database with 30 images of Manila-type mangoes was used. The images are in TIF format and have a size of 1016 x 870 pixels. Using the SCILAB code of Fig. 6e, the averages of the three RGB components for each mango were extracted and stored in an EXCEL file. From these 30 mangoes, 2 mangoes were selected that classified unambiguously (visually) as Green (M1, M2), 2 other mangoes as Mature (M3, M4), see Fig. 12. These mangoes were used to train the ANN.
Using the SCILAB code in Fig. 11, the input variables
As expected, the result of the training are the matrices
To classify the 26 remaining mangoes, the program in Fig. 9 is used, one mango at a time, where the vector of input values
Some mangoes classified as mature look better as medium, and some mediums appear green. To improve the result, two mangoes were included for training. Two mangoes, that classify unambiguously as medium, were chosen; thus, 6 mangoes were used for training, as shown in Fig. 15.
An improved result is shown in Fig. 16. Some mangoes were moved from mature to medium (b3-b, a2-a, a4-a, and b5-a). Red arrows indicate mangoes that changed their classification.
This work presents both, the theoretical details and the programming code using SCILAB, to classify mangoes according with their maturity level using RGC color model. The code includes the color extraction from mango images. SCILAB programming is simple, efficient and does not require computers with large processing capacity. The code extracts the color of the mangoes from images in TIF format; and classifies, through an ANN, each object in the image into mature, medium, or green mango. It seems that the number of mangoes used for ANN training is fundamental to increase the classification performance, but it is also important that the selected mangoes must be representative enough of the three categories. 30 Manila-type mangoes were classified, 6 of them were used for the training; within the ANN, the level of maturity is in the range [0, 1], where 0 corresponds to mature mango, 0.5 to medium mango and 1 to green mango. The method implemented to train the ANN was that of the descent of the gradient, which converges after 20, 000 iterations for this size of ANN (3 layers); the computation time for training is 895 ms, which is very low, even when the code runs on conventional desktop computers. Once the ANN has been trained, the SCILAB code takes 55 ms to run the code that classify one mango. Evidently, the presented code can be used to classify other types of fruits based on their color, a 3-layer ANN, with a hidden layer of 3 neurons is sufficient.
In addition, from the didactic point of view, the students who followed the Artificial Intelligence course using SCILAB as a programming language, were able to apply the same code for other useful solutions with artificial intelligence and satellite images, such as: identifying objects in the sea (boats, whales, islands, ...); identify objects in the sky (planes, birds, clouds, ...); and detecting houses in the desert or in the middle of large rainforests.
[1] | Modeling of color values for nondestructive evaluation of maturity of mango. Journal of Food Engineering (2007) 78: 22-26. |
[2] | In: https://www.magmar.com.mx/, available 4th July 2021. |
[3] | (1995) Artificial Intelligence: A modern Approach. New Jersey, USA: Prentice Hall. |
[4] | Bughin, J., Seong, J., Manyika, J., Chui, M. and Joshi, R., Notes from AI frontier: Modeling the impact of AI on the world economy. Discussion paper, 2018, McKinsey Global Institute. |
[5] | (2015) Artificial Intelligence in the 21st Century. VA, USA: Mercury Learning and Information. |
[6] | Assessment of banana fruit maturity by image processing technique. J Food Sci Technol (2015) 52: 1216-1327. |
[7] | Relación del Color y del Estado de Madurez, con las Propiedades FisicoquȪmica de Frutas Tropicales. Información Tecnológica (2013) 24: 51-56. |
[8] | (1999) The Image Processing Handbook.Prentice Hall. |
[9] | (2002) Digital Image Processing.Prentice Hall. |
[10] | The perceptron: A probabilistic model for information storage and organization in the brain. Psychological Review (1958) 65:. |
[11] | Rojas, R., The Backpropagation Algorithm. Neural Networks, 1996, pp. 149-182. Springer-Verlag. |
[12] | A generalized normalized gradient descent algorithm. IEEE Signal Processing Letters (2004) 11: 115-118. |
1. | Tanveer Aslam, Salman Qadri, Syed Furqan Qadri, Syed Ali Nawaz, Abdul Razzaq, Syeda Shumaila Zarren, Mubashir Ahmad, Muzammil Ur Rehman, Amir Hussain, Israr Hussain, Javeria Jabeen, Adnan Altaf, Machine learning approach for classification of mangifera indica leaves using digital image analysis, 2022, 25, 1094-2912, 1987, 10.1080/10942912.2022.2117822 |