A method for detecting the quality of corn oil based on image processing
By windowing the grayscale image of corn oil surface and adaptive grayscale classification, a grayscale symbiosis matrix is constructed, which solves the problems of time-consuming, labor-intensive and computational intensive traditional detection methods, and achieves efficient and accurate corn oil quality detection.
Patent Information
- Application Number
- CN202510405647.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-04-02
AI Technical Summary
The traditional corn oil quality detection method is time-consuming and labor-intensive, and has strong subjectivity. The existing grayscale symbiosis matrix method has the problem of large amount of calculation or incomplete retention of texture features during calculation.
By dividing the grayscale image of corn oil surface into several windows, adaptive grayscale classification is performed according to the grayscale information and degree of change in the window, a grayscale symbiosis matrix is constructed, the calculation amount is reduced and texture features are retained.
It improves the accuracy and efficiency of corn oil quality detection, reduces the calculation amount, while retaining the texture characteristics of the image, and enhancing the robustness of the detection.
Smart Images

Figure CN119919411B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of image processing, and in particular to a corn oil quality detection method based on image processing. Background Art
[0002] As people pay more and more attention to food safety and quality, the refined quality detection of corn oil products is becoming more and more important. In the current industry situation, traditional corn oil quality detection methods mainly rely on manual visual inspection and chemical analysis, which are time-consuming, labor-intensive, and highly subjective. Therefore, a refined detection method for corn oil based on image processing is needed. The main defects in corn oil are turbidity, milky white, etc., showing obvious texture characteristics.
[0003] A common method for extracting image texture features is the gray level co-occurrence matrix. By calculating the relationship between different gray levels in the image, the texture features of the image can be extracted, thereby analyzing the defective area. The commonly used gray level co-occurrence matrix uniformly uses a gray level of 255, which lacks consideration of the defects and normal area features in the image. Too high a gray level will result in more computing time in the image texture calculation process. If a lower gray level is used directly, it is easy to cause the texture characteristics of the image to be not fully expressed, reducing the robustness of the algorithm. Summary of the invention
[0004] In order to solve the above problems, the present invention provides a corn oil quality detection method based on image processing, the method comprising:
[0005] Acquire a grayscale image of the surface of corn oil, and divide the grayscale image of the surface of corn oil into a plurality of windows;
[0006] The grayscale change degree in the window is obtained according to the grayscale information in the window and the grayscale value discreteness;
[0007] The fineness of the grayscale division in the window is obtained according to the grayscale range of the grayscale in the window and the number of pixels contained in the grayscale; the threshold of the fineness of the grayscale division in the window is obtained according to the grayscale change degree in the window and the difference between the maximum grayscale value and the minimum grayscale value in the window; the original grayscale in the window is obtained; the original grayscale in the window is initially divided into grayscales according to the fineness of the grayscale division in the window and the threshold of the fineness of the grayscale division in the window, and the grayscale after the initial division in the window and the fineness of the grayscale division after the initial division in the window are obtained; the preferred degree of the grayscale division of the window after the initial grayscale division is obtained according to the fineness of the grayscale division after the initial division in the window; the grayscale after the initial division in the window is divided twice according to the preferred degree of the grayscale division of the window after the initial grayscale division, and the optimal grayscale division result of the window is obtained;
[0008] Obtain the gray-level co-occurrence matrix of the window according to the optimal gray-level division result of the window; obtain the energy of the gray-level co-occurrence matrix of the window according to the gray-level co-occurrence matrix of the window; obtain the number of defective windows in the gray-scale image of the corn oil surface according to the energy of the gray-level co-occurrence matrix of the window, and complete the quality inspection of the corn oil according to the number of defective windows in the gray-scale image of the corn oil surface.
[0009] Preferably, the obtaining of the gray-level change degree within the window according to the gray-level information within the window and the degree of gray-value dispersion includes the following specific steps:
[0010] Multiply the coefficient of variation of the gray values in the th window by the information entropy of the gray values in the th window, and denote it as the first product; input the reciprocal of the square value of the preset parameter into the logarithmic function with base 2 to obtain the output value, and denote it as the first output value; denote the negative of the product between the first output value and the square value of the preset parameter as the first negative number; use the ratio of the first product to the first negative number as the gray-level change degree within the th window.
[0011] Preferably, the obtaining of the fineness of the gray-level division within the window according to the gray-level range of the gray levels within the window and the number of pixel points included in the gray levels includes the following specific steps:
[0012] Add 1 to the number of gray values of the th gray level within the window, and denote it as the first sum value; use the reciprocal of the product between the first sum value and the number of gray values of the th gray level within the window as the fineness of the th gray-level division within the window.
[0013] Preferably, the obtaining of the threshold of the fineness of the gray-level division of the window according to the gray-level change degree within the window and the difference between the maximum gray value and the minimum gray value within the window includes the following specific steps:
[0014] Denote the difference between the maximum gray value and the minimum gray value in the th window as the first difference; use the product of the gray-level change degree in the th window and the first difference as the threshold of the fineness of the gray-level division of the th window.
[0015] Preferably, the initial gray-level division of the original gray levels within the window according to the fineness of the gray-level division within the window and the threshold of the fineness of the gray-level division of the window to obtain the gray levels after the initial division within the window and the fineness of the gray-level division after the initial division within the window includes the following specific steps:
[0016] For the windows, arrange all the gray values of the th window in ascending order to obtain the gray value sequence of the th window; First, divide the minimum gray value of the th window into a gray level, denoted as the first gray level. Secondly, according to the gray value order in the gray value sequence of the th window, divide the gray values into the first gray level in turn. After each division, calculate the fineness of the first gray level division of the th window. If, after the jth gray value in the gray value sequence of the th window is divided into the first gray level, the fineness of the first gray level division is greater than or equal to the fineness threshold of the gray level division of the th window, continue the division; If, after the jth gray value in the gray value sequence of the th window is divided into the first gray level, the fineness of the first gray level division is less than the fineness threshold of the gray level division of the th window, stop the division, remove the jth gray value from the first gray level, and record the first gray level as a complete gray level; Finally, use the removed gray value as a new gray level and continue to repeat the operation of gray level division, thereby completing the initial gray level division of the original gray levels within the th window, and obtain all the initial divided gray levels and the fineness of all the initial divided gray level divisions within the th window.
[0017] Preferably, the method for obtaining the preferred degree of the window gray level division after the initial gray level division according to the fineness of the window gray level division after the initial division includes the following specific steps:
[0018] Subtract the fineness of the th gray level division within the th window after the initial gray level division from the fineness threshold of the gray level division of the th window after the initial gray level division, and denote it as the initial difference of the th gray level division within the th window after the initial gray level division; Take the inverse normalization value of the sum of the initial differences of all gray level divisions within the th window after the initial gray level division as the preferred degree of the gray level division of the th window after the initial gray level division.
[0019] Preferably, the method for performing a secondary division on the gray levels after the initial division within the window according to the preferred degree of the window gray level division after the initial gray level division to obtain the optimal gray level division result of the window includes the following specific steps:
[0020] After the initial gray level is divided, any gray level in the th window is recorded as the target gray level. The rightmost edge gray value in the target gray level is obtained and added to the initial gray level before the adjacent right gray level of the target gray level. The preference degree of the gray level division in the th window is recorded as the preference degree of the gray level division before addition; the rightmost edge gray value in the target gray level is obtained and added to the initial gray level after the adjacent right gray level of the target gray level. The preference degree of the gray level division in the th window is recorded as the preference degree of the gray level division after addition; if the preference degree of the gray level division after addition is greater than the preference degree of the gray level division before addition, the rightmost edge gray value in the target gray level is added to the adjacent right gray level of the target gray level; if the preference degree of the gray level division after addition is less than or equal to the preference degree of the gray level division before addition, the original division result is maintained; similarly, after the initial gray level division is completed, all the initial divided gray levels in the th window are subjected to secondary gray level division to obtain the optimal gray level division result of the th window.
[0021] Preferably, obtaining the gray level co-occurrence matrix of the window according to the optimal gray level division result of the window includes the following specific steps:
[0022] Calculating the gray level co-occurrence matrix of the corn oil surface gray image according to the optimal gray level division results of all windows divided by the corn oil surface gray image: First, initialize the gray level co-occurrence matrix, record each gray level and the range of gray values included in its gray level in the first row and the first column of the horizontal gray level co-occurrence matrix respectively, and then set the initial values of other positions in the matrix to zero;
[0023] Secondly, calculate the gray level co-occurrence matrix according to the gray value of the pixel points in the corn oil surface gray image. Traverse the gray values in the window of the corn oil surface gray image. If the gray value belongs to the th gray level of the gray level division in the window, and the gray value of the first pixel point adjacent to its right belongs to the th gray level of the gray level division, then add 1 to the count of the th row and the th column in the horizontal gray level co-occurrence matrix; traverse all pixel points in the window to obtain the gray level co-occurrence matrix of the window.
[0024] Preferably, obtaining the number of defective windows of the corn oil surface gray image according to the energy of the gray level co-occurrence matrix of the window, and completing the quality inspection of the corn oil according to the number of defective windows of the corn oil surface gray image includes the following specific steps:
[0025] Preset two threshold parameters , according to the gray-level co-occurrence matrix of each window of the corn oil surface grayscale image, extract the energy of the gray-level co-occurrence matrix of each window; set the energy of the gray-level co-occurrence matrix less than the threshold The window is recorded as a defect window, and the number of defect windows is counted. If the number of defect windows is greater than or equal to the preset threshold parameter , the quality of the corn oil is unqualified, otherwise, the quality of the corn oil is qualified.
[0026] Preferably, the The method for obtaining the gray value variation coefficient within a window is as follows:
[0027] The first The ratio between the standard deviation and the mean of the grayscale values in the first window is taken as The coefficient of variation of grayscale values within a window.
[0028] The technical solution of the present invention has the beneficial effect that, in view of the problem of excessive calculation amount caused by too much grayscale division in the process of monitoring corn oil product quality using grayscale co-occurrence matrix, the present invention analyzes the degree of local grayscale change of the image, performs fine grayscale division on the corn oil defect area with drastic local grayscale change, re-divides the original grayscale into grayscale with adaptive segment number, reduces the calculation amount of grayscale co-occurrence matrix, and retains the texture characteristics of pixels. On the basis of ensuring the accuracy of corn oil product quality detection, the calculation amount is reduced and the detection efficiency is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0030] Figure 1 The present invention is a flowchart of the steps of a corn oil quality detection method based on image processing. DETAILED DESCRIPTION
[0031] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of a corn oil quality detection method based on image processing proposed by the present invention, its specific implementation, structure, features and effects, in conjunction with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0032] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the technical field to which this invention belongs.
[0033] The following specifically describes the specific solution of a method for detecting the quality of corn oil based on image processing provided by the present invention in conjunction with the accompanying drawings.
[0034] Please refer to Figure 1 , which shows a flowchart of the steps of a method for detecting the quality of corn oil based on image processing provided by an embodiment of the present invention. The method includes the following steps:
[0035] Step S001: Obtain the grayscale image of the corn oil surface and divide the grayscale image of the corn oil surface into several windows.
[0036] Specifically, collect the image of the corn oil surface, grayscale it to obtain the grayscale image of the corn oil surface. Perform preprocessing on the grayscale image of the corn oil surface, including noise removal and other processing, so as to remove noise interference, facilitate subsequent improvement of the contrast of the grayscale image of the corn oil surface, and make the surface information of the corn oil appear more obvious. Among them, in this embodiment, the median filter method is used to remove noise for subsequent analysis and processing of the grayscale image of the corn oil surface. Among them, the median filter is a well-known technology and will not be elaborated here.
[0037] Due to the existence of turbidity defects inside the corn oil, the diffusion inside the corn oil is slower, and stronger texture characteristics will be shown in the grayscale image of the corn oil surface. The gray-level co-occurrence matrix is a commonly used method for extracting image texture features. The traditional gray-level co-occurrence matrix is directly calculated according to 255 gray levels, and finer image texture features can be obtained. However, the overall gray range of the corn oil image is small, and there are many regions that are not of interest. Directly using 255 gray levels will cause a waste of a large amount of calculation time and increase the calculation amount in the subsequent defect extraction process. And if a smaller gray level is used rashly to calculate the gray-level co-occurrence matrix, a large amount of texture characteristics in the regions of interest in the image will be lost, reducing the robustness of the algorithm. Therefore, windowing processing is performed on the grayscale image of the corn oil surface. By calculating the complexity of the gray values within the window, the gray level of the window with a higher complexity is set more finely, and then the final division of the gray level is obtained according to the probability distribution of the gray values in the image. While reducing the subsequent calculation amount, the texture characteristics in the grayscale image of the corn oil surface are retained.
[0038] Preset a parameter , where this embodiment is described by taking as an example. This embodiment is not specifically limited, and depends on the specific implementation situation.
[0039] To better obtain the local information of the grayscale image of the corn oil surface, the grayscale image of the corn oil surface is divided into several windows; in this embodiment, the window of the preset size is set to , which can be adjusted by the implementer according to the actual situation and will not be limited here. The window starts sliding from the upper left corner of the grayscale image of the corn oil surface until it stops at the lower right corner of the grayscale image of the corn oil surface, and the sliding step size is w. Among them, the size of the window should be combined with the size of the grayscale image of the corn oil surface so that the windows in the grayscale image of the corn oil surface are integer numbers, and the window can completely divide the grayscale image of the corn oil surface. For special cases where the boundary pixel points in the grayscale image of the corn oil surface cannot form a window, the window of the boundary pixel points is superimposed with other windows.
[0040] So far, all the windows divided from the grayscale image of the corn oil surface are obtained.
[0041] Step S002: Obtain the degree of grayscale change within the window according to the grayscale information and the degree of grayscale value dispersion within the window.
[0042] It should be noted that the degree of change of the grayscale value within the window can be obtained according to the degree of grayscale dispersion within the window. Directly calculating the coefficient of variation of the grayscale value of the window can represent the degree of grayscale dispersion within the window. Then calculate the information entropy of the grayscale value within the window, and the information entropy can represent the amount of information contained in the grayscale value within the window. According to the information entropy and the degree of grayscale value dispersion within the window, obtain the degree of grayscale change within each window, and according to the degree of grayscale change, windows with a large amount of information and a relatively dispersed grayscale value distribution can be obtained.
[0043] Specifically, the specific method for obtaining the degree of grayscale change within the -th window is as follows:
[0044] Take the ratio between the standard deviation and the average value of the grayscale values within the -th window as the coefficient of variation of the grayscale values within the -th window;
[0045] Multiply the coefficient of variation of the grayscale values within the -th window by the information entropy of the grayscale values within the -th window, and denote it as the first product; input the reciprocal of the square value of the preset parameter into the logarithmic function with base 2 to obtain the output value, denoted as the first output value; denote the negative product of the first output value and the square value of the preset parameter as the first negative number; take the ratio of the first product to the first negative number as the degree of grayscale change within the -th window;
[0046] The specific formula is:
[0047]
[0048] In the formula, represents the degree of gray-scale change within the th window; represents the coefficient of variation of the gray-scale values within the th window, characterizing the degree of dispersion of the gray-scale values in the th window; represents the information entropy of the gray-scale values within the th window, characterizing the gray-scale information of the th window; is a preset parameter.
[0049] Among them, the information entropy of the gray-scale values within the th window has the following calculation expression:
[0050]
[0051] In the formula, represents the information entropy of the gray-scale values within the th window; represents the occurrence frequency of the gray-scale value within the th window.
[0052] Among them, the coefficient of variation of the gray-scale values within the window and the information entropy of the gray-scale values within the window are well-known prior arts and will not be elaborated here.
[0053] Step S003: Adaptive partitioning of the gray levels within the window according to the degree of gray-scale change within the window and the probability distribution of the gray-scale values.
[0054] It should be noted that in this embodiment, the gray-scale value and the gray level are not the same. They are two concepts, and please pay attention to the distinction. The gray-scale value is the original division standard of the image with a value range of 255, and the gray level is the gray-scale grading in the gray-level co-occurrence matrix formed by combining some of the 255 gray-scale values to calculate the gray-level co-occurrence matrix. One gray level may include one or more gray-scale values, and in this embodiment, the gray level is of variable length.
[0055] It should be noted that, according to the degree of gray-scale change within the window, a window with a large degree of gray-scale discreteness and a large amount of information can be obtained. For such windows, the gray levels should be divided more finely to better retain the texture features in these windows, while the gray level division of windows with a lower degree of gray-scale change can be relatively rough. In addition, since the distribution of gray values in each window of the gray-scale image on the surface of corn oil may not be uniform, the dynamic division of gray levels is used to determine variable-length gray levels, reducing the computational amount of subsequent calculations without affecting the calculation results; for a window with a determined number of pixel points, the fineness of gray level division is mainly reflected by the gray-scale range of the divided gray levels and the number of pixel points included in each gray level.
[0056] Specifically, for any window, the fineness of the -th gray level division within the window and the -th gray-scale range and the -th specific method for the number of pixel points included in the gray level is as follows:
[0057] Denote the sum of the number of gray values of the -th gray level within the window and 1 as the first sum value; take the reciprocal of the product between the first sum value and the number of gray values of the -th gray level within the window as the fineness of the -th gray level division within the window;
[0058] The specific formula is:
[0059]
[0060] In the formula, represents the fineness of the -th gray level division within the window; represents the number of gray values of the -th gray level within the window; represents the number of pixel points whose gray values within the window belong to the -th gray level.
[0061] Among them, for any gray level division within the window, the finer the division, the smaller the gray-scale range of this gray level within the window and the fewer the number of pixel points included in the gray level; conversely, the coarser the division of this gray level, the larger the gray-scale range of this gray level within the window and the more the number of pixel points included in the gray level.
[0062] It should be noted that when dynamically dividing the gray levels within any window, the threshold of the fineness of gray level division can be set according to the degree of gray-scale change within the window to dynamically determine the appropriate size of the gray level.
[0063] Specifically, for the The specific method for the threshold of the fineness of gray-level division of a window is as follows:
[0064] The difference between the maximum gray value and the minimum gray value within the window is denoted as the first difference; the product of the degree of gray-level change within the window and the first difference is used as the threshold for the fineness of gray-level division of the
[0065] window.
[0066]
[0067] In the formula, represents the threshold for the fineness of gray-level division of the window; represents the degree of gray-level change within the window; represents the difference between the maximum gray value and the minimum gray value within the window.
[0068] Among them, the threshold for the fineness of gray-level division defines the division level of the gray level. When the fineness of any gray-level division in the window is greater than the threshold for the fineness of gray-level division, it indicates that the division of this gray level meets the fineness requirement. Furthermore, the original gray levels within the window are initially divided according to the obtained threshold for the fineness of gray-level division of the window.
[0069] For the window, the specific operation for initially dividing the original gray levels within this window is as follows:
[0070] Arrange all the gray values of the window in ascending order to obtain the gray-value sequence of the window; First, divide the minimum gray value of the window into a gray level, denoted as the first gray level. Secondly, sequentially divide the gray values into the first gray level according to the order of the gray values in the gray-value sequence of the window, and after each division, calculate the fineness of the division of the first gray level of the window. If the fineness of the division of the first gray level is greater than or equal to the threshold for the fineness of gray-level division of the window after the j-th gray value in the gray-value sequence of the window is divided into the first gray level, continue the division; if the fineness of the division of the first gray level is less than the threshold for the fineness of gray-level division of the window after the j-th gray value in the gray-value sequence of the If the threshold of the fineness of the gray-level division of a window is reached, stop the division, remove the j-th gray value from the first gray level, and record the first gray level as a complete gray level; finally, use the removed gray value as a new gray level and continue to repeat the operation of gray-level division, thereby completing the initial gray-level division of the original gray levels within the -th window, and obtaining all the gray levels after the initial division and the fineness of all the gray-level divisions after the initial division within the -th window.
[0071] The fineness of the gray-level division obtained through the above operations is generally greater than the fineness threshold, which can ensure that the gray-level co-occurrence matrix corresponding to this gray level can retain better texture features.
[0072] It should be noted that there may be deviations in the division of the gray values at the adjacent positions of a certain two gray levels in the initial gray-level division of the original gray levels within the window. Therefore, it is necessary to traverse the gray levels after the initial division again for adjustment.
[0073] Specifically, for the -th window after the initial gray-level division, the specific operation of the secondary gray-level division of the gray levels after the initial division within this window is as follows:
[0074] First, the specific method for obtaining the preference degree of the gray-level division of this window according to the fineness of the gray-level division of each gray level in this window is as follows:
[0075] Take the difference between the fineness of the -th gray-level division within the -th window after the initial gray-level division and the fineness threshold of the gray-level division of the -th window after the initial gray-level division, and denote it as the initial difference of the -th gray-level division within the -th window after the initial gray-level division; take the inverse proportional normalization value of the sum of the initial differences of all the gray-level divisions within the -th window after the initial gray-level division as the preference degree of the gray-level division of the -th window after the initial gray-level division;
[0076] The specific formula is:
[0077]
[0078] In the formula, represents the preference degree of the gray-level division of the -th window after the initial gray-level division; represents the -th gray-level division within the The fineness of the gray-level division; Indicates the threshold of the fineness of the gray-level division of the th window after the initial gray-level division; Indicates the number of gray levels within the window after the initial gray-level division; Indicates the exponential function with the natural constant as the base.
[0079] Secondly, denote any gray level in the th window after the initial gray-level division as the target gray level, obtain the rightmost edge gray value in the target gray level and add it to the fineness of the gray-level division of the th window before the adjacent right gray level of the target gray level, and denote it as the fineness of the gray-level division before addition; obtain the rightmost edge gray value in the target gray level and add it to the fineness of the gray-level division of the th window after the adjacent right gray level of the target gray level, and denote it as the fineness of the gray-level division after addition; if the fineness of the gray-level division after addition is greater than the fineness of the gray-level division before addition, then add the rightmost edge gray value in the target gray level to the adjacent right gray level of the target gray level; if the fineness of the gray-level division after addition is less than or equal to the fineness of the gray-level division before addition, then keep the original division result; similarly, complete the secondary gray-level division of all the initially divided gray levels within the th window to obtain the optimal gray-level division result of the th window.
[0080] Similarly, obtain the optimal gray-level division results of all the windows in the gray-scale image division of the corn oil surface.
[0081] Step S004: Obtain the gray-level co-occurrence matrix of the window according to the adaptively divided gray levels within the window, and evaluate the quality of the corn oil based on the gray-level co-occurrence matrices of each window.
[0082] Specifically, calculate the gray-level co-occurrence matrix of the corn oil surface gray-scale image according to the optimal gray-level division results of all the windows in the corn oil surface gray-scale image division. First, initialize the gray-level co-occurrence matrix, record each gray level and the range of gray values it contains in the first row and the first column of the horizontal gray-level co-occurrence matrix respectively, and then set the initial values of other positions in the matrix to zero.
[0083] Secondly, calculate the gray-level co-occurrence matrix according to the gray values of the pixel points in the corn oil surface gray-scale image. Traverse the gray values within the window of the corn oil surface gray-scale image. If the gray value belongs to the th gray level of the gray-level division within the window, and the gray value of the first adjacent pixel point on its right belongs to the gray-level division of the gray levels, then increment the count of the element in the horizontal gray-level co-occurrence matrix at the th row and the th column by one. Traverse all the pixel points in the window to obtain the gray-level co-occurrence matrix of the window.
[0084] It should be noted that the energy of the gray-level co-occurrence matrix of the window is a measure of the stability of the gray-scale change of the window texture, reflecting the evenness of the gray-scale distribution and the fineness of the texture of the window. The smaller the energy value, the more likely it indicates that the current window texture is a texture with a large degree of variation and is more likely to belong to the defective area of the gray-scale image of the corn oil surface.
[0085] Preset two threshold parameters . In this embodiment, is taken as an example for description. This embodiment is not specifically limited, and is determined according to the specific implementation situation.
[0086] Specifically, according to the gray-level co-occurrence matrices of each window in the gray-scale image of the corn oil surface, extract the energy of the gray-level co-occurrence matrix of each window; mark the window with the energy of the gray-level co-occurrence matrix less than the threshold as a defective window, count the number of defective windows. If the number of defective windows is greater than or equal to the preset threshold parameter , then the quality of the corn oil is unqualified; otherwise, the quality of the corn oil is qualified.
[0087] The above are only the preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.
Claims
1. A method for detecting the quality of corn oil based on image processing, characterized in that, The method includes the following steps: Obtain the grayscale image of the corn oil surface and divide the grayscale image of the corn oil surface into several windows; Obtain the degree of grayscale change within the window based on the grayscale information and the degree of grayscale value dispersion within the window; Obtain the fineness of the grayscale level division within the window based on the grayscale range of the grayscale level within the window and the number of pixel points included in the grayscale level; obtain the threshold for the fineness of the grayscale level division of the window based on the degree of grayscale change within the window and the difference between the maximum grayscale value and the minimum grayscale value within the window; obtain the original grayscale level within the window; perform an initial grayscale level division on the original grayscale level within the window according to the fineness of the grayscale level division within the window and the threshold for the fineness of the grayscale level division of the window to obtain the grayscale level after the initial division within the window and the fineness of the grayscale level division after the initial division within the window; obtain the preference degree of the grayscale level division of the window after the initial grayscale level division according to the fineness of the grayscale level division after the initial division within the window; perform a secondary division on the grayscale level after the initial division within the window according to the preference degree of the grayscale level division of the window after the initial grayscale level division to obtain the optimal grayscale level division result of the window; Obtain the gray-level co-occurrence matrix of the window according to the optimal grayscale level division result of the window; obtain the energy of the gray-level co-occurrence matrix of the window according to the gray-level co-occurrence matrix of the window; obtain the number of defective windows in the grayscale image of the corn oil surface according to the energy of the gray-level co-occurrence matrix of the window, and complete the quality inspection of the corn oil according to the number of defective windows in the grayscale image of the corn oil surface; The obtaining the preference degree of the grayscale level division of the window after the initial grayscale level division according to the fineness of the grayscale level division after the initial division within the window includes the following specific steps: After the initial gray level division, the th window, the th gray level division fineness and the difference between the fineness threshold of the gray level division of the th window after the initial gray level division are recorded as the initial difference of the th window and the th gray level division; the inverse normalization value of the sum of the initial differences of all gray level divisions in the th window after the initial gray level division is used as the preference degree of the gray level division of the th window after the initial gray level division; The performing a secondary division on the grayscale level after the initial division within the window according to the preference degree of the grayscale level division of the window after the initial grayscale level division to obtain the optimal grayscale level division result of the window includes the following specific steps: After the initial gray level is divided, the gray level of any one of the windows is recorded as the target gray level. Obtain the rightmost edge gray value in the target gray level and add it to the initial gray level before the gray level of the window adjacent to the right of the target gray level. Record the preference degree of the gray level division of the window as the preference degree of the gray level division before adding; Obtain the rightmost edge gray value in the target gray level and add it to the initial gray level after the gray level of the window adjacent to the right of the target gray level. Record the preference degree of the gray level division of the window as the preference degree of the gray level division after adding; If the preference degree of the gray level division after adding is greater than the preference degree of the gray level division before adding, then add the rightmost edge gray value in the target gray level to the gray level adjacent to the right of the target gray level; If the preference degree of the gray level division after adding is less than or equal to the preference degree of the gray level division before adding, then keep the original division result; Similarly, after the initial gray level is divided, perform secondary gray level division on all the gray levels after the initial division within the window to obtain the optimal gray level division result of the window.
2. The method for detecting the quality of corn oil based on image processing according to claim 1, wherein, The obtaining the degree of grayscale change within the window based on the grayscale information and the degree of grayscale value dispersion within the window includes the following specific steps: Multiply the coefficient of variation of the gray-scale values within the th window by the information entropy of the gray-scale values within the th window, and denote the result as the first product; input the reciprocal of the square value of the preset parameter into the logarithmic function with base 2 to obtain the output value, and denote it as the first output value; Denote the negative value of the product between the first output value and the square value of the preset parameter as the first negative number; use the ratio of the first product to the first negative number as the degree of gray-scale change within the 3. The method for detecting the quality of corn oil based on image processing according to claim 1, characterized in that, The obtaining the fineness of the grayscale level division within the window based on the grayscale range of the grayscale level within the window and the number of pixel points included in the grayscale level includes the following specific steps: Denote the sum of the number of gray values at the -th gray level within the window and 1 as the first sum value; take the reciprocal of the product between the first sum value and the number of gray values at the -th gray level within the window as the fineness of the division at the -th gray level within the window.
4. The method for detecting the quality of corn oil based on image processing according to claim 1, wherein, The obtaining the threshold for the fineness of the grayscale level division of the window based on the degree of grayscale change within the window and the difference between the maximum grayscale value and the minimum grayscale value within the window includes the following specific steps: The difference between the maximum gray value and the minimum gray value within the th window is denoted as the first difference; the product of the degree of gray change within the th window and the first difference is used as the threshold for the fineness of gray level division of the th window.
5. The method for detecting the quality of corn oil based on image processing according to claim 1, wherein, The performing an initial grayscale level division on the original grayscale level within the window according to the fineness of the grayscale level division within the window and the threshold for the fineness of the grayscale level division of the window to obtain the grayscale level after the initial division within the window and the fineness of the grayscale level division after the initial division within the window includes the following specific steps: For the th window, arrange all the gray values of the th window in ascending order to obtain the gray value sequence of the th window; First, divide the minimum gray value of the th window into a gray level, denoted as the first gray level. Secondly, according to the gray value order in the gray value sequence of the th window, divide the gray values into the first gray level in turn. After each division, calculate the fineness of the first gray level division of the th window. If after the jth gray value in the gray value sequence of the th window is divided into the first gray level, the fineness of the first gray level division is greater than or equal to the gray level division fineness threshold of the th window, then continue the division; If after the jth gray value in the gray value sequence of the th window is divided into the first gray level, the fineness of the first gray level division is less than the gray level division fineness threshold of the th window, then stop the division, remove the jth gray value from the first gray level, and record the first gray level as a complete gray level; Finally, use the removed gray value as a new gray level and continue to repeat the operation of gray level division, thereby completing the initial gray level division of the original gray levels within the th window, and obtaining all the gray levels after the initial division and the fineness of all the gray level divisions after the initial division within the th window.
6. The method for detecting the quality of corn oil based on image processing according to claim 1, wherein The obtaining the gray-level co-occurrence matrix of the window according to the optimal grayscale level division result of the window includes the following specific steps: Calculate the gray-level co-occurrence matrix of the grayscale image of the corn oil surface according to the optimal grayscale level division results of all the windows divided from the grayscale image of the corn oil surface: First, initialize the gray-level co-occurrence matrix, record each grayscale level and the range of grayscale values included in its grayscale level in the first row and the first column of the horizontal gray-level co-occurrence matrix respectively, and then set the initial values of other positions in the matrix to zero; Secondly, calculate the gray-level co-occurrence matrix according to the gray values of the pixel points in the gray-scale image of the corn oil surface. Traverse the gray values in the window of the gray-scale image of the corn oil surface. If the gray value belongs to the th gray level divided by the gray levels in the window, and the gray value of the first adjacent pixel point on its right belongs to the th gray level divided by the gray levels, then increment the count of the th row and the th column in the horizontal gray-level co-occurrence matrix by one; Traverse all the pixel points of the window to obtain the gray-level co-occurrence matrix of the window.
7. The method for detecting the quality of corn oil based on image processing according to claim 1, wherein, Obtain the number of defective windows in the gray-scale image of the corn oil surface according to the energy of the gray-level co-occurrence matrix of the window, and complete the quality inspection of the corn oil according to the number of defective windows in the gray-scale image of the corn oil surface. The specific steps are as follows: Preset two threshold parameters , according to the gray-level co-occurrence matrix of each window of the gray-scale image on the surface of corn oil, extract the energy of the gray-level co-occurrence matrix of each window; mark the window with the energy of the gray-level co-occurrence matrix less than the threshold as a defective window, count the number of defective windows. If the number of defective windows is greater than or equal to the preset threshold parameter , then the quality of the corn oil is unqualified; otherwise, the quality of the corn oil is qualified.
8. The method for detecting the quality of corn oil based on image processing according to claim 2, wherein The method for obtaining the coefficient of variation of the gray value within the th window is as follows: Take the ratio between the standard deviation and the average of the gray values within the th window as the coefficient of variation of the gray values within the th window.
Citation Information
Patent Citations
Electric spindle fault diagnosis method and device based on deconvolution imaging
CN112966560A
Detection method and detection equipment for building external wall thermal insulation material
CN114882038A