Disclosure of Invention
Aiming at the problems that the image details are lost or distorted, the image noise is amplified and the quality of the enhanced image is reduced in the existing image enhancement method, the compensation factors are introduced to correct the logarithmic function of the MSR algorithm, and the optimal scale parameters are calculated based on the flatness index, so that the self-adaptive weight is determined, the brightness of the image is normalized, the enhanced image is more balanced and natural, and the image quality is improved; aiming at the problems that the traditional optical lens surface defect detection model is excessively focused on local features, so that model training is difficult and convergence time is long, the scheme calculates the score of the defect class, measures the dispersion degree of feature vectors by calculating the square sum of the distances between the features and the centers of the corresponding classes, introduces a weighting coefficient and a constraint factor to define a loss function, and improves the accuracy of defect detection; aiming at the problems that the current model parameter searching algorithm is low in convergence speed and easy to fall into local optimum and low in optimizing accuracy, the method uses a sinusoidal chaotic mapping method to initialize individual positions, introduces a nonlinear convergence factor and a random delay step length optimizing position updating strategy, and enhances the global searching capability and the local utilization capability of the algorithm in iteration.
The technical scheme adopted by the invention is as follows: the invention provides an optical lens surface defect detection method based on image processing, which comprises the following steps:
step S1: image acquisition, namely acquiring an optical lens surface image and constructing a surface image data set;
step S2: image enhancement, namely introducing a compensation factor to correct a logarithmic function of an MSR algorithm, calculating an optimal scale parameter based on a flatness index, thereby determining an adaptive weight, and carrying out normalization processing on the brightness of the image to obtain an optical lens surface enhanced image;
step S3: constructing an optical lens surface defect detection model, calculating the score of a defect class and the square sum of the distance between the feature and the center of the corresponding class, and introducing a weighting coefficient and a constraint factor to define a loss function;
step S4: model parameter searching, initializing an individual position by using a sine chaotic mapping method, introducing a nonlinear convergence factor and a random delay step length optimization position updating strategy, and determining model parameters;
step S5: and (3) detecting the surface defects of the optical lens, inputting the optical lens surface images acquired in real time into an optical lens surface defect detection model for classification, and detecting the defects based on the output defect type labels.
Further, in step S1, the image acquisition is acquisition of an optical lens surface image and a surface image dataset is constructed based on the optical lens surface image and a defect class of the optical lens surface image.
Further, in step S2, the image enhancement specifically includes the following steps:
step S21: dividing an image area, namely uniformly dividing each optical lens surface image in a surface image data set into N1 image sub-blocks, presetting a flatness threshold value psi 1, and dividing the image sub-blocks with flatness indexes larger than the flatness threshold value psi 1 into non-flat areas; otherwise, dividing into flat areas, and calculating a flatness index according to the following formula:
;
wherein beta is f Is the flatness index of image sub-block f, gamma and epsilon are the control flatness index range factors, delta f Is the standard deviation, beta, of image sub-block f f And delta f Satisfying the inverse relation, f is the image sub-block index;
step S22: calculating an optimal scale parameter, and calculating the optimal scale parameter of the Gaussian surrounding filter based on the flatness index of the image sub-block f by using the following formula:
;
wherein mu is f Is the optimal scale parameter of Gaussian surrounding filter corresponding to image sub-block f, mu max Sum mu min Maximum and minimum, respectively, of the optimal scale parameter, max (beta f ) And min (beta) f ) Respectively maximum and minimum values of the flatness index;
step S23: the adaptive weights are calculated using the following formula:
;
;
wherein mu is 1 、μ 2 Sum mu 3 Respectively minimum, intermediate and maximum values of flatness index, b f,1 、b f,2 And b f,3 Is three different scales, ω, of image sub-block f f,c Is the adaptive weight of image sub-block f on scale c, i and c are scale indices;
step S24: multiscale enhancement, the formula used is as follows:
;
;
in which W is e (x, y) is the enhancement effect of the optical lens surface map R, G and the B color channels,is a compensation factor, l e (x, y) is the luminance value of the e-th color channel of the optical lens surface image, e is the color channel index,/->Is the convolution operator, g e (x, y) is the effect of the e-th color channel of the optical lens surface image after being processed by a Gaussian surround filter, h is a normalization factor, and x and y are the abscissa index and the ordinate index of the optical lens surface image respectively;
step S25: brightness normalization is carried out on the optical lens surface image, so that a brightness normalized optical lens surface image M (x, y) is obtained;
step S26: constructing an enhancement data set, calculating an enhanced optical lens surface image, and constructing the enhancement data set based on the optical lens surface enhanced image, wherein the formula is as follows:
;
wherein J is e (x, y) is an optical lens surface enhanced image.
Further, in step S3, the construction of the optical lens surface defect detection model specifically includes the following steps:
step S31: initializing a model, wherein the preset model consists of an input layer, a hidden layer and an output layer, the input layer receives the surface enhanced image of the optical lens, the hidden layer is used for extracting the characteristics in the surface enhanced image of the optical lens, and the output layer is used for outputting the defect type corresponding to the surface enhanced image of the optical lens;
step S32: the loss function is defined using the formula:
;
where Loss is a Loss function, θ is the angle between defect categories, N3 is the feature quantity, p is the feature index, x p Is the p-th feature, yp is the p-th bitC, marking corresponding defect type labels yp Is the defect class center of the defect class yp, m is the margin parameter, w is the defect class ratio, d is the number of defect class labels, j is the index of the defect class labels, λ is the weighting coefficient, n is the constraint factor,is the score of the defect class yp.
Further, in step S4, the model parameter search specifically includes the following steps:
step S41: initializing a position, representing the position of an individual by using model parameters, initializing the position of the individual by using a sinusoidal chaotic mapping method, taking the model performance established based on the model parameters as an individual position fitness value, and initializing the position of the individual by using the following formula:
;
in the method, in the process of the invention,is the initial position of the a+1st individual, < >>Is the initial position of the a-th individual, a is the individual index, N2 is the number of individuals, o is the control factor,>an initial position of the 1 st individual randomly generated based on the individual search space;
step S42: calculating an optimal fitness value and a global optimal position, updating fitness values of individuals, selecting the highest fitness value as the optimal fitness value, taking an individual corresponding to the optimal fitness value as an optimal individual, and taking the position corresponding to the optimal individual as a global optimal position E best ;
Step S43: the position is updated as follows:
step S431: calculating nonlinear convergence factor, and presetting the most value of nonlinear convergence factorLarge value s max The formula used is as follows:
;
wherein s is a nonlinear convergence factor, T is the current iteration number, and T is the maximum iteration number;
step S432: the random delay step is calculated using the following formula:
;
;
;
in the method, in the process of the invention,is elite individual index, round () is a rounding function, +.>Is the distance between the qth individual and the optimal individual or elite individual in the nth iteration in the nth dimension, U is the individual search space dimension, U is the dimension index,is the position of the optimal individual in the u-th dimension at the t-th iteration,/for the iteration>Is the position of the qth individual in the nth iteration in the nth dimension, +.>Is the position of the elite individual in the u-th dimension at the t-th iteration,/for>Is the random delay step size, r, used for updating the position of elite individuals in the ith iteration 1 And r 2 Is a random number between (0, 1), P is a time lag factor, v 0 And v 1 The initial value and the end value of the acceleration coefficient are respectively, k is a random delay time and k is E [0, t-1];
Step S433: updating the individual location using the formula:
;
in the method, in the process of the invention,is the position of the (q) th individual in the (t+1) th iteration, r 3 And r 4 Is a random number between (0, 1), z is a chaotic vector;
step S44: determining model parameters, presetting an fitness value evaluation threshold delta, updating an optimal fitness value and a global optimal position, and constructing an optical lens surface defect detection model based on current model parameters when the optimal fitness value is higher than the fitness value evaluation threshold delta; otherwise, if the maximum iteration number T is reached, go to step S41; otherwise, the process goes to step S43.
Further, in step S5, the optical lens surface defect detection is to collect an optical lens surface image in real time, input the optical lens surface image into the optical lens surface defect detection model, and detect the optical lens surface based on the defect type label output by the optical lens surface defect detection model.
The invention provides an optical lens surface defect detection system based on image processing, which comprises an image acquisition module, an image enhancement module, a module for constructing an optical lens surface defect detection model, a model parameter search module and an optical lens surface defect detection module, wherein the image acquisition module is used for acquiring an image of the optical lens surface defect;
the image acquisition module acquires the surface image of the optical lens, constructs a surface image data set based on the surface image of the optical lens and the defect type of the surface image of the optical lens, and sends the data to the image enhancement module;
the image enhancement module introduces a compensation factor to correct a logarithmic function of an MSR algorithm, calculates an optimal scale parameter based on a flatness index, thereby determining an adaptive weight, carrying out normalization processing on brightness of an image to obtain an optical lens surface enhanced image, and sending data to a module for constructing an optical lens surface defect detection model;
the module for constructing the optical lens surface defect detection model calculates the score and the square sum of the distance between the feature of the defect category and the center of the corresponding category, introduces a weighting coefficient and a constraint factor to define a loss function, and sends data to the model parameter searching module;
the model parameter searching module uses a sine chaotic mapping method to initialize individual positions, introduces nonlinear convergence factors and random delay step length optimization position updating strategies, determines model parameters, and sends data to the optical lens surface defect detecting module;
the optical lens surface defect detection module acquires an optical lens surface image in real time, inputs the optical lens surface image into the optical lens surface defect detection model, and detects defects on the optical lens surface based on the defect type label output by the optical lens surface defect detection model.
By adopting the scheme, the beneficial effects obtained by the invention are as follows:
(1) Aiming at the problems of loss or distortion of image details and reduced image quality caused by amplified image noise in the existing image enhancement method, the method introduces a compensation factor to correct the logarithmic function of the MSR algorithm, can better reserve and enhance the detail information in the image, calculates the optimal scale parameter based on the flatness index, thereby determining the self-adaptive weight, effectively inhibiting the noise in the image, better balancing the details and the noise in the image, carrying out normalization processing on the brightness of the image, leading the enhanced image to be more balanced and natural, and improving the image quality.
(2) Aiming at the problems that the traditional optical lens surface defect detection model is excessively focused on local features, so that model training is difficult and convergence time is long, the scheme calculates the score of the defect class, so that the higher-score class has larger contribution to the loss function, measures the dispersion degree of feature vectors by calculating the square sum of the distances between the features and the centers of the corresponding classes, introduces a weighting coefficient and a constraint factor to define the loss function, enables the loss function to more comprehensively reflect the performance of the model, can accurately detect and classify the defects of the optical lens surface image, reduces the misjudgment rate, and improves the accuracy of defect detection.
(3) Aiming at the problems that the current model parameter searching algorithm is low in convergence speed and easy to fall into local optimum and low in optimizing accuracy, the method initializes the individual position by using a sinusoidal chaotic mapping method, introduces a nonlinear convergence factor and a random delay step length optimizing position updating strategy, effectively prevents the algorithm from falling into a local optimum solution, improves convergence and solving accuracy, and enhances global searching capability and local utilization capability of the algorithm in iteration.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are only some, but not all embodiments of the invention; all other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In the description of the present invention, it should be understood that the terms "upper," "lower," "front," "rear," "left," "right," "top," "bottom," "inner," "outer," and the like indicate orientation or positional relationships based on those shown in the drawings, merely to facilitate description of the invention and simplify the description, and do not indicate or imply that the devices or elements referred to must have a particular orientation, be constructed and operated in a particular orientation, and thus should not be construed as limiting the invention.
Referring to fig. 1, the method for detecting surface defects of an optical lens based on image processing provided by the invention includes the following steps:
step S1: image acquisition, namely acquiring an optical lens surface image and constructing a surface image data set;
step S2: image enhancement, namely introducing a compensation factor to correct a logarithmic function of an MSR algorithm, calculating an optimal scale parameter based on a flatness index, thereby determining an adaptive weight, and carrying out normalization processing on the brightness of the image to obtain an optical lens surface enhanced image;
step S3: constructing an optical lens surface defect detection model, calculating the score of a defect class and the square sum of the distance between the feature and the center of the corresponding class, and introducing a weighting coefficient and a constraint factor to define a loss function;
step S4: model parameter searching, initializing an individual position by using a sine chaotic mapping method, introducing a nonlinear convergence factor and a random delay step length optimization position updating strategy, and determining model parameters;
step S5: and (3) detecting the surface defects of the optical lens, inputting the optical lens surface images acquired in real time into an optical lens surface defect detection model for classification, and detecting the defects based on the output defect type labels.
In step S1, the image acquisition is to acquire an optical lens surface image, and construct a surface image dataset based on the optical lens surface image and a defect class of the optical lens surface image, referring to fig. 1.
Embodiment three, referring to fig. 1 and 3, the embodiment is based on the above embodiment, and in step S2, the image enhancement specifically includes the following steps:
step S21: dividing an image area, namely uniformly dividing each optical lens surface image in a surface image data set into N1 image sub-blocks, presetting a flatness threshold value psi 1, and dividing the image sub-blocks with flatness indexes larger than the flatness threshold value psi 1 into non-flat areas; otherwise, dividing into flat areas, and calculating a flatness index according to the following formula:
;
wherein beta is f Is the flatness index of image sub-block f, gamma and epsilon are the control flatness index range factors, delta f Is the standard deviation, beta, of image sub-block f f And delta f Satisfying the inverse relation, f is the image sub-block index;
step S22: calculating an optimal scale parameter, and calculating the optimal scale parameter of the Gaussian surrounding filter based on the flatness index of the image sub-block f by using the following formula:
;
wherein mu is f Is the optimal scale parameter of Gaussian surrounding filter corresponding to image sub-block f, mu max Sum mu min Maximum and minimum, respectively, of the optimal scale parameter, max (beta f ) And min (beta) f ) Respectively maximum and minimum values of the flatness index;
step S23: the adaptive weights are calculated using the following formula:
;
;
wherein mu is 1 、μ 2 Sum mu 3 Respectively minimum, intermediate and maximum values of flatness index, b f,1 、b f,2 And b f,3 Is three different scales, ω, of image sub-block f f,c Is the adaptive weight of image sub-block f on scale c, i and c are scale indices;
step S24: multiscale enhancement, the formula used is as follows:
;
;
in which W is e (x, y) is the enhancement effect of the optical lens surface map R, G and the B color channels,is a compensation factor, l e (x, y) is the luminance value of the e-th color channel of the optical lens surface image, e is the color channel index,/->Is the convolution operator, g e (x, y) is the effect of the e-th color channel of the optical lens surface image after being processed by a Gaussian surround filter, h is a normalization factor, and x and y are the abscissa index and the ordinate index of the optical lens surface image respectively;
step S25: brightness normalization is carried out on the optical lens surface image, so that a brightness normalized optical lens surface image M (x, y) is obtained;
step S26: constructing an enhancement data set, calculating an enhanced optical lens surface image, and constructing the enhancement data set based on the optical lens surface enhanced image, wherein the formula is as follows:
;
wherein J is e (x, y) is an optical lens surface enhanced image.
By executing the operation, aiming at the problems of loss or distortion of image details, amplification of image noise and reduction of enhanced image quality existing in the existing image enhancement method, the method introduces a compensation factor to correct a logarithmic function of an MSR algorithm, can better reserve and enhance detail information in an image, calculates an optimal scale parameter based on a flatness index, thereby determining self-adaptive weight, effectively inhibiting noise in the image, better balancing details and noise in the image, and carrying out normalization processing on brightness of the image, so that the enhanced image is more balanced and natural, and the image quality is improved.
In a fourth embodiment, referring to fig. 1 and 4, the method for constructing the optical lens surface defect detection model in step S3 specifically includes the following steps:
step S31: initializing a model, wherein the preset model consists of an input layer, a hidden layer and an output layer, the input layer receives the surface enhanced image of the optical lens, the hidden layer is used for extracting the characteristics in the surface enhanced image of the optical lens, and the output layer is used for outputting the defect type corresponding to the surface enhanced image of the optical lens;
step S32: the loss function is defined using the formula:
;
where Loss is a Loss function, θ is the angle between defect categories, N3 is the feature quantity, p is the feature index, x p Is the p-th feature, yp is the defect class label corresponding to the p-th feature, c yp Is the defect class center of the defect class yp, m is the margin parameter, w is the defect class ratio, d is the number of defect class labels, j is the index of the defect class labels, λ is the weighting coefficient, n is the constraint factor,is the score of the defect class yp.
By executing the operation, aiming at the problems that the traditional optical lens surface defect detection model has too much attention to local characteristics, so that model training is difficult and convergence time is long, the scheme calculates the score of the defect class, so that the higher-score class has larger contribution to the loss function, measures the dispersion degree of the feature vector by calculating the square sum of the distances between the feature and the center of the corresponding class, and introduces a weighting coefficient and a constraint factor to define the loss function, so that the loss function can more comprehensively reflect the performance of the model, accurately detect and classify the defects of the optical lens surface image, reduce the false judgment rate and improve the accuracy of defect detection.
Fifth embodiment referring to fig. 1 and 5, the embodiment is based on the above embodiment, and in step S4, the model parameter search specifically includes the following steps:
step S41: initializing a position, representing the position of an individual by using model parameters, initializing the position of the individual by using a sinusoidal chaotic mapping method, taking the model performance established based on the model parameters as an individual position fitness value, and initializing the position of the individual by using the following formula:
;
in the method, in the process of the invention,is the initial position of the a+1st individual, < >>Is the initial position of the a-th individual, a is the individual index, N2 is the number of individuals, o is the control factor,>an initial position of the 1 st individual randomly generated based on the individual search space;
step S42: calculating the optimal fitness value and the global optimal position, updating the fitness value of the individual, selecting the highest fitness value as the optimal fitness value, and corresponding the optimal fitness valueThe individual is taken as the optimal individual, and the corresponding position of the optimal individual is taken as the global optimal position E best ;
Step S43: the position is updated as follows:
step S431: calculating nonlinear convergence factor, and presetting the maximum value of the nonlinear convergence factor as s max The formula used is as follows:
;
wherein s is a nonlinear convergence factor, T is the current iteration number, and T is the maximum iteration number;
step S432: the random delay step is calculated using the following formula:
;
;
;
in the method, in the process of the invention,is elite individual index, round () is a rounding function, +.>Is the distance between the qth individual and the optimal individual or elite individual in the nth iteration in the nth dimension, U is the individual search space dimension, U is the dimension index,is the position of the optimal individual in the u-th dimension at the t-th iteration,/for the iteration>Is the bit of the qth individual in the nth iteration in the nth dimensionPut (I) at>Is the position of the elite individual in the u-th dimension at the t-th iteration,/for>Is the random delay step size, r, used for updating the position of elite individuals in the ith iteration 1 And r 2 Is a random number between (0, 1), P is a time lag factor, v 0 And v 1 The initial value and the end value of the acceleration coefficient are respectively, k is a random delay time and k is E [0, t-1];
Step S433: updating the individual location using the formula:
;
in the method, in the process of the invention,is the position of the (q) th individual in the (t+1) th iteration, r 3 And r 4 Is a random number between (0, 1), z is a chaotic vector;
step S44: determining model parameters, presetting an fitness value evaluation threshold delta, updating an optimal fitness value and a global optimal position, and constructing an optical lens surface defect detection model based on current model parameters when the optimal fitness value is higher than the fitness value evaluation threshold delta; otherwise, if the maximum iteration number T is reached, go to step S41; otherwise, the process goes to step S43.
By executing the operation, aiming at the problems that the current model parameter searching algorithm is low in convergence speed and easy to fall into local optimum and low in optimum solving accuracy, the method uses a sinusoidal chaotic mapping method to initialize individual positions, introduces nonlinear convergence factors and random delay step length optimizing position updating strategies, effectively prevents the algorithm from falling into local optimum solutions, improves convergence and solving accuracy, and enhances global searching capacity and local utilization capacity of the algorithm in iteration.
In step S5, the optical lens surface defect detection is to collect the optical lens surface image in real time, input the image into the optical lens surface defect detection model, and detect the defect on the optical lens surface based on the defect type label output by the optical lens surface defect detection model, as shown in fig. 1.
An embodiment seven, referring to fig. 2, based on the above embodiment, the optical lens surface defect detection system provided by the invention based on image processing includes an image acquisition module, an image enhancement module, a module for constructing an optical lens surface defect detection model, a model parameter search module and an optical lens surface defect detection module;
the image acquisition module acquires the surface image of the optical lens, constructs a surface image data set based on the surface image of the optical lens and the defect type of the surface image of the optical lens, and sends the data to the image enhancement module;
the image enhancement module introduces a compensation factor to correct a logarithmic function of an MSR algorithm, calculates an optimal scale parameter based on a flatness index, thereby determining an adaptive weight, carrying out normalization processing on brightness of an image to obtain an optical lens surface enhanced image, and sending data to a module for constructing an optical lens surface defect detection model;
the module for constructing the optical lens surface defect detection model calculates the score and the square sum of the distance between the feature of the defect category and the center of the corresponding category, introduces a weighting coefficient and a constraint factor to define a loss function, and sends data to the model parameter searching module;
the model parameter searching module uses a sine chaotic mapping method to initialize individual positions, introduces nonlinear convergence factors and random delay step length optimization position updating strategies, determines model parameters, and sends data to the optical lens surface defect detecting module;
the optical lens surface defect detection module acquires an optical lens surface image in real time, inputs the optical lens surface image into the optical lens surface defect detection model, and detects defects on the optical lens surface based on the defect type label output by the optical lens surface defect detection model.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus.
Although embodiments of the present invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made therein without departing from the principles and spirit of the invention, the scope of which is defined in the appended claims and their equivalents.
The invention and its embodiments have been described above with no limitation, and the actual construction is not limited to the embodiments of the invention as shown in the drawings. In summary, if one of ordinary skill in the art is informed by this disclosure, a structural manner and an embodiment similar to the technical solution should not be creatively devised without departing from the gist of the present invention.