A method and device for online detection of edible oil color based on machine learning

Through the online detection method of edible oil color based on machine learning, the problems of manual operation and real-time monitoring of the Lovibond colorimeter were solved, and the automatic detection and remote monitoring of edible oil color were realized, thereby improving the detection efficiency and accuracy.

CN119251160BActive Publication Date: 2025-09-23ZHEJIANG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411286540.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-13
Publication Date
2025-09-23
Estimated Expiration
2044-09-13

AI Technical Summary

Technical Problem

The existing Lovibond colorimeter requires manual operation and cannot achieve real-time monitoring of edible oil color. This results in the inability to provide timely feedback and adjustments during the production process, and places high demands on professional laboratories and testing teams.

Method used

An online detection method for edible oil color based on machine learning is adopted. Through image processing and random forest modeling, automatic detection of edible oil color is achieved. The method includes image collection, edge detection, feature extraction and model construction, and the random forest algorithm is used to predict the red and yellow values.

Benefits of technology

It realizes online real-time monitoring of edible oil color, reduces dependence on professional laboratories and testing teams, improves testing efficiency and accuracy, and supports remote monitoring and data analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119251160B_ABST
    Figure CN119251160B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for online colorimetry of edible oil based on machine learning. The method utilizes a specific light source and a camera device for data acquisition; a Lovibond colorimeter is used to sample edible oil samples to obtain the edible oil colorimetry value corresponding to the acquired image; the original image is processed through image processing and analysis algorithms to remove noise, impurities, and other parts in the image data that may affect the detection results; key features in the image data are obtained through feature extraction; a colorimetry detection model is obtained based on these key features through machine learning algorithm modeling; and online detection of edible oil colorimetry is achieved through the deployment of the model. This method for online colorimetry of edible oil based on machine learning provides an efficient, accurate, and automated solution. Compared with traditional colorimetry detection methods, it can quickly obtain colorimetry information of edible oil samples, effectively improves detection efficiency, is easy to implement and promote, and has high practical application value.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of food analysis and computer vision, and in particular to a method and device for online detection of edible oil chroma based on machine learning. Background Art

[0002] Pure oil is colorless in liquid form and white in solid form. However, oils made from various common oilseeds all have a certain color. This color primarily comes from the oil-soluble pigments contained in the oilseed, including chlorophyll, carotenoids, and gossypol. It is a comprehensive reflection of the various pigments in the oil. Although the current national standard for soybean oil has revised color to a non-quantitative, descriptive sensory measurement item, it remains a key quality indicator for oil production monitoring. Color also serves as a visual basis for consumers when choosing edible oils. Therefore, processing companies need to optimize oil decolorization processes while controlling production to achieve national standards for finished oil color and produce products that satisfy and are recognized by consumers. Therefore, accurate and quantitative color testing is crucial in the daily production monitoring of oils.

[0003] The Lovibond colorimeter has become a widely used instrument for measuring oil color internationally, and is also specified in GB1536-2004, "Rapeseed Oil," and GB / T22460-2008, "Determination of Color of Animal and Vegetable Oils and Fats—Lovibond." Lovibond colorimeter is widely used in edible oil color testing, but accurate results require skilled operators. Over time, the instrument can become inaccurate. Furthermore, it can only operate intermittently, requiring a laboratory to sample and measure edible oils. Each measurement cycle is long, requiring a large number of personnel, and cannot provide real-time monitoring of the production process, hindering timely feedback on production status.

[0004] Therefore, a method for long-term, real-time monitoring of edible oil color is needed to provide feedback on the color value of edible oil, allowing for real-time monitoring of the production process and facilitating dynamic adjustments by manufacturers. This method also reduces the requirements for specialized laboratories and testing teams, providing a new solution for intelligent production workshops. Summary of the Invention

[0005] The present invention aims to address the deficiencies of the existing technology and propose an online detection method and device for edible oil color based on machine learning.

