An Adaptive Method for Inspecting Illumination of Color Intensity in Transparent Polyethylene Terephthalate Preforms

Machine vision systems are applied in industry to control the quality of production while optimizing efficiency. A machine vision and AI-based inspection of color intensity in transparent Polyethylene Terephthalate (PET) preforms is especially sensitive to backgrounds and lighting, therefore, much attention is given to its illumination conditions. The paper examines the adverse factors affecting the quality of image recognition and presents an adaptive method for reducing the influence of changing illumination conditions in the color inspection process of transparent PET preforms. The method is based on predicting measured color intensity correction parameters according to illumination conditions. To test this adaptive method, a hardware and software system for image capture and processing was developed. This system is capable of inspecting large quantities of preforms in real time using a neural network with a modified gradient descent and momentum algorithm. The experiment showed that correction of the measured color intensity value reduced the standard deviation caused by variable and uneven illumination by 61.51%, demonstrating that machine vision color intensity evaluation is a robust and adaptive solution under illuminated conditions for detecting abnormalities in machine-based PET inspection procedures.


I. INTRODUCTION
The world's tech industry is rapidly changing to Industry 4.0 and fostering a ''smart production'' initiative aimed at production quality and cost improvements. Major industrial companies are adopting new AI systems to gain an Industry 4.0 advantage. In this paper, the authors propose a machine vision technique for improving Polyethylene Terephthalate (PET) preform production. Machine vision is a combination of software and hardware that provides operational control in devices for executing functions such as image capture and processing and measurement of critical attributes. In these systems, resolution and sensitivity are the two most important parameters. Resolution is responsible for differentiating between objects, whereas sensitivity is the system's ability to detect an object despite dim light.
The associate editor coordinating the review of this manuscript and approving it for publication was Xi Peng . The increasing demand worldwide for standardized inspection of quality in production and automation for different industrial applications is likely to drive the machine vision industry forward. The technology has seen extensive development and innovations since it emerged. The surge in demand for application-oriented machine vision systems is also boosting the adoption of new technologies. In the production of PET for plastic bottles, color stability is very important and dependent on the dosing of paint during the manufacturing process and the use of automated defect inspection algorithms [1]- [6]. Visual inspection for color defects in transparent objects such as PET preforms is especially sensitive to illumination; therefore, the lighting system should be precisely designed for the object being inspected. Background and illumination conditions for machine vision in order to enhance image quality, simplify object classification, and improve the visual perception of computer systems have been examined in [3], [7]- [12]. However, the large volumes VOLUME 8, 2020 This work is licensed under a Creative Commons Attribution 4.0 License. For more information, see https://creativecommons.org/licenses/by/4.0/ of PET preform mass production require quick and robust visual data analysis methods to adequately assess production quality. Achieving high accuracy in color inspection under variable illumination conditions is difficult. This is especially important when the color variation range of production is extremely limited. In this research, the authors introduce an adaptive method for reducing the effect of variable lighting conditions during the color inspection process of transparent PET preforms. The method is based on predicting measured color intensity parameters that can be used to correct the luminance intensity and unevenness of the imaging scene.