[0006] The object of the present invention is achieved through the following technical solutions: a method for online detection of edible oil color based on machine learning, the method comprising:

[0007] S1. Collect edible oil images of different chromaticities and Lovibond red and yellow value data to obtain edible oil images and corresponding labels;

[0008] S2, denoising and gray-scaling the image, and performing Canny edge detection on the processed image to obtain the edges of impurities in the image;

[0009] S3, after obtaining the impurity edge information, using the dilation operation to expand the edge information, retrieving the outermost contour in the binary image and saving the contour circumscribed rectangle information, and constructing a mask image based on the contour circumscribed rectangle information;

[0010] S4, converting the RGB image into an HSV image, and removing the influence of the noise area according to the mask image;

[0011] S5, performing feature extraction on the HSV image after the mask operation, and performing feature screening on the red value feature and the yellow value feature respectively;

[0012] S6. Using the filtered features, build a red value prediction model and a yellow value prediction model based on random forest modeling, test the accuracy and stability, and obtain the most suitable number of features for the corresponding red value and yellow value prediction models;

[0013] S7. Input the image into the trained red value prediction model and yellow value prediction model to obtain real-time monitoring results.

[0014] Furthermore, the collecting of edible oil images of different chromaticities and Lovibond red and yellow value data specifically includes:

[0015] A yellow surface light source with a wavelength of 570nm to 590nm is used as a stable light source. The cooking oil pipeline is sealed to obtain image data with uniform features under the same light source.

[0016] Furthermore, in the image denoising, a 5*5 convolution kernel is defined as a two-dimensional Gaussian kernel, the Gaussian kernel is convolved with the image, each element of the Gaussian kernel is multiplied by the corresponding image pixel value, and the results are summed; the summed result is divided by the sum of the Gaussian kernel to ensure that the brightness of the image does not change; finally, the result of the convolution operation is assigned to the corresponding pixel position in the original image.

[0017] Furthermore, the Canny edge detection is divided into five steps, namely Gaussian filtering, pixel gradient calculation, non-maximum suppression, hysteresis threshold processing and isolated weak edge suppression;

[0018] The pixel gradient calculation includes: calculating the pixel gradient matrix in the x and y directions:

[0019]

[0020]

[0021] Where I is the grayscale image matrix, G x is the pixel gradient matrix in the x direction, G y is the pixel gradient matrix in the y direction, * represents the cross-correlation operation, and the gradient intensity matrix G of the image xy It can be calculated by the following formula:

[0022]

[0023] The non-maximum pixel gradient suppression is as follows: comparing the gradient strength of the current pixel with the gradient strength of the adjacent pixels along the positive and negative gradient directions; if the gradient strength is an extreme value, the pixel is retained as an edge;

[0024] The threshold hysteresis processing and isolated weak edge suppression are performed by defining a high threshold and a low threshold. Pixels with gradient strength lower than the low threshold are suppressed and not regarded as edge points; pixels with gradient strength higher than the high threshold are defined as strong edges and retained as edge points; pixels between the high and low thresholds are defined as weak edges; by checking the weak edge pixel and its eight neighboring pixels, a judgment is made based on their connection with the strong edge. As long as one of the neighboring pixels is a strong edge pixel, the weak edge can be retained as a strong edge, i.e., a true edge point.

[0025] Furthermore, S3 specifically includes: further expanding edge information through the dilation operation in the morphological operation, so that the unclear and disconnected edges in the original image can be connected as a whole to form a connected domain; for the expanded image, using the findContours algorithm in OpenCV to retrieve the outermost contour in the binary image, and save the endpoint coordinates and length and width information of its circumscribed rectangle.

[0026] By traversing the saved bounding rectangle information, the rectangle is filled with 0 on the mask with a value of 255. After the traversal is completed, all rectangular areas are discarded and do not participate in subsequent feature extraction.

[0027] Furthermore, the feature extraction is: using the open source numpy package to extract features from image statistical data, including the median, mean, standard deviation, maximum value, minimum value, variance and kurtosis of each channel as features of an image data.

[0028] Furthermore, the feature screening is specifically as follows: multiple feature screening methods are selected for joint screening, including correlation analysis through Pearson correlation coefficient, adding variance-based feature selection method to screen out features with small variance changes in the entire data set, and finally adding tree model-based feature selection method to select model nonlinear features.

[0029] Furthermore, the S6 constructs a red value prediction model and a yellow value prediction model based on random forest modeling:

[0030] The final result is obtained by voting through multiple basic weak learners. In the regression problem, the mean value can be selected as the result value. The weak learner is a decision tree model. The decision tree includes: if the training data set is D and the decision tree is f(x), first select the optimal split variable j and split point s, and solve

[0031]

[0032] Traverse the variable j, scan the split point s for the fixed split variable j, and select the pair (j, s) that minimizes the above equation;

[0033] Use the selected pair (j,s) to divide the region and determine the corresponding output value:

[0034]

[0035] Where R1(j,s)={x|x (j) ≤s}, R2(j,s)={x|x (j) >s}.

[0036] Continue to call the above steps for the two sub-regions until the stopping condition is met;

[0037] Divide the input space into M regions R1, R2...R M Generate a decision tree

[0038]

[0039] Where I is the indicator function,

[0040] In the regression problem, when the maximum depth is reached, the data is fitted by linear regression to generate the regression value.

[0041] On the other hand, the present invention provides an online detection device for edible oil color based on machine learning, comprising a memory and one or more processors, wherein the memory stores executable code, and when the processor executes the executable code, it implements the online detection method for edible oil color based on machine learning.

[0042] On the other hand, the present invention provides a computer-readable storage medium having a program stored thereon. When the program is executed by a processor, the online detection method of edible oil color based on machine learning is implemented.

[0043] Beneficial effects of the present invention:

[0044] The present invention establishes a correspondence between the true chromaticity values ​​of image data, utilizes a variety of image processing and analysis algorithms, extracts key features, and uses a random forest algorithm for modeling. This enables online detection of edible oil color, and the detection accuracy will not be reduced due to time factors.

[0045] This invention breaks through the general mechanistic modeling method. It directly starts from the image features of different chromaticities, uses image processing algorithms to process images, selects the main features related to edible oil chromaticity through statistical analysis and correlation analysis, and uses machine learning technology to model multiple features. It realizes automated detection of edible oil chromaticity without human intervention, thereby improving detection efficiency and accuracy.

[0046] By deploying machine learning models and optimizing and improving the model's feedback mechanism during the detection process, the performance and adaptability of colorimetry detection can be enhanced. The performance of algorithms and models can be continuously optimized to achieve online real-time monitoring of edible oil color, ensuring the stability and consistency of product quality.

[0047] The data is transmitted to the factory data platform through the data transmission protocol to realize remote monitoring and data analysis, which can be remotely managed and convenient for users to conduct data statistics and analysis. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 Schematic diagram of the online detection method of edible oil color based on machine learning;

[0049] Figure 2 Schematic diagram of the structure of the online detection device for edible oil color based on machine learning. DETAILED DESCRIPTION

[0050] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0051] Example

[0052] like Figure 1 As shown, the present invention provides an online detection method for edible oil color based on machine learning, specifically:

[0053] During the dataset creation phase, a yellow area light source with a wavelength of 570nm to 590nm was used as a stable light source. The cooking oil pipeline was sealed to ensure that it was illuminated by a single, controllable yellow light source. This area light source ensures that the cooking oil receives uniform light intensity, producing uniform image data for easier processing. Furthermore, the yellow light source mitigates the effects of oversaturated images caused by excessive oil clarity.

[0054] By collecting image data of edible oils with different chromaticity values ​​and data on Lovibond red and yellow values, dense images and corresponding label data are obtained.