II. RELATED WORKS
Automated inspection based on machine vision has been successfully applied to detect surface defects in electronic device packages [13] and plastic products [14], problematic printing processes [10], color defects in fruit skins [15], and to classify plastic in recycling processes [16], [17], etc. Most of these systems inspect objects that are stage positioned and require mechatronic equipment to capture image orientation. Substantial progress has been made over the past several years; for example, Chen et al. [18] developed a machine vision system for inspecting red indicia rice kernels for broken kernels, chalkiness, spots and other damage. In their research, near infrared images of colored rice samples were collected using the system and a supporting vector machine (SVM) classifier, with input from the invariant moment ellipse major axis, to identify broken rice kernels in the images. The system proved its efficiency, achieving at least 99.3% recognition accuracy for broken kernels, chalkiness, spots and other damage. Similarly, Kumar and Kumar [19] investigated the application potential of a machine vision system to capture and store the images of a 3D printed workpiece under different colors of incident light. The researchers studied the effects of the color of light on the surface roughness of the workpiece using a stylustype instrument to detail the image texture features of the workpiece, such as correlation, contrast, energy, homogeneity and entropy, and used an artificial neural network (ANN) to predict surface roughness. Asaei et al. [20] analyzed a problem causing pesticide sprayed along orchard rows to be wasted due to the use of conventional, continuous spraying mechanisms and control systems. A site-specific orchard sprayer was developed using machine vision technology to optimize the process and improve chemical application efficiency at the orchard. The initial results suggested that discrete-targeted spraying resulted in 54% less chemical consumption than with conventional, continuous spraying techniques. Louw and Droomer [21] devised a low-cost machine vision quality control system for a Learning Factory. Jibin and Arunachalam [22] investigated the effects of variable illumination on the accuracy and robustness of an inspection method for evaluating ground surface roughness with a machine vision system. Further applications of machine vision systems include research by Wang et al. [23]. The authors analyzed product inspection methods that use machine vision to improve product quality and reduce labor costs. The methods employed advancements in deep learning techniques and advanced analytical tools with greater robustness to identify and classify defective products without loss of accuracy using system identification modules based on a convolutional neural network (CNN). Massinaei et al. [24] investigated the potential of machine vision in monitoring and controlling flotation circuits. The authors developed a machine vision system for a coal column flotation circuit and demonstrated its use at an industrial site with flotation experiments conducted under various operating conditions. The results indicated that the system could be successfully used for diagnosing process conditions and predicting process performance under different operations in a harsh industrial environment. Finally, Gongal et al. [25] analyzed the problem of estimating tree fruit crop size and crop-load during selective robotic harvesting. The authors proposed and developed a machine vision system to detect fruit and pinpoint its position. The proposed machine vision system consisted of a color CCD camera and a time-of-flight (TOF) light-based 3D camera for estimating apple size in tree canopies. The results demonstrated great potential using a 3D machine vision system to estimate fruit size in an outdoor environment. The system achieved an accuracy of up to 70%. Using a machine vision system, Fernández-Robles et al. [26] analyzed automated identification of broken inserts in edge profile milling heads. Jahedsaravani et al. [27] developed a machine vision system for real-time monitoring and control of batch flotation processes. The proposed control system consisted of two in-series models that linked process variables to froth and metallurgical parameters and a stabilizing fuzzy controller. Momin et al. [28] developed a novel proof of concept to detect Materials Other than Grain (MOGs) in soybean harvesting. An HSI (hue, saturation and intensity) color model was used to segment the image background, and subsequently, dockage fractions could be detected using median blurring, morphological operators, watershed transformation, and component labelling based on projected area and circularity. Baigvand et al. [29] studied a grading system based on machine vision for grading figs. The system used a machine algorithm and hardware comprising a feeder, belt conveyor, CCD camera, lighting system, and separation unit. Images of the fig samples were captured using the machine vision system. A grading algorithm was also coded in Lab-VIEW for sorting figs according to their quality indices extracted by the image processing algorithm. Pacella et al. [30] analyzed automated cutting processes and quality control using machine vision technology, proposing non-parametric methods for statistical monitoring of free-form profiles characterized, for example, by irregular shapes or different argument variables. A computer-based machine vision system used for process control. Hong et al. [31] described a machine vision system developed for visually assessing the quality of aquatic products. A machine vision system was used to measure size, shape, and color. The authors proposed an improved camera with illumination settings.