[0055] To segment the illuminated portion of the cooking oil from the image data, high-frequency noise must first be removed due to camera sensor characteristics and liquid flow. A Gaussian filter algorithm is used to remove noise from the image. In this algorithm, a Gaussian function is applied to each pixel in the image and a weighted average of its neighboring pixel values ​​is taken. The averaged pixel value is obtained by multiplying each pixel within the window with the Gaussian function curve, summing the resulting products, and dividing the sum by the sum of the products. For the cooking oil image processing, a 5*5 convolution kernel is defined as a two-dimensional Gaussian kernel. The Gaussian kernel is convolved with the image, and each element of the Gaussian kernel is multiplied by the corresponding image pixel value, and the results are summed. The summed result is then divided by the sum of the Gaussian kernel to ensure that the image brightness does not change. Finally, the convolution result is assigned to the corresponding pixel position in the original image.

[0056] Grayscale the Gaussian filtered image to obtain a grayscale image of the liquid. Perform Canny edge detection on this grayscale image. The detection threshold should be based on distinguishing between the cooking oil liquid and impurities such as bubbles. Generally, a low threshold of 30 and a high threshold of 255 are sufficient. The specific thresholds vary depending on light intensity, but the correct threshold range can be determined by analyzing the cooking oil image data. A Sobel operator window size of 3 is sufficient for calculating the image gradient. Canny edge detection is used to detect the edges of impurities such as bubbles in the image.

[0057] Canny edge detection is divided into five steps, namely Gaussian filtering, pixel gradient calculation, non-maximum suppression, hysteresis threshold processing and isolated weak edge suppression. When using pixel gradient calculation, the Sobel operator is used to calculate the gradient. For a 3*3 window, the pixel gradient matrix in the x and y directions is calculated as follows:

[0058]

[0059]

[0060] Where I is the grayscale image matrix, G x is the pixel gradient matrix in the x direction, G y is the pixel gradient matrix in the y direction, * represents the cross-correlation operation, and for the image gradient intensity matrix G xy , which can be calculated by the following formula:

[0061]

[0062] Non-maximum pixel gradient suppression can eliminate the stray responses caused by edge detection and play a role in "slimming down" the edge. Its basic method is to compare the gradient strength of the current pixel with the gradient strength of the adjacent pixels along the positive and negative gradient directions. If the gradient strength is the largest (i.e., the extreme value), the pixel is retained as an edge point. If it is not the maximum, it is suppressed and not considered an edge point.

[0063] Threshold hysteresis processing and isolated weak edge suppression are performed by defining a high threshold and a low threshold. Pixels with gradient strengths below the low threshold are suppressed and not considered edge points; pixels with gradient strengths above the high threshold are defined as strong edges and retained as edge points; pixels between the high and low thresholds are defined as weak edges. By examining the weak edge pixel and its eight neighboring pixels and judging their connection to the strong edge, as long as one of the neighboring pixels is a strong edge pixel, the weak edge can be retained as a strong edge, i.e., a true edge point.

[0064] After obtaining edge information for noise components like bubbles and impurities, the dilation operation within morphological operations further expands this edge information, connecting any unclear and disconnected edges in the original image to form a connected domain. For this dilated image, the findContours algorithm in OpenCV can be used to efficiently retrieve contours from the binary image. Because it's necessary to eliminate areas that may affect detection, such as bubbles and impurities, only the outermost contours need to be retrieved for subsequent processing. Furthermore, when retrieving contours, the endpoint coordinates, length, and width of the bounding rectangle must be saved.

[0065] After obtaining the bounding rectangles of impurities such as bubbles, we create a mask image the same size as the cooking oil image. This is done by filling a white image with values ​​all 255 with rectangles with values ​​0. Specifically, we traverse the saved bounding rectangle information and fill the rectangles with 0s on the mask with values ​​255. After the traversal is complete, all rectangular areas are discarded and do not participate in subsequent feature extraction operations.

[0066] Converting an RGB image to an HSV image yields an HSV image. The RGB model is commonly used as an image model in camera photography. However, the three components in the RGB model are highly correlated, making continuous color transformations unintuitive and limiting in image processing. In contrast, the three components in the HSV model are decoupled: hue represents the color type (e.g., red, green, blue), saturation represents the color's purity, and value represents the color's brightness. This intuitiveness makes HSV images easier to analyze and process. Therefore, converting an RGB image to an HSV image is necessary to obtain an HSV image.

[0067] Based on the assumption that the chromaticity of edible oil is constant within a short period of time during the production process (the time it takes for the camera to capture the image), the assumption that the edible oil is evenly distributed in experiments and actual production, and based on field experimental observations and image analysis, it can be concluded that the color distribution differences in the images are small, the texture features are not obvious, the texture features of different chromaticities are not different, and the texture features are more reflected in the noise level. Therefore, the image data is converted into statistical data for further processing. Specifically, the RGB image data and the HSV image data are masked to remove the influence of the noise area, and then the corresponding 6-dimensional image statistics are obtained.

[0068] Use the open source numpy package to extract features from image statistics, including statistical indicators such as the median, mean, maximum, minimum, and kurtosis of each channel as features of an image data.

[0069] Feature screening. Because an image contains too many statistical features, it is necessary to remove weakly correlated features and select highly correlated features to facilitate model fitting for subsequent feature extraction. In feature screening, multiple feature screening methods are selected for joint screening, and features that show strong correlation across multiple methods are selected as training features for learning.

[0070] The screening of red value features and yellow value features should be performed separately. First, the Pearson correlation coefficient is used for correlation analysis. Its value range is [-1, 1], where -1 indicates a complete negative correlation (when one variable decreases, the other will increase), +1 indicates a complete positive correlation, and 0 indicates no linear correlation. The calculation method is the quotient of the covariance and standard deviation between the two variables. The calculation method for the sample correlation coefficient is:

[0071]

[0072] Where X is the median, mean, standard deviation and other variables of the pixel values ​​of the above channels, and Y is the red value or yellow value. If the correlation coefficient is greater than 0.7 or less than -0.7, it is considered to have a strong correlation. The Pearson correlation coefficient can obtain linearly related features, making the model easy to fit, but it is not good at extracting nonlinear features and ignores the correlation of many nonlinear features. Therefore, a variance-based feature selection method is added to filter out features with small variance changes in the entire data set. Specifically, for feature X in the data set, for feature X j , and its variance calculation formula is:

[0073]

[0074] Where n is the number of samples, X ij is the value of the i-th sample on feature j, is the mean of feature j over all samples. If the variance of a feature is less than 0.8 in the entire dataset, it is filtered out.

[0075] Finally, a tree-based feature selection method is added to select the nonlinear features of the model. The important features of the tree-based feature selection method are more likely to appear in nodes with shallower depths, and the number of times they appear may be greater. By sorting the importance of features through indicators such as the number of feature occurrences, nonlinear features with high correlation can be obtained. In the actual operation process, random forest is selected as the feature filter, and the SelectFromModel function is introduced through the feature_selectio package of sklearn. The original features with low correlation are removed by the variance-based feature selection method, and the importance of each feature can be obtained through the feature_importances_ of the random forest regressor. The mean squared error (MSE) is used as the evaluation criterion, and some features with low correlation can be removed, while having almost no effect on the accuracy of the model. Specifically, in a tree model, when node n is split into left child node n left and right child node n rig ht t When , the new mean square error is

[0076]

[0077]

[0078] The reduction in mean square error before and after splitting is,

[0079]

[0080] For each feature, accumulate the mean squared error reduction for all nodes split using that feature. This can be done by iterating over all trees and all nodes within them. Within each tree, the importance of feature j is the sum of the mean squared error reductions for all nodes split using feature j. The importance of all features is normalized and reversed in the feature_importances_ method. Due to the varying contributions of individual features, some redundant features are retained during feature selection to ensure tree stability. Finally, features with importance below 0.03 are removed before training.