III. GRADIENT DESCENT THEORY FOR OPTIMIZING ANN
Many authors around the world have examined the application of neural networks. The adoption of smart systems is a casual business for most industries, nevertheless, each case study provides unique findings for examination. In recent years, scientists have advanced in providing industry with new algorithms and methods for optimizing the production of different items related to evaluating the light spectrum. These methods rely mostly on general neural network architectures but provide specific corrections for parameters. In the present paper, the authors explore the application of a gradient descent algorithm. Gradient descent (GS) is one of the most popular optimization algorithms and by far the most common method used to optimize a neural network. Each state-ofthe-art case study contains implementations of different algorithms for optimizing gradient descent. These algorithms, however, are often used as black-box optimizers, as practical explanations of their strengths and weaknesses are hard to come by in the general literature.
Gradient descent is a method used to minimize an objective function J (θ) parameterized by a model's parameters θ ∈ R d by updating the parameters in the opposite direction of the gradient of the objective function ∇ θ J (θ) to the parameters. The learning rate η determines the size of the steps taken to reach a minimum. Three variations of the GD algorithm exist. They differ in how much data is used to compute the gradient of the objective function. Each case study compromises between the accuracy of the parameter update and the time required to perform an update. It depends on the amount of data used during computation. Batch gradient descent (BGD), computes the gradient of the cost function to the parameters θ for the entire training dataset, given by (1): For a pre-defined number of epochs, the gradient vector of the loss function for the entire dataset is first computed. Parameters are then updated in the direction of the gradients, and a new learning rate based on the size of the update is determined. Batch gradient descent will converge to the global minimum for convex error surfaces and to a local minimum for non-convex surfaces. Batch GD can be very slow and is intractable for datasets that are too big and do not fit into memory. In this case, the gradients for the entire dataset need to be calculated in order to perform just one update. It is therefore generally omitted in industry since technological processes tend to produce huge amounts of information from sensors and other input sources and due to its incompatibility with online updating. Stochastic gradient descent (SGD), however, applies a parameter update rule for each training example x (i) and label y (i) , given by (2): SGD eliminates redundancy by performing each update consecutively for each case. It is much faster and can also be used to learn online with cloud systems and high-tech industrial processes. Nevertheless, SGD performs frequent updates with high variance, usually causing the objective function to fluctuate heavily, and as a result, either loses the optimal value or enables it to jump to a new and potentially better local minima. This makes convergence more difficult to reach the exact minimum, and SGD will keep missing the right value. However, some research findings indicate that when the learning rate is slowly decreased, SGD shows the same convergence dependencies as BGD, converging to a local or even global minimum. The final mini-batch gradient descent algorithm develops a synergy between BGD and SGD and performs an update for each mini-batch of n training examples, given by (3): The variance of the parameter updates is thus reduced and leads to better convergence. Most common mini-batch sizes range between 50 and 256 but may vary between different industrial applications.
In the literature, mini-batch gradient descent algorithms are used to train neural networks and are also frequently referred to as SGD. Using the momentum algorithm [32], this version of mini-batch SGD was therefore applied often in the present research. Momentum helps accelerate SGD in the relevant direction and dampens oscillations. It does this by adding a fraction µ of the update vector of the past time step to the current update vector. Momentum is essentially a small change in the SGD parameter update so that movement through the parameter space is averaged over multiple time steps. This is done by introducing a velocity component v t . Momentum speeds up movement along the directions of strong improvement (loss decrease) and also helps the network avoid local minima (4): where µ is the air resistance coefficient less than 1. At each time step, the velocity is updated according to the local gradient and then applied to the parameters. The momentum increases for dimensions whose gradients point in the same direction and reduces the updates for dimensions whose gradients change direction. As a result, faster convergence and reduced oscillation is achieved. Many research studies direct the reader to the practical efficiency of the SGD method when using momentum. This method allows a network to respond not only to the local gradient but also to recent trends in the surface error, thereby preventing it from being trapped in local minima.