[0081] The data set is divided into training set and test set in the ratio of 8:2. The random forest model is used to train the features. During the training process, grid search is used to select hyperparameters. The model is evaluated using the test set data. The mean square error function is used as the evaluation indicator. The yellow value and red value of the Lovibond chromaticity should be modeled separately, that is, two models are generated. Random forest is a classic bagging model. The final result is obtained by voting through multiple basic weak learners. In regression problems, the mean value can be selected as the result value. Its weak learner is a decision tree model. In the decision tree, each region in the input space where the training data set is located is recursively divided into two sub-regions and the output value of each sub-region is determined. Specifically, if X and Y are the input and output variables respectively, and Y is a continuous variable, given a training data set D = {(x1, y1), (x2, y2),…, (x N ,y n )}, the decision tree is f(x), first select the optimal split variable j and split point s, and solve

[0082]

[0083] Where c1, c1 are the representative values ​​of the two regions after the current region is divided into two regions. Traverse the variable j, scan the split point s for the fixed split variable j, and select the pair (j, s) that makes the above formula reach the minimum value

[0084] Use the selected pair (j,s) to divide the region and determine the corresponding output value:

[0085]

[0086] Where R1(j,s)={x|x (j) ≤s}, R2(j,s)={x|x (j) >s}.

[0087] Continue to call the above steps for the two sub-regions until the stopping condition is met, that is, the depth of the tree meets the maximum depth or the cut sub-set reaches the minimum cut sub-set.

[0088] Divide the input space into M regions R1, R2...R M Generate a decision tree

[0089]

[0090] Where I is the indicator function,

[0091] In the regression problem, when the maximum depth is reached, the data is fitted by linear regression to generate the regression value.

[0092] By performing random forest modeling on different numbers of features, testing the accuracy and stability, the most suitable number of features for the corresponding red value and yellow value prediction models were obtained.

[0093] The above method generates a regression model for red and yellow value detection. By exporting the model and generating a model file, online detection of red and yellow values ​​can be achieved. Regarding data transmission, the Modbus protocol is commonly used for serial communication in industrial production. The red and yellow values ​​obtained from the model feedback can be directly transmitted to the industrial data platform via the Modbus protocol, enabling remote data monitoring and online real-time monitoring.

[0094] After the model has been deployed for a long enough time, the model can be corrected through machine learning algorithms based on actual production data to improve the accuracy of model detection.

[0095] The above description is merely a preferred embodiment of the present invention and does not constitute any form of limitation to the present invention. Although the present invention has been described in detail with reference to the best embodiment, those skilled in the art should understand that the technical solution of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention, and all of these should be covered by the claims of the present invention.

[0096] Corresponding to the aforementioned embodiment of an online detection method for edible oil color based on machine learning, the present invention also provides an embodiment of an online detection device for edible oil color based on machine learning.

[0097] See also Figure 2 An embodiment of the present invention provides an online detection device for edible oil color based on machine learning, including a memory and one or more processors. The memory stores executable code, and when the processor executes the executable code, it is used to implement an online detection method for edible oil color based on machine learning in the above embodiment.

[0098] The embodiment of the online detection device for edible oil color based on machine learning provided by the present invention can be applied to any device with data processing capabilities, and the device with data processing capabilities can be a device or apparatus such as a computer. The device embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of any device with data processing capabilities in which it is located reading the corresponding computer program instructions in the non-volatile memory into the memory for execution. From the hardware level, if Figure 2 As shown in the figure, it is a hardware structure diagram of any device with data processing capability where the online detection device of edible oil color based on machine learning provided by the present invention is located. Figure 2 In addition to the processor, memory, network interface, and non-volatile memory shown, any device with data processing capabilities in which the apparatus in the embodiment is located may also include other hardware, generally based on the actual functions of the device with data processing capabilities, which will not be described in detail.