IV. COLOR INTENSITY INSPECTION ANALYSIS OF PET PREFORMS
PET preforms produced at the factory move freely through an angled scanning image device while a color camera captures images at 15 FPS. Each video frame is then processed according to the following steps: • RGB image converted to grayscale; VOLUME 8, 2020 • Images of PET preforms extracted from the background; • Average luminance of PET preforms calculated; • Calculated values checked to determine whether they satisfied the tolerance range. Figure 1 illustrates the Flow Scheme of the full analysis of PET preforms using the described method.
Dome lights were used in combination with an LED panel at the bottom, which functioned as a backlight by removing shadows from transparent object areas (Fig. 2). Figure 2 (top) illustrates how a large number of inspected objects covering the backlight diminishes the amount of light detected by the camera, and vice versa, a single object against the backlight (bottom) permits additional reflections from the dome, focusing a greater amount of light at the center of the scene. As a result, significant differences in brightness can be observed between image frames with only one PET preform and those with many PET preforms.
To convert an RGB color image into grayscale, a linear approximation of luminance is applied [33]. In this case, the image matrix I carries the information of the relative light intensity at each pixel, which corresponds to the real color intensity, and is calculated using (5): where R, G and B are the light intensity matrices of the red, green and blue channels, respectively, of an RGB color image matrix, with assumed pixel values between 0 and 1.
In the second step, Otsu's thresholding is applied. This is based on automated calculation of the threshold value from the bimodal image histogram, and using this threshold value, an image mask is created that classifies pixel values into background and object areas. By applying this mask, the color intensity C of PET preforms can be obtained by calculating the mean value of the pixel light intensity. The calculated value is then checked whether it falls within a defined tolerance range, and consequently the quality of the product color intensity can be considered either proper or defective. This method's advantage is in allowing large quantities of PET preforms to be checked quickly without the use of any additional mechatronic positioning system. However, fluctuations in the measured value may occur due to illumination noise, even without changing the color of the preforms. Illumination conditions are a key factor in processing images of clear objects [5], [7], [9]. In such cases, dome lights can be used to eliminate any non-uniform lighting effects [34]. However, this lighting solution is quite problematic in detecting very small deviations in color intensity since it is highly dependent on the number of objects against the recognition scene. Such variation in image brightness creates noise in evaluating the color intensity of PET preforms. FIGURE 4 shows that the densities of pixel values illustrating the continuous real color intensity of preforms vary widely between images.
The center of first density peak of (pixel value < 0.4) represents the relative color light intensity value of the PET preforms, while the second peak (pixel value > 0.7) represents the relative color light intensity value of the image background. No linear relationship exists between the background and the object's luminance intensity values, although the luminance intensity variation of an image depends on the scene's area. Another closely related problem is uneven scene lighting, which results from the fluctuating reflections on the dome's surface. When no object is in the scene and the backlight is open, the luminance intensity in the dome's lighting system increases. The backlight reflected on the dome concentrates light towards the center of the scene, and the edges of the scene appear darker.  When many objects are present in the scene, the background becomes much more even. As a result, different color measurements are obtained whether an object is placed at the edge or the center of a scene. This difference in measured color also decreases as the area covered by objects increases.
It is assumed that the variation in measured color depends on the mean luminance intensity value of the image background, the position of the inspected object in the scene, the scattering of inspected objects in the scene, the area covered by objects in the scene, and the area of the image background.
• ϕ 6 -pixel count of preform images; • ϕ 7 -pixel count of image background. These features define the overall amount of light in the dome lighting system, the position and variation of preforms in the scene, and how much of the scene is covered with preforms.

V. ADAPTIVE METHOD FOR CORRECTING MEASURED COLOR INTENSITY VALUES
To reduce variation in the measured color intensity of PET preforms, the authors of the present research propose a new adaptive method based on a corrective function G(· ) which returns a correction coefficient for the measured color intensity value. The function takes the previously defined arguments ϕ 1 , . . . , ϕ 7 and calculates the corrected measured color intensity valueĈ according to (6): where C is the measured color intensity value. The y=G(·) function is approximated using a supervised learning-based feed forward neural network. Combining many simple nonlinear transfer functions enables extremely non-linear functions to be approximated [35]. These functions contain seven nodes in the input layer with corresponding illumination features , one output node in the output layer, which represents the predicted correction coefficient of the measured color intensity, and one hidden layer. In this case, the mathematical model of artificial neural network's i-th node in a hidden layer is defined as (7): where W j is the neural network weights matrix for function f , and f(·) is a hyperbolic tangent sigmoid transfer function. Then, (7) can be defined as (8): The neural network's output with n nodes in a hidden layer is defined as (9): where F(·) represents a linear output function matrix. The present study used an improved neural network that contained only one hidden layer and used only hyperbolic tangent sigmoid and linear transfer functions (f, F) in the common form of (10): The weights (specified by the vector θ i and alternatively by the matrices w and W ) are the adjustable network parameters and are determined through network training. The objective of training is then to determine the mapping from the training data set Z to the set of possible weights θ (11): The network will produce predictionsŷ i , which in some sense are close to the true outputs y i . The prediction error method, which is the strategy applied here, is based on the introduction of a measure of closeness in terms of a mean square error criterion (12): The weights for predictions are (13): By an iterative minimization scheme (14): Here, θ i specifies the current iterate (number 'i'), f ji is the search direction, and ? i is the step size. The network was trained with SGD with momentum and evaluated for minimization of the mean-square error criteria because of its rapid convergence properties and robustness. Some improvements were made to the method. The size of the elements of the diagonal matrix added to the Gauss-Newton Hessian was adjusted according to the size of the ratio between actual decrease and predicted decrease (15) and (16).
Here, B denotes the gradient of the criterion with respect to the weights, and R is the Gauss-Newton approximation to the Hessian. The following algorithm was used: • Select an initial parameter vector θ 0 and an initial value δ 0 ; • Determine the search direction from [R (θ i + δ i · I )] · f ji = −G (θ i ), I being a unit matrix; • r i > 0.75 → δ i = δ i 2 (If the predicted decrease is close to the actual decrease, let the search direction approach the Gauss-Newton search direction while increasing step size); • r i < 0.25 → δ i = 2 · δ i (If the predicted decrease is far from the actual decrease, let the search direction approach the gradient direction while decreasing step size); • If the stopping criterion is not satisfied, go to 2). The weights are the network's adjustable parameters and are determined through network training. The training data is the set of inputs ϕ i , and the corresponding desired outputs are y i . The training set is given by (17): The objective of training, therefore, is to determine the mapping from the training data set to the set of possible weights. Many methods can be used to select the number of nodes in a hidden layer [29], but no general rule exists that would meet every case of neural network design. Therefore, initially, a neural network model with five neurons in a hidden layer was designed. Each time after applying a five-fold cross validation and calculation mean square error (MSE) of neural network prediction, one node is added to the hidden layer. This process is repeated until MSE starts increasing. Figure 8 shows that the lowest MSE value was achieved when a neural network with 12 nodes in a hidden layer was trained. This neural network configuration was therefore used for further experiments. The boxes represent start and final values.

VI. EXPERIMENTAL EVALUATION AND RESULTS
The experiment was performed on image capturing and processing hardware developed for this research (Fig. 9).
The hardware system consisted of a color camera IDS ui-5260cp-c-hq and dome lighting system mounted on a PET   preform production conveyor line. Captured images were transferred to a computer with software installed for saving and processing captured images, calculating color intensity values, and registering defects (Fig. 10).
The software was used during the PET preform production process to capture and save color inspection images with a constant color intensity. In total, 360 records of images  were obtained for neural network training. For each image, the actual color intensity was assigned to a data set according to the inspected preforms. The values of feature vector for each image were then calculated. To train the neural network using a supervised learning method, the target values were assigned to an appropriate feature vector.
The target values were calculated for each image by dividing the actual color intensity with the mean value of the measured preform color intensity. A sample was created from a total of 360 records, which were split into training sets (60%), validation (20%), and ANT test (20%). The neural network was trained using MATLAB software. After training the neural network, a correlation between the target values and neural network outputs was observed. Figures 11 and 12 indicate a very strong correlation (overall correlation coefficient R = 0.93239), suggesting that the approximation of the correction function f (·) was accurate.
After function approximation, in order to test the effect of measured color intensity, a value correction (2) equation was applied. The variability of measured and corrected color intensity values (red and blue lines, respectively) can be observed for a constant actual color intensity value (0.33) (Fig. 13).
The standard deviation and mean squared error (MSE) were evaluated for both cases ( Table 1).
The proposed correction method reduced the standard deviation and mean squared error of the measured value by 61.51% and 83.81%, respectively. This suggests that the proposed color intensity evaluation method adapts to the  illumination conditions and is more robust than the standard medium color intensity estimation method. It is a very important finding, because the tolerance range in color intensity evaluation can be significantly reduced, which leads to more precise color inspections.