[0099] The implementation process of the functions and effects of each unit in the above-mentioned device is specifically described in the implementation process of the corresponding steps in the above-mentioned method, and will not be repeated here.

[0100] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present invention. A person of ordinary skill in the art can understand and implement the present invention without inventive work.

[0101] An embodiment of the present invention also provides a computer-readable storage medium having a program stored thereon. When the program is executed by a processor, an online detection method for edible oil color based on machine learning in the above embodiment is implemented.

[0102] The computer-readable storage medium may be an internal storage unit of any device with data processing capabilities described in any of the aforementioned embodiments, such as a hard disk or memory. The computer-readable storage medium may also be an external storage device of any device with data processing capabilities, such as a plug-in hard disk, a smart media card (SMC), an SD card, a flash card, etc. equipped on the device. Furthermore, the computer-readable storage medium may also include both an internal storage unit and an external storage device of any device with data processing capabilities. The computer-readable storage medium is used to store the computer program and other programs and data required by any device with data processing capabilities, and may also be used to temporarily store data that has been output or is to be output.

[0103] The present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements the online detection method for edible oil color based on machine learning.

[0104] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the contents disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present application that follow the general principles of the present application and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered merely as exemplary, and the true scope and spirit of the present application are indicated by the claims.

[0105] It should be understood that the above general description and the detailed description that follows are exemplary and explanatory only and do not limit the present application. The present application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes may be made without departing from the scope of the present application. The scope of the present application is limited only by the appended claims.

Claims

1. A method for online detection of edible oil chromaticity based on machine learning, characterized in that: The method includes: S1. Collect edible oil images of different chromaticities and Lovibond red and yellow value data to obtain edible oil images and corresponding labels; S2, denoising and gray-scaling the image, and performing Canny edge detection on the processed image to obtain the edges of impurities in the image; S3, after obtaining the impurity edge information, using the dilation operation to expand the edge information, retrieving the outermost contour in the binary image and saving the contour circumscribed rectangle information, and constructing a mask image based on the contour circumscribed rectangle information; S4, converting the RGB image into an HSV image, and removing the influence of the noise area according to the mask image; S5, performing feature extraction on the HSV image after the mask operation, and performing feature screening on the red value feature and the yellow value feature respectively; S6. Using the filtered features, build a red value prediction model and a yellow value prediction model based on random forest modeling, test the accuracy and stability, and obtain the most suitable number of features for the corresponding red value and yellow value prediction models; S7. Input the image into the trained red value prediction model and yellow value prediction model to obtain real-time monitoring results.

2. The method for online detection of edible oil chromaticity based on machine learning according to claim 1, wherein: The collecting of edible oil images of different chromaticities and Lovibond red and yellow value data specifically includes: A yellow surface light source with a wavelength of 570nm to 590nm is used as a stable light source. The cooking oil pipeline is sealed to obtain image data with uniform features under the same light source.

3. The method for online detection of edible oil chromaticity based on machine learning according to claim 1, wherein: In the image denoising process, a 5*5 convolution kernel is defined as a two-dimensional Gaussian kernel, the Gaussian kernel is convolved with the image, each element of the Gaussian kernel is multiplied by the corresponding image pixel value, and the results are summed; the summed result is divided by the sum of the Gaussian kernel to ensure that the brightness of the image does not change; finally, the result of the convolution operation is assigned to the corresponding pixel position in the original image.

4. The method for online detection of edible oil chromaticity based on machine learning according to claim 1, wherein: The Canny edge detection is divided into five steps, namely Gaussian filtering, pixel gradient calculation, non-maximum suppression, hysteresis threshold processing and isolated weak edge suppression; The pixel gradient calculation includes: calculating the pixel gradient matrix in the x and y directions: Where I is the grayscale image matrix, G x is the pixel gradient matrix in the x direction, G y is the pixel gradient matrix in the y direction, * represents the cross-correlation operation, and the gradient intensity matrix G of the image xy It can be calculated by the following formula: The non-maximum pixel gradient suppression is as follows: comparing the gradient strength of the current pixel with the gradient strength of the adjacent pixels along the positive and negative gradient directions; if the gradient strength is an extreme value, the pixel is retained as an edge; The threshold hysteresis processing and isolated weak edge suppression are performed by defining a high threshold and a low threshold. Pixels with gradient strength lower than the low threshold are suppressed and not regarded as edge points; pixels with gradient strength higher than the high threshold are defined as strong edges and retained as edge points; pixels between the high and low thresholds are defined as weak edges; by checking the weak edge pixel and its eight neighboring pixels, a judgment is made based on their connection with the strong edge. As long as one of the neighboring pixels is a strong edge pixel, the weak edge is retained as a strong edge, i.e., a true edge point.

5. The method for online detection of edible oil chromaticity based on machine learning according to claim 1, wherein: The step S3 specifically includes: further expanding edge information through a dilation operation in a morphological operation, so that unclear and disconnected edges in the original image are connected as a whole to form a connected domain; for the expanded image, using the findContours algorithm in OpenCV to retrieve the outermost contour in the binary image, and saving the endpoint coordinates and length and width information of its circumscribed rectangle; By traversing the saved bounding rectangle information, the rectangle is filled with 0 on the mask with a value of 255. After the traversal is completed, all rectangular areas are discarded and do not participate in subsequent feature extraction.

6. The method for online detection of edible oil chromaticity based on machine learning according to claim 1, wherein: The feature extraction is: using the open source numpy package to extract features from image statistical data, including the median, mean, standard deviation, maximum value, minimum value, variance and kurtosis of each channel as the features of an image data.

7. The method for online detection of edible oil color based on machine learning according to claim 1, characterized in that: The feature screening specifically includes: selecting multiple feature screening methods for joint screening, including correlation analysis through Pearson correlation coefficient, adding variance-based feature selection method to screen out features with small variance changes in the entire data set; finally, adding a tree model-based feature selection method to select the nonlinear features of the model, and in the tree model-based feature selection method, the mean square error is used as the correlation criterion.

8. The method for online detection of edible oil chromaticity based on machine learning according to claim 1, wherein: The S6 constructs a red value prediction model and a yellow value prediction model based on random forest modeling: The final result is obtained by voting through multiple basic weak learners, and the mean is selected as the result value in the regression problem. The weak learner is a decision tree model; the decision tree includes: if the training data set is D and the decision tree is f(x), first select the optimal split variable j and split point s, and solve Traverse the variable j, scan the split point s for the fixed split variable j, and select the pair (j, s) that minimizes the above equation; Use the selected pair (j,s) to divide the region and determine the corresponding output value: Where R1(j,s)={x|x (j) ≤s}, R2(j,s)={x|x (j) >s}; Continue to divide the two sub-regions until the depth of the tree meets the maximum depth or the sub-set of cuts reaches the minimum sub-set of cuts; Divide the input space into M regions R1, R2...R M Generate a decision tree Where I is the indicator function, In the regression problem, when the maximum depth is reached, the data is fitted by linear regression to generate the regression value.

9. An online edible oil color detection device based on machine learning, comprising a memory and one or more processors, wherein the memory stores executable code, characterized in that: When the processor executes the executable code, an online detection method for edible oil color based on machine learning is implemented as described in any one of claims 1-8.

10. A computer-readable storage medium having a program stored thereon, characterized in that: When the program is executed by a processor, an online detection method for edible oil color based on machine learning is implemented as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Edible oil deterioration level determination device, edible oil deterioration level determination system, edible oil deterioration level determination method, edible oil deterioration level learning device, and learned model for use in edible oil deterioration level determination

    CA3232438A1

  • Printing color quality detecting method of integrating visual measurement, density measurement and color measurement

    CN101518980A