VII. CONCLUSION
Variable and uneven illumination of a scene in machine vision has an adverse effect on inspecting color intensity defects by reducing the visual perception capabilities of the computer system. An adaptive method that mitigates the effect of variable illumination conditions during the color inspection process of transparent PET preforms was proposed.
The method involved predicting the measured color intensity correction parameter according to the illumination conditions using an artificial neural network. The results showed that correcting the measured color intensity value reduced the standard deviation and mean squared error caused by variable and uneven illumination by 61.51% and 83.81%, respectively. Color intensity evaluation based on machine vision proved more robust and adaptive to illumination conditions than the standard medium color intensity estimation method and led to significant improvements in the accuracy of detecting color defects in the manufacturing process.
The ever-increasing need for superior inspection procedures and increasing automation in mass production are key factors paving the way for full-scale adoption of machine vision technology at a higher level. The need for increased quality control by consumers and manufacturers coupled with constantly changing government regulations to follow prescribed specifications is also expected to increase the adoption of machine vision technology in different markets and areas of application outside mass production.
Future research will include the application of other relevant machine learning techniques, including Structured AutoEncoders [36], [37], transfer hashing with privileged information [38] and other computational methods for more efficient machine vision systems. He is currently working as a Researcher and Associate Professor at the Klaipėda University Marine Research Institute and Informatics, and the Statistics Department, Klaipėda University. His Ph.D. thesis explored intelligent control systems. His research interests include machine learning algorithms, industry 4.0, artificial intelligence, data mining, and affective computing, especially on the application of artificial intelligence in optimizing technological processes.

MINDAUGAS KURMIS was born in Lithuania.
He received the bachelor's degree in informatics engineering and the master's degree from the Faculty of Marine Technologies, Klaipėda University, in 2009 and 2011, respectively, and the Ph.D. degree in informatics engineering from Vilnius University, in 2016.
He is currently working as an Associate Professor and the Head of the Informatics and Statistics Department, Klaipėda University. His research interests are networking technologies, telecommunication systems, and data mining, especially on the quality of communications, network security, wireless networks, and vehicle communications systems. He is the author or coauthor of more than 20 articles.

ZYDRUNAS LUKOSIUS was born in Lithuania.
He received the bachelor's degree in biophysics from the Faculty of Health Sciences, Klaipėda University, in 2009, and the master's degree in informatics engineering from Klaipėda University, in 2011. He is currently pursuing the Ph.D. degree with the Institute of Biomedical Sciences, Vilnius University.
He is also working as a Researcher and a Lecturer at the Marine Research Institute, Klaipėda University. His research interests include digital signal processing and intelligent and biomedical systems, especially on the efficiency of signal filtering and bio-physical systems. He is currently working as a Researcher at the Marine Research Institute, Klaipėda University, and a Senior Researcher at the IT4Innovations National Supercomputing Center, VSB-Ostrava Technical University. He is a member of several editorial boards and reviewer of the highly ranked CA and SCOPUS journals (Soft Computing and the IEEE TRANSACTIONS ON NEURAL NETWORKS AND LEARNING SYSTEMS). His research interests are intelligent systems, AI, statistical data analysis, operations research, and big data analytics. He is the author or coauthor of more than 50 articles, including SCOPUS and CA. He was appointed as a Full Professor in Electronics and Communications Technologies, in 2017. His research interests generally focus on information and communication technologies, especially on quality of service and experience, network security, wireless networks, and big data analytics. He is the author or coauthor of more than 100 articles in SCI/SCIE journals. He has served as a member of editorial boards for several journals, including Sensors, the Journal of Communications, Elektronika Ir Elektrotechnika, and Advances in Electrical and Electronic Engineering.