Automatic focusing method and device based on image processing, equipment and storage medium

By combining MobileNetV3 and ResNet18 networks with the DQN algorithm, an autofocus method was developed to solve the problem of traditional autofocus failure in laser repair of OLED display panels. This method achieves efficient and accurate autofocus, making it suitable for industrial production in different scenarios.

CN122027892APending Publication Date: 2026-05-12JIHUA LAB
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
JIHUA LAB
Filing Date
2025-12-25
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

In the laser repair process of OLED display panels, the traditional line laser autofocus solution fails due to short-wavelength repair, while manual focusing is inefficient, unstable, and has a high error rate, which cannot meet the needs of industrial production.

Method used

The MobileNetV3 network is used for defect identification. Combined with the ResNet18 network and DQN algorithm, the light intensity, exposure time and step size are adaptively adjusted. The focus is terminated and the optimal position is locked by weighted summation of the Laplacian operator mean, image variance and gradient magnitude mean.

Benefits of technology

It improves the focusing efficiency, accuracy, and consistency of laser repair for OLED display panels, reduces the error rate, adapts to different wavelengths and coating lens scenarios, and meets the needs of industrial production.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122027892A_ABST
    Figure CN122027892A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of display panels, and discloses an automatic focusing method, device and equipment based on image processing and a storage medium, and the method comprises the steps: setting light intensity, exposure time, an initial direction, an initial step length, an initialization highest score and a corresponding position according to a defect type and an objective lens parameter; obtaining a defect position image, adaptively extracting an ROI region, filtering and denoising, and calculating a Laplacian operator mean value, an image variance and a gradient magnitude mean value of the ROI region; distributing feature weights based on defect types, and performing weighted summation to obtain a current focusing score; according to the comparison between the current focusing score and the historical focusing score, the moving direction and the step length are adjusted, and the highest score and the corresponding position are updated; when the step length is less than or equal to 0.25 [mu] m, if the current position is the highest score position or the distance between the current position and the highest score position is less than or equal to 0.25 [mu] m, stopping focusing and locking the optimal focusing position; according to the invention, the focusing efficiency, accuracy and consistency are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of display panel technology, and more specifically to an autofocus method, apparatus, device, and storage medium based on image processing. Background Technology

[0002] Currently, the production of OLED display panels is increasing day by day, and laser repair of OLED panels used in production is becoming more and more important. The prerequisite for laser repair is that it can be focused correctly. Due to the use of short-wavelength repair, such as 343nm and 257nm, the objective lens will be coated to isolate or weaken other light, causing the traditional line laser autofocus solution to completely fail. Manual focusing has problems such as low efficiency, poor stability and high error rate, which cannot meet the needs of industrial production. Summary of the Invention

[0003] The purpose of this invention is to solve the above-mentioned problems by designing an autofocus method, apparatus, device, and storage medium based on image processing.

[0004] The first aspect of this invention provides an autofocus method based on image processing, the autofocus method based on image processing comprising: The MobileNetV3 network is used to identify defects in the original panel image. Based on the defect type and objective lens parameters, the light intensity, exposure time, initial direction and initial step size are set, and the highest score and corresponding position are initialized. The defect location image is acquired, and the ROI region is adaptively extracted and filtered for noise reduction. The mean of the Laplacian operator, the image variance, and the mean of the gradient magnitude of the ROI region are calculated. The ResNet18 network is used to assign feature weights based on defect type, and the current focus score is obtained by weighted summation based on the mean of the Laplacian operator, image variance, and mean of gradient magnitude. Based on the DQN algorithm, the current focus score is compared with the historical focus scores to adjust the movement direction and step size, and update the highest score and corresponding position. When the step size is less than or equal to 0.25μm, if the current position is the highest score position or the distance to the highest score position is less than or equal to 0.25μm, focus is terminated and the optimal focus position is locked.

[0005] Optionally, in a first implementation of the first aspect of the present invention, the step of using a MobileNetV3 network to perform defect identification on the original panel image, and setting the light intensity, exposure time, initial direction and initial step size according to the defect type and objective lens parameters, and initializing the highest score and corresponding position, includes: The original panel image to be processed is obtained, and the wavelet transform algorithm is used to enhance the original panel image. The enhanced panel image is input into the MobileNetV3 network and upscaled using 1×1 convolutional kernels. The feature information dimension of the image is expanded according to the preset number of output feature map channels. A 3×3 depthwise separable convolution operation is performed on the upgraded feature map to extract preliminary defect features from the image. The initial defect features are fed into the inverse residual structure, which then undergoes global pooling and two fully connected layer operations to automatically assign weights to different feature channels. The weighted feature map is reduced in dimension by using a 1×1 pointwise convolution module to obtain the dimension-reduced defect feature vector. The defect feature vector is input into a classifier consisting of positive Lagrange multipliers, which classifies and determines the defect type. Based on the identified defect type and objective lens parameters, select the light intensity and exposure time values ​​that are suitable for the current scene, and set the initial direction and initial step size for focus movement. Set the initial value of the highest score parameter to 0, and set the initial position corresponding to the highest score as the focus start position.

[0006] Optionally, in a second implementation of the first aspect of the present invention, the step of obtaining the original panel image to be processed and enhancing the original panel image using a wavelet transform algorithm includes: Perform on the original panel image Layer wavelet decomposition operation decomposes the image into layers. The low-frequency and high-frequency coefficients corresponding to the layer; Regarding the first The low-frequency coefficients of the layer determine the image pixel coordinates corresponding to each low-frequency coefficient in the current layer. And extract the two different dimensional components corresponding to the low-frequency coefficient. and ,in j The value range is 1 to ; The wavelet coefficient amplitude of the low-frequency coefficients is calculated using the following formula. : in, Indicates the original panel image in coordinates Pixel value at; Introducing a nonlinear function to adjust the argument of the calculated wavelet coefficients Adjustments are made, and the adjusted argument is denoted as... The expression for the nonlinear function is: in, Indicates the adjustment operator, Indicates the brightness coefficient. Indicates the wavelet threshold. Indicates the current number Low-frequency coefficient values ​​of the layer; Calculate parameters according to the formula. ,by As an enhancement function: in, Used to control the scaling ratio of molecules. For constant bias terms; Compare the enhancement function with the current [number]. The wavelet coefficients corresponding to the low-frequency coefficients in the layer are multiplied to obtain the adjusted low-frequency coefficients. The high-frequency coefficients of each layer after wavelet decomposition are kept unchanged. Combined with all the adjusted low-frequency coefficients, the inverse wavelet transform reconstruction operation is performed to obtain the enhanced panel image.

[0007] Optionally, in a third implementation of the first aspect of the present invention, the step of acquiring the defect location image, adaptively extracting the ROI region and filtering for noise reduction, and calculating the Laplacian operator mean, image variance, and gradient magnitude mean of the ROI region includes: The defect location image is converted into a grayscale image to obtain the coordinate information of the defect region and determine the bounding box coordinates of the defect region. Calculate the width and height of the defect region's bounding box. If the width or height is greater than 640, then use the geometric center of the defect region's bounding box as a reference and truncate it to 640. A 640-pixel square area is designated as the Region of Interest (ROI). If the width is less than or equal to 640 and the height is less than or equal to 40, then the area of ​​the ROI is expanded by 10% pixels in all directions based on the bounding box of the defect area. Iterate through each pixel of the extracted ROI grayscale image, multiply the current pixel and its 8 neighboring pixels by the weights corresponding to the Gaussian kernel, calculate the sum of all products, and replace the grayscale value of the current pixel with the sum to complete noise filtering; The Laplacian operator is used to perform edge detection on the denoised ROI grayscale image to obtain an edge image containing positive and negative values. The value of each pixel in the edge image is converted into an absolute value, and then the arithmetic mean of the absolute values ​​of all pixels is calculated to obtain the Laplacian operator mean. Iterate through all pixels of the denoised ROI grayscale image, calculate the arithmetic mean of all pixel grayscale values, then calculate the difference between each pixel's grayscale value and the arithmetic mean, square each difference to obtain a set of squared differences, and calculate the arithmetic mean of all elements in the set of squared differences to obtain the image variance. The formula is: in, This represents the height (in pixels) of the denoised ROI grayscale image. This represents the width in pixels of the denoised ROI grayscale image. Indicates the ROI region number Line number The grayscale value of the column pixels, This represents the arithmetic mean of the grayscale values ​​of all pixels. Using a 3×3 kernel Sobel operator, gradient operators in the X and Y directions are constructed respectively. This is done by combining each pixel in the denoised ROI grayscale image with its neighboring pixels. The window is convolved with the gradient operators in the X and Y directions respectively to obtain the gradient values ​​in the X and Y directions. The gradient magnitude of the current pixel is obtained based on the gradient values ​​in the X and Y directions, and the arithmetic mean of the gradient magnitudes of all pixels is calculated to determine the average gradient magnitude.

[0008] Optionally, in the fourth implementation of the first aspect of the present invention, the step of using a ResNet18 network to assign feature weights based on defect type and obtaining the current focus score by weighted summation based on the Laplacian operator mean, image variance, and gradient magnitude mean includes: One-hot coding is used to digitize the defect type, and the defect type coding vector and three feature values, namely the mean of the Laplacian operator, the image variance, and the mean of the gradient magnitude, are normalized. The normalized defect type encoding vector and the three normalized feature values ​​are concatenated to form the input vector of the ResNet18 network. The input vector is fed into the input layer of the ResNet18 network, and then passes through the network's convolutional layer, batch normalization layer and ReLU activation function in sequence to perform feature extraction and nonlinear transformation on the input vector; The processed feature vector is input into a global average pooling layer for dimensionality reduction, and then input into a fully connected layer. Through linear transformation, the feature dimension is mapped to 3 dimensions to obtain the initial weight vector. The initial weight vector is input into the Softmax activation function, and the elements of the initial weight vector are normalized to obtain the weight coefficients corresponding to the Laplacian operator mean, the image variance, and the gradient magnitude mean. The current focus score is calculated by weighting the weight coefficients corresponding to the Laplacian operator mean, the image variance, and the gradient magnitude mean.

[0009] Optionally, in the fifth implementation of the first aspect of the present invention, the step of adjusting the movement direction and step size based on the DQN algorithm according to the comparison between the current focus score and the historical focus scores, and updating the highest score and corresponding position, includes: Get the last score, last position, current focus score, current position, highest score, highest score position, and current step size, and collect defect type labels and historical focus score sequences at the same time; Determine if the previous score was 0. If so, determine the first score calculation without adjusting the direction or step size. If it is not 0, the historical focus score sequence is input into the GRU module. Through the synergistic effect of the reset gate and the update gate, a hidden state vector with fused temporal dependence is generated to capture the historical score change trend. The hidden state vector, the previous score, the previous position, the current focus score, the current position, the highest score, the position of the highest score, the current step size, and the defect type label are concatenated in sequence to form a high-dimensional input vector. The high-dimensional input vector is input into the DQN algorithm, the Q value is calculated, and the action with the largest Q value is selected as the initial proposed action of DQN. Calculate the ratio of the current focus score to the previous score. If the ratio is greater than or equal to 5, the step size is halved. If the ratio is less than 5, the step size is adjusted according to the DQN initial suggested action. If the current focus score is less than the previous score, the movement direction is set to negative, and the step size is halved again to obtain the final step size. If the current focus score is greater than the previous score, the movement direction remains positive, and the step size remains unchanged. Move to a new position based on the final step size and final direction of movement, acquire a focus image at the new position, and calculate a new focus score; Compare the new focus score, the previous score, and the highest score. Assign the score with the largest value to the highest score and assign the position corresponding to the highest score to the highest score position.

[0010] Optionally, in the sixth implementation of the first aspect of the present invention, the step of inputting the high-dimensional input vector into the DQN algorithm, calculating the Q-value, and selecting the action with the largest Q-value as the initial proposed action of DQN includes: high-dimensional input vector The input to the DQN algorithm is processed sequentially through convolutional layers and fully connected layers, and then fed into the NoisyLinear layer to calculate the weights of the NoisyLinear layer. and bias And calculate the output of the NoisyLinear layer. : in, , This represents the learnable mean parameter. , This represents the learnable standard deviation parameter. , represents Gaussian noise, and ⊙ represents element-wise multiplication; The output of the NoisyLinear layer is passed to the Dueling module, and the Q value is calculated using the following formula: in, Represents the state value function. Represents the action advantage function. This represents the mean of the action advantage value. Indicates the current state. Indicates a candidate action.

[0011] A second aspect of the present invention provides an image processing-based autofocus device, the image processing-based autofocus device comprising: The initialization module is used to identify defects in the original panel image using the MobileNetV3 network, and to set the light intensity, exposure time, initial direction and initial step size according to the defect type and objective lens parameters, and initialize the highest score and corresponding position. The calculation module is used to acquire defect location images, adaptively extract ROI regions and filter and denoise, and calculate the mean of the Laplacian operator, image variance and mean gradient magnitude of the ROI region. The weighted summation module is used to assign feature weights based on defect type using the ResNet18 network, and to obtain the current focus score by weighted summation based on the mean of the Laplacian operator, the image variance, and the mean of the gradient magnitude. The update module is used to adjust the movement direction and step size based on the DQN algorithm, comparing the current focus score with the historical focus scores, and to update the highest score and its corresponding position. The focusing module is used to terminate focusing and lock the optimal focusing position when the step size is less than or equal to 0.25μm, if the current position is the highest score position or the distance to the highest score position is less than or equal to 0.25μm.

[0012] A third aspect of the present invention provides an image processing-based autofocus device, the image processing-based autofocus device comprising a memory and at least one processor, the memory storing instructions; the at least one processor invokes the instructions in the memory to cause the image processing-based autofocus device to perform the steps of the image processing-based autofocus method as described in any of the preceding claims.

[0013] A fourth aspect of the present invention provides a computer-readable storage medium storing instructions that, when executed by a processor, implement the steps of the image processing-based autofocus method as described in any of the preceding claims.

[0014] In the technical solution provided by this invention, a MobileNetV3 network is used to identify defects in the original panel image. Based on the defect type and objective lens parameters, the light intensity, exposure time, initial direction, and initial step size are set, and the highest score and corresponding position are initialized. The defect location image is acquired, and the Region of Interest (ROI) is adaptively extracted and filtered for noise reduction. The mean of the Laplacian operator, image variance, and mean gradient magnitude of the ROI region are calculated. A ResNet18 network is used to assign feature weights based on the defect type, and the weighted sum is obtained based on the mean of the Laplacian operator, image variance, and mean gradient magnitude. The system retrieves the current focus score; based on the DQN algorithm, it adjusts the movement direction and step size by comparing the current focus score with historical focus scores, and updates the highest score and its corresponding position; when the step size is less than or equal to 0.25μm, if the current position is the highest score position or the distance to the highest score position is less than or equal to 0.25μm, focusing is terminated and the optimal focus position is locked; this invention eliminates dependence on other sensors, adapts to different wavelengths, bright / dark fields, and scenes with coated lenses, improves focusing efficiency, accuracy, and consistency, reduces error rate, and adapts to the focusing needs of scenarios such as laser repair of display panels. Attached Figure Description

[0015] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the invention.

[0016] Figure 1 A schematic diagram of the first embodiment of the remote image processing-based autofocus method provided by the present invention; Figure 2 A schematic diagram of a second embodiment of the image processing-based autofocus method provided by the present invention; Figure 3 A schematic diagram of a third embodiment of the image processing-based autofocus method provided by the present invention; Figure 4 A schematic diagram of an image processing-based autofocus device provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of the structure of an image processing-based autofocus device provided in an embodiment of the present invention. Detailed Implementation

[0017] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a particular order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” or “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, apparatus, product, or device that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or devices.

[0018] For ease of understanding, the specific process of the embodiments of the present invention is described below. Please refer to [link / reference]. Figure 1 A schematic diagram of the first embodiment of the autofocus method based on image processing provided by this invention is shown. The method specifically includes the following steps: Step 101: Use the MobileNetV3 network to identify defects in the original panel image, and set the light intensity, exposure time, initial direction and initial step size according to the defect type and objective lens parameters, and initialize the highest score and corresponding position. Step 102: Obtain the defect location image and adaptively extract the ROI region and filter and denoise it. Calculate the mean of the Laplacian operator, the image variance, and the mean of the gradient magnitude of the ROI region. In this embodiment, the defect location image is converted into a grayscale image to obtain the coordinate information of the defect area and determine the bounding box coordinates of the defect area; Calculate the width and height of the defect region's bounding box. If the width or height is greater than 640, then use the geometric center of the defect region's bounding box as a reference and truncate it to 640. A 640-pixel square area is designated as the Region of Interest (ROI). If the width is less than or equal to 640 and the height is less than or equal to 40, then the area of ​​the ROI is expanded by 10% pixels in all directions based on the bounding box of the defect area. Iterate through each pixel of the extracted ROI grayscale image, multiply the current pixel and its 8 neighboring pixels by the weights corresponding to the Gaussian kernel, calculate the sum of all products, and replace the grayscale value of the current pixel with the sum to complete noise filtering; The Laplacian operator is used to perform edge detection on the denoised ROI grayscale image to obtain an edge image containing positive and negative values. The value of each pixel in the edge image is converted into an absolute value, and then the arithmetic mean of the absolute values ​​of all pixels is calculated to obtain the Laplacian operator mean. Iterate through all pixels of the denoised ROI grayscale image, calculate the arithmetic mean of all pixel grayscale values, then calculate the difference between each pixel's grayscale value and the arithmetic mean, square each difference to obtain a set of squared differences, and calculate the arithmetic mean of all elements in the set of squared differences to obtain the image variance. The formula is: in, This represents the height (in pixels) of the denoised ROI grayscale image. This represents the width in pixels of the denoised ROI grayscale image. Indicates the ROI region number Line number The grayscale value of the column pixels, This represents the arithmetic mean of the grayscale values ​​of all pixels. Using a 3×3 kernel Sobel operator, gradient operators in the X and Y directions are constructed respectively. This is done by combining each pixel in the denoised ROI grayscale image with its neighboring pixels. The window is convolved with the gradient operators in the X and Y directions respectively to obtain the gradient values ​​in the X and Y directions. The gradient magnitude of the current pixel is obtained based on the gradient values ​​in the X and Y directions, and the arithmetic mean of the gradient magnitudes of all pixels is calculated to determine the average gradient magnitude.

[0019] Step 103: Use the ResNet18 network to assign feature weights based on defect type, and obtain the current focus score by weighted summation based on the mean of the Laplacian operator, image variance, and mean of gradient magnitude. Step 104: Based on the DQN algorithm, adjust the movement direction and step size according to the comparison between the current focus score and the historical focus score, and update the highest score and corresponding position; In this embodiment, one-hot encoding is used to digitize the defect type, and the defect type encoding vector and three feature values—the Laplacian operator mean, image variance, and gradient magnitude mean—are normalized. The normalized defect type encoding vector and the three normalized feature values ​​are concatenated to form the input vector of the ResNet18 network. The input vector is then fed into the input layer of the ResNet18 network, passing through convolutional layers, batch normalization layers, and the ReLU activation function in sequence to perform feature extraction and nonlinear transformation. The processed feature vector is then... The input values ​​are processed by a global average pooling layer for dimensionality reduction, and then input into a fully connected layer. A linear transformation maps the feature dimension to 3D, resulting in a preliminary weight vector. The preliminary weight vector is then input into a Softmax activation function to normalize its elements, yielding weight coefficients corresponding to the Laplacian operator mean, image variance, and gradient magnitude mean. Based on these weight coefficients, a weighted sum is calculated to obtain the current focus score.

[0020] In this embodiment, the total dimension of the input vector is k plus 3, where k is the total number of defect types and 3 corresponds to three image feature values. After the stitching is completed, if there is a dimension mismatch, it is adjusted through the dimension mapping layer built into the ResNet18 network. Usually, a 1×1 convolutional kernel or a fully connected layer is used for dimension adaptation to ensure that the format of the input data fully conforms to the processing standard of the ResNet18 network. The input vector first needs to be reshaped from a one-dimensional vector into a three-dimensional tensor format that the ResNet18 network can accept. After the format conversion, the tensor is passed to the convolutional layer. The convolutional layer uses a 3×3 kernel. By sliding the kernel on the feature map, the local correlation features in the input vector are extracted. During the convolution process, each kernel performs a weighted calculation on the pixel values ​​in its coverage area and adds a bias term to obtain the feature response value of that area. The output of the convolution operation is immediately passed to the batch normalization layer. This layer standardizes each feature value by calculating the mean and variance of the current batch of feature data, making the distribution of feature values ​​more stable, thereby reducing the internal covariate shift problem during network training and improving the stability and convergence speed of model training. The feature vector after batch normalization is input to the ReLU activation function. The function retains the part of the feature value that is greater than 0 and sets the feature value that is less than or equal to 0 to 0. Through this non-linear mapping relationship, invalid feature signals are suppressed, and effective feature expressions that are valuable for defect identification and focus judgment are strengthened, thus completing the initial feature extraction and optimization. In the global average pooling layer, for each feature channel, the arithmetic mean of all pixel values ​​in that channel is calculated, resulting in a mean for each channel. This compresses the high-dimensional feature map into a fixed-dimensional one-dimensional feature vector. The one-dimensional feature vector obtained after pooling is then fed into the fully connected layer, which contains a preset weight matrix. Through matrix multiplication, the input feature vector is linearly transformed, mapping the original high-dimensional feature vector into a fixed-dimensional 3-dimensional vector. This 3-dimensional vector is the initial weight vector, and the three elements in the vector correspond to the initial weight coefficients of the three original features: the Laplacian operator mean, the image variance, and the gradient magnitude mean. The initial weight vector is input into the Softmax activation function. First, each element in the initial weight vector is subjected to an exponential operation. Then, the sum of the exponential operation results of the three elements is calculated. Finally, the exponential operation result of each element is divided by this sum. The result is the standardized weight coefficient corresponding to that element. Through this operation, the initial weight vector is transformed into a standardized weight vector. The three elements in the vector serve as the weight coefficients of the Laplacian operator mean, image variance, and gradient magnitude mean, respectively. These three coefficients are interrelated, and their values ​​directly reflect the importance of the corresponding feature in the focus score calculation. The larger the value, the more significant the impact of the feature on the sharpness judgment. The original value of the Laplacian operator mean is multiplied by its corresponding standardized weight coefficient, the original value of the image variance is multiplied by its corresponding weight coefficient, and the original value of the gradient magnitude mean is multiplied by its corresponding weight coefficient. Finally, the results of these three calculations are added together. The sum is the score of the current focus position. This score is a quantitative value that can intuitively reflect the sharpness of the current imaging position. The higher the score, the better the sharpness of the current imaging position and the closer it is to the optimal focus state.

[0021] Step 105: When the step size is less than or equal to 0.25 μm, if the current position is the highest score position or the distance to the highest score position is less than or equal to 0.25 μm, stop focusing and lock the optimal focus position.

[0022] In this embodiment, it is determined whether the current step size is already the minimum (less than or equal to 0.25). If so, it is determined whether the score at the current position is the highest. If so, it directly exits the autofocus. Otherwise, it is determined whether the distance between the highest score position and the current position is less than or equal to the minimum step size. If so, it directly moves to the highest score position and exits the autofocus. If neither of these conditions is met, it moves according to the direction and step size and re-enters the image scoring step.

[0023] In this embodiment of the invention, defect identification is performed on the original panel image using the MobileNetV3 network. This network combines lightweight design with high recognition accuracy, enabling it to quickly and accurately distinguish different defect types. By combining core parameters such as the coating type and magnification of the objective lens, imaging parameters such as light intensity and exposure time are set specifically, avoiding the problem of blurred imaging of defect areas under traditional general parameters. This ensures that the initially acquired defect location image clearly presents detailed features. At the same time, the focusing parameters and the highest scoring benchmark are initialized, giving the focusing process a clear target orientation from the beginning and reducing invalid focusing actions. The adaptive ROI extraction step can accurately pinpoint the location of defects, discarding redundant areas without defects in the image, significantly reducing the processing load of subsequent filtering, denoising, and feature calculation, and improving the overall process efficiency. After filtering and denoising to remove image noise interference, the calculated Laplacian operator mean, image variance, gradient magnitude mean, and other features can more realistically reflect the imaging clarity of the defect area, avoiding feature distortion caused by noise. Compared with the traditional full-image feature calculation method, this mode reduces the consumption of computing resources and improves the effectiveness of feature data. The weighted focus score can accurately match the current sharpness judgment requirements of the defect, avoid the scoring deviation caused by the solidification of weights, and make the scoring results more in line with the actual image quality, providing accurate guidance for focus adjustment; the introduction of the DQN algorithm combines the comparison results of historical focus scores and current scores to dynamically optimize the movement direction and step size, which has stronger adaptive ability compared with traditional fixed step size or experience-based adjustment methods. A dual termination condition is set: the minimum step size limit ensures that the focus adjustment reaches the micrometer level accuracy, and the position judgment locks the optimal imaging position. When the step size drops to the minimum accuracy, if the current position is already the highest score position, it can be terminated directly to avoid invalid operation; if the distance to the highest score position is within the accuracy range, it moves to that position and then terminates, ensuring that the finally locked position is the optimal position with the clearest defect imaging. This effectively avoids the problems of insufficient accuracy or over-adjustment in traditional focusing and meets the stringent requirements of panel defect detection for imaging accuracy. The entire process requires no manual intervention, reducing labor costs and workload, and avoiding focusing deviations caused by human error. This ensures high consistency in focusing processes across different batches and operators, improving the stability and repeatability of panel inspection results and providing reliable technical support for industrialized batch inspection. Requiring only the image, it eliminates reliance on other sensors, offering convenient integration, low cost, and fully automatic focusing without human intervention, thus improving efficiency. It adapts to different wavelengths, bright / dark fields, and coated lenses. The more complex the pattern, the more accurate the focus, making it ideal for automatic focusing at defect locations, significantly reducing error rates. Automatic focusing has a lower error rate and higher consistency than manual focusing, improving focusing efficiency, accuracy, and consistency, reducing error rates, and offering wide adaptability. It is not affected by various lens coatings, preventing focusing failures, and is suitable for focusing requirements in scenarios such as laser repair of display panels. Please see Figure 2 A schematic diagram of a second embodiment of the image processing-based autofocus method provided in this invention is shown. The method includes: Step 201: Obtain the original panel image to be processed, and use the wavelet transform algorithm to enhance the original panel image; In this embodiment, the original panel image is processed. Layer wavelet decomposition operation decomposes the image into layers. The low-frequency and high-frequency coefficients corresponding to the layer; Regarding the first The low-frequency coefficients of the layer determine the image pixel coordinates corresponding to each low-frequency coefficient in the current layer. And extract the two different dimensional components corresponding to the low-frequency coefficient. and ,in j The value range is 1 to ; The wavelet coefficient amplitude of the low-frequency coefficients is calculated using the following formula. : in, Indicates the original panel image in coordinates Pixel value at; Introducing a nonlinear function to adjust the argument of the calculated wavelet coefficients Adjustments are made, and the adjusted argument is denoted as... The expression for the nonlinear function is: in, Indicates the adjustment operator, Indicates the brightness coefficient. Indicates the wavelet threshold. Indicates the current number Low-frequency coefficient values ​​of the layer; Calculate parameters according to the formula. ,by As an enhancement function: in, Used to control the scaling ratio of molecules. For constant bias terms; Compare the enhancement function with the current [number]. The wavelet coefficients corresponding to the low-frequency coefficients in the layer are multiplied to obtain the adjusted low-frequency coefficients. The high-frequency coefficients of each layer after wavelet decomposition are kept unchanged. Combined with all the adjusted low-frequency coefficients, the inverse wavelet transform reconstruction operation is performed to obtain the enhanced panel image.

[0024] Step 202: Input the enhanced panel image into the MobileNetV3 network and perform dimensionality upscaling operation through 1×1 convolution kernels to expand the feature information dimension of the image according to the preset number of output feature map channels. In this embodiment, the enhanced panel image needs to be converted into a tensor format adapted to the network to ensure that the pixel values ​​are normalized to a preset range. After the tensor is input into the input layer of the MobileNetV3 network, a 1×1 convolution kernel is called to perform dimensionality increase operation. The number of convolution kernels is consistent with the preset number of output feature map channels. The feature dimension of the image is expanded through convolution operation, so that the feature vector dimension corresponding to each pixel increases, thereby enriching the feature information of the image.

[0025] Step 203: Perform a 3×3 depthwise separable convolution operation on the upgraded feature map to extract preliminary defect features from the image; In this embodiment, the upgraded feature map is split according to the channel dimension, and a 3×3 convolution kernel is applied to each channel for convolution operation. Each channel corresponds to independent convolution kernel parameters to avoid mutual interference between features of different channels. This depth-separable convolution operation reduces the computation of network parameters and lowers the operating cost, while accurately capturing local features related to defects in the image, such as the edge contours and texture differences of defects, forming a feature map set containing preliminary defect information, thus completing the extraction of preliminary defect features.

[0026] Step 204: Input the preliminary defect features into the inverse residual structure, and then process them through global pooling and two fully connected layer operations in sequence, automatically assigning weights to different feature channels; In this embodiment, the initial defect feature map first enters the global pooling layer. By aggregating and calculating the global information of each feature channel, the global feature value of each channel is obtained, compressing the spatial dimension while retaining key information. Then, the global feature value is input into the first fully connected layer for linear transformation and dimension mapping of the features. It is then passed into the second fully connected layer, where the ReLU activation function is combined to achieve nonlinear feature transformation. Through the synergistic effect of the two fully connected layers, the importance of different feature channels is automatically learned, and feature channels containing effective defect information are given higher weights, while irrelevant and redundant feature channels are suppressed, thus completing the weight allocation of feature channels.

[0027] Step 205: The weighted feature map is reduced in dimension by a 1×1 pointwise convolution module to obtain the dimension-reduced defect feature vector. In this embodiment, the weighted feature map still maintains a high channel dimension. A 1×1 pointwise convolution kernel is used, the number of which is determined based on the preset target feature dimension. Convolution operations are performed to compress the dimensionality of the high-dimensional feature map, removing redundant information and retaining the core defect features. The semantic consistency of the features is maintained during dimensionality reduction to ensure that key defect-related information is not lost. The final output is a one-dimensional defect feature vector with fixed dimensions and condensed information.

[0028] Step 206: Input the defect feature vector into a classifier composed of positive Lagrange multipliers, classify the defect feature vector, and output the defect type result; In this embodiment, the defect feature vector is first standardized to ensure that its numerical range meets the input standard of the classifier. The classifier constructs an optimization objective function through a forward Lagrange multiplier, integrates the classification task with regularization constraints, solves the input defect feature vector, calculates the matching degree between the feature vector and the standard feature templates of various defects, determines the defect type based on the maximum matching degree, and outputs a clear classification result.

[0029] Step 207: Based on the identified defect type and objective lens parameters, select the light intensity value and exposure time value that are suitable for the current scene, and set the initial direction and initial step size of the focus movement. In this embodiment, the core parameters of the objective lens are first collected, including key indicators such as the lens coating type and magnification, to ensure the completeness and accuracy of the parameter information. Based on a preset defect type-objective parameter-parameter configuration correspondence table, the appropriate light intensity and exposure time values ​​are queried according to the identified defect type and actual objective lens parameters to ensure that the imaging device can clearly capture defect details under these parameters. Simultaneously, the initial direction of focus movement is set to positive, i.e., the direction of movement towards the panel. Referring to industry-standard initial step size and combining it with the objective lens magnification, the initial focus motion parameters are adjusted to clarify the parameters.

[0030] Step 208: Set the initial value of the highest score parameter to 0, and set the initial position corresponding to the highest score as the focus start position.

[0031] In this embodiment, since no multi-round focus scoring comparison has been performed and there is no historical highest score reference, the initial value of the highest score parameter is uniformly set to 0 as the benchmark threshold for subsequent scoring comparison. The focus starting position is defined as the current physical coordinate position of the imaging device, and this position is recorded as the initial position corresponding to the highest score. After each subsequent round of focus is completed, the highest score and the corresponding position information are updated by comparing with the current score, providing an initial basis for the termination judgment of autofocus.

[0032] Please see Figure 3 A schematic diagram of a third embodiment of the image processing-based autofocus method provided in this invention, the method comprising: Step 301: Obtain the last score, last position, current focus score, current position, highest score, highest score position, and current step size, while collecting defect type labels and historical focus score sequences; In this embodiment, the previous score is the final score result obtained from the previous round of focus calculation, the previous position is the physical coordinate position corresponding to the previous round of focus, the current focus score is the focus score obtained by feature weighting calculation in this round, the current position is the physical coordinate position of this focus, the highest score is the highest score recorded in all historical focus rounds, the highest score position is the physical coordinate corresponding to the highest score, and the current step size is the distance unit of focus movement in the current round; the defect type label must clearly indicate the specific category of the defect to be identified, and the historical focus score sequence must collect the focus scores of the most recent 3 times.

[0033] Step 302: Determine if the previous score was 0. If so, determine the first score calculation without adjusting the direction or step size. In this embodiment, the value of the previous score is confirmed by numerical comparison. If the result is 0, it means that this is the first time to perform focus score calculation and no effective historical score comparison basis has been formed. According to the preset rules, there is no need to start the subsequent movement direction adjustment and step size adjustment process. The current stage is directly ended and the next round of image acquisition and focus score calculation steps is started.

[0034] Step 303: If it is not 0, input the historical focus score sequence into the GRU module. Through the synergistic effect of the reset gate and the update gate, generate a hidden state vector that fuses the temporal dependence and capture the historical score change trend. In this embodiment, after the GRU module receives the historical focus scoring sequence, the reset gate dynamically adjusts the information retention ratio of the previous hidden state according to the input scoring data and discards irrelevant and redundant information; the update gate controls the fusion weight of the current input scoring information and the previous hidden state information to achieve effective transmission of temporal information; after two rounds of gating mechanism screening and integration, a hidden state vector that can reflect the historical scoring change pattern is finally generated. This vector integrates the scoring correlation features in the temporal dimension.

[0035] Step 304: Concatenate the hidden state vector, last score, last position, current focus score, current position, highest score, highest score position, current step size, and defect type label in sequence to form a high-dimensional input vector; In this embodiment, the defect type label is converted into a one-hot encoded vector to ensure that it is consistent with other numerical data formats. Then, in the order of hidden state vector → last score → last position → current focus score → current position → highest score → highest score position → current step size → defect type one-hot encoded vector, all data are dimensionally aligned and concatenated to finally form a high-dimensional input vector that meets the input dimension requirements of the improved DQN network.

[0036] Step 305: Input the high-dimensional input vector into the DQN algorithm, calculate the Q value, and select the action with the largest Q value as the initial proposed action of DQN; In this embodiment, the high-dimensional input vector is first fed into the convolutional layer of the improved DQN network for feature depth extraction and dimension mapping; then it is converted into a fixed-dimensional feature vector through a fully connected layer; subsequently, Gaussian noise is introduced through a NoisyLinear layer to optimize action exploration capability, and the state value and action advantage value are decomposed through the Dueling module; finally, the Q value corresponding to all candidate actions is calculated, and the action with the largest Q value is selected. This action includes the initial proposed movement direction and the initial proposed step size adjustment coefficient, which is used as the initial proposed action of DQN.

[0037] In this embodiment, the high-dimensional input vector The input to the DQN algorithm is processed sequentially through convolutional layers and fully connected layers, and then fed into the NoisyLinear layer to calculate the weights of the NoisyLinear layer. and bias And calculate the output of the NoisyLinear layer. : in, , This represents the learnable mean parameter. , This represents the learnable standard deviation parameter. , ⊙ represents Gaussian noise, and ⊙ represents element-wise multiplication. The output of the NoisyLinear layer is passed to the Dueling module, and the Q value is calculated using the following formula: in, Represents the state value function. Represents the action advantage function. This represents the mean of the action advantage value. Indicates the current state. Indicates a candidate action.

[0038] In this embodiment, the reward value of the environment feedback is calculated, the experience tuple is stored in the experience replay pool, and when the number of samples in the experience replay pool reaches a preset threshold, a batch of samples is randomly sampled, the loss function is calculated based on the TD objective, and all learnable parameters of the DQN network are updated by gradient descent.

[0039] Step 306: Calculate the ratio of the current focus score to the previous score. If the ratio is greater than or equal to 5, the step size is halved. If the ratio is less than 5, the step size is adjusted according to the DQN initial suggested action. In this embodiment, the ratio is calculated by dividing the current focus score by the previous score, and the result is rounded to two decimal places. If the ratio is greater than or equal to 5, the preset step size adjustment rule is triggered, and the current step size is directly divided by 2 to obtain the temporary step size. If the ratio is less than 5, the fixed step size adjustment rule is not executed, and the current step size is multiplied by the step size adjustment coefficient in the DQN initial suggested action to obtain the temporary step size.

[0040] Step 307: If the current focus score is less than the previous score, the movement direction is set to negative, and the step size is halved again to obtain the final step size. If the current focus score is greater than the previous score, the movement direction remains positive, and the step size remains unchanged. In this embodiment, the current focus score is compared with the previous score. If the current focus score is less than the previous score, it means that the current movement direction deviates from the optimal focus position. The movement direction is set to negative, that is, opposite to the previous movement direction. The temporary step size obtained in step 306 is divided by 2 again to determine the final step size. If the current focus score is greater than the previous score, it means that the current movement direction is towards the optimal focus position. The positive movement direction is maintained. The temporary step size obtained in step 306 is directly used as the final step size, thus clarifying the final movement direction and the final step size.

[0041] Step 308: Move to the new position according to the final step length and final direction of movement, acquire the focus image at the new position, and calculate the new focus score; In this embodiment, the final movement direction and final step size are converted into displacement control commands and sent to the displacement stage control system to move to the corresponding new physical position. After the movement is completed, the image acquisition device is activated to align with the defect area of ​​the new position and acquire a complete, unobstructed focus image. The image is then subjected to ROI region adaptive extraction and Gaussian filtering denoising processing. The mean of the Laplacian operator, the image variance, and the mean of the gradient magnitude of the ROI region are calculated. Finally, the focus score of the new position is obtained by feature weighted summation, i.e., the new focus score.

[0042] Step 309: Compare the new focus score, the previous score, and the highest score. Assign the score with the largest value to the highest score and assign the position corresponding to the highest score to the highest score position.

[0043] In this embodiment, the new focus score obtained in step 308, the previous score recorded in the previous round, and the historically accumulated highest score are compared and sorted in descending order; the score with the largest value after sorting is selected and updated as the new highest score; at the same time, the physical location corresponding to the highest score is found, the new focus score corresponds to the new location, the previous score corresponds to the previous location, and the original highest score corresponds to the original highest score location, and this location is updated as the new highest score location, thus completing the update operation of the highest score and its corresponding location.

[0044] Please see Figure 4 A schematic diagram of an image processing-based autofocus device provided in an embodiment of the present invention, the device comprising: The initialization module 401 is used to perform defect identification on the original panel image using the MobileNetV3 network, and to set the light intensity, exposure time, initial direction and initial step size according to the defect type and objective lens parameters, and initialize the highest score and corresponding position. The calculation module 402 is used to acquire the defect location image, adaptively extract the ROI region and filter and denoise, and calculate the Laplacian operator mean, image variance and gradient magnitude mean of the ROI region. The weighted summation module 403 is used to assign feature weights based on defect type using the ResNet18 network, and to obtain the current focus score by weighted summation based on the mean of the Laplacian operator, the image variance, and the mean of the gradient magnitude. The update module 404 is used to adjust the movement direction and step size based on the DQN algorithm and the comparison between the current focus score and the historical focus score, and update the highest score and its corresponding position. The focusing module 405 is used to terminate focusing and lock the optimal focusing position when the step size is less than or equal to 0.25μm, if the current position is the highest score position or the distance to the highest score position is less than or equal to 0.25μm.

[0045] Figure 5 This is a schematic diagram of the structure of an image processing-based autofocus device 600 provided in an embodiment of the present invention. The image processing-based autofocus device 600 can vary significantly due to different configurations or performance characteristics. It may include one or more central processing units (CPUs) 610 (e.g., one or more processors) and a memory 620, and one or more storage media 630 (e.g., one or more mass storage devices) storing application programs 633 or data 632. The memory 620 and storage media 630 can be temporary or persistent storage. The program stored in the storage media 630 may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the image processing-based autofocus device 600. Furthermore, the processor 610 may be configured to communicate with the storage media 630 and execute the series of instruction operations in the storage media 630 on the image processing-based autofocus device 600 to implement the method provided in the above embodiment.

[0046] The image processing-based autofocus device 600 may also include one or more power supplies 640, one or more wired or wireless network interfaces 650, one or more input / output interfaces 660, and / or one or more operating systems 631, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that... Figure 5 The image processing-based autofocus device structure shown does not constitute a limitation on the computer device provided by the present invention. It may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0047] The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions that, when executed on a computer, cause the computer to perform the various steps of the image processing-based autofocus method provided in the above embodiments.

[0048] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described equipment or apparatus / unit can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0049] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0050] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. An autofocus method based on image processing, characterized in that, The image processing-based autofocus method includes: The MobileNetV3 network is used to identify defects in the original panel image. Based on the defect type and objective lens parameters, the light intensity, exposure time, initial direction and initial step size are set, and the highest score and corresponding position are initialized. The defect location image is acquired, and the ROI region is adaptively extracted and filtered for noise reduction. The mean of the Laplacian operator, the image variance, and the mean of the gradient magnitude of the ROI region are calculated. The ResNet18 network is used to assign feature weights based on defect type, and the current focus score is obtained by weighted summation based on the mean of the Laplacian operator, image variance, and mean of gradient magnitude. Based on the DQN algorithm, the current focus score is compared with the historical focus scores to adjust the movement direction and step size, and update the highest score and corresponding position. When the step size is less than or equal to 0.25μm, if the current position is the highest score position or the distance to the highest score position is less than or equal to 0.25μm, focus is terminated and the optimal focus position is locked.

2. The autofocus method based on image processing as described in claim 1, characterized in that, The process involves using a MobileNetV3 network to identify defects in the original panel image, and setting the light intensity, exposure time, initial direction, and initial step size based on the defect type and objective lens parameters, as well as initializing the highest score and its corresponding position. The original panel image to be processed is obtained, and the wavelet transform algorithm is used to enhance the original panel image. The enhanced panel image is input into the MobileNetV3 network and upscaled using 1×1 convolutional kernels. The feature information dimension of the image is expanded according to the preset number of output feature map channels. A 3×3 depthwise separable convolution operation is performed on the upgraded feature map to extract preliminary defect features from the image. The initial defect features are fed into the inverse residual structure, which then undergoes global pooling and two fully connected layer operations to automatically assign weights to different feature channels. The weighted feature map is reduced in dimension by using a 1×1 pointwise convolution module to obtain the dimension-reduced defect feature vector. The defect feature vector is input into a classifier consisting of positive Lagrange multipliers, which classifies and determines the defect type. Based on the identified defect type and objective lens parameters, select the light intensity and exposure time values ​​that are suitable for the current scene, and set the initial direction and initial step size for focus movement. Set the initial value of the highest score parameter to 0, and set the initial position corresponding to the highest score as the focus start position.

3. The image processing-based autofocus method as described in claim 2, characterized in that, The process of acquiring the original panel image to be processed and enhancing the original panel image using a wavelet transform algorithm includes: Perform on the original panel image Layer wavelet decomposition operation decomposes the image into layers. The low-frequency and high-frequency coefficients corresponding to the layer; Regarding the first The low-frequency coefficients of the layer determine the image pixel coordinates corresponding to each low-frequency coefficient in the current layer. And extract the two different dimensional components corresponding to the low-frequency coefficient. and ,in j The value range is 1 to ; The wavelet coefficient amplitude of the low-frequency coefficients is calculated using the following formula. : in, Indicates the original panel image in coordinates Pixel value at; Introducing a nonlinear function to adjust the argument of the calculated wavelet coefficients Adjustments are made, and the adjusted argument is denoted as... The expression for the nonlinear function is: in, Indicates the adjustment operator, Indicates the brightness coefficient. Indicates the wavelet threshold. Indicates the current number Low-frequency coefficient values ​​of the layer; Calculate parameters according to the formula. ,by As an enhancement function: in, Used to control the scaling ratio of molecules. For constant bias terms; Compare the enhancement function with the current [number]. The wavelet coefficients corresponding to the low-frequency coefficients in the layer are multiplied to obtain the adjusted low-frequency coefficients. The high-frequency coefficients of each layer after wavelet decomposition are kept unchanged. Combined with all the adjusted low-frequency coefficients, the inverse wavelet transform reconstruction operation is performed to obtain the enhanced panel image.

4. The image processing-based autofocus method as described in claim 1, characterized in that, The process of acquiring the defect location image, adaptively extracting the Region of Interest (ROI) and filtering for noise reduction, and calculating the Laplacian operator mean, image variance, and gradient magnitude mean of the ROI region includes: The defect location image is converted into a grayscale image to obtain the coordinate information of the defect region and determine the bounding box coordinates of the defect region. Calculate the width and height of the defect region's bounding box. If the width or height is greater than 640, then use the geometric center of the defect region's bounding box as a reference and truncate it to 640. A 640-pixel square area is designated as the Region of Interest (ROI). If the width is less than or equal to 640 and the height is less than or equal to 40, then the area of ​​the ROI is expanded by 10% pixels in all directions based on the bounding box of the defect area. Iterate through each pixel of the extracted ROI grayscale image, multiply the current pixel and its 8 neighboring pixels by the weights corresponding to the Gaussian kernel, calculate the sum of all products, and replace the grayscale value of the current pixel with the sum to complete noise filtering; The Laplacian operator is used to perform edge detection on the denoised ROI grayscale image to obtain an edge image containing positive and negative values. The value of each pixel in the edge image is converted into an absolute value, and then the arithmetic mean of the absolute values ​​of all pixels is calculated to obtain the Laplacian operator mean. Iterate through all pixels of the denoised ROI grayscale image, calculate the arithmetic mean of all pixel grayscale values, then calculate the difference between each pixel's grayscale value and the arithmetic mean, square each difference to obtain a set of squared differences, and calculate the arithmetic mean of all elements in the set of squared differences to obtain the image variance. The formula is: in, This represents the height (in pixels) of the denoised ROI grayscale image. This represents the width in pixels of the denoised ROI grayscale image. Indicates the ROI region number Line number The grayscale value of the column pixels, This represents the arithmetic mean of the grayscale values ​​of all pixels. Using a 3×3 kernel Sobel operator, gradient operators in the X and Y directions are constructed respectively. This is done by combining each pixel in the denoised ROI grayscale image with its neighboring pixels. The window is convolved with the gradient operators in the X and Y directions respectively to obtain the gradient values ​​in the X and Y directions. The gradient magnitude of the current pixel is obtained based on the gradient values ​​in the X and Y directions, and the arithmetic mean of the gradient magnitudes of all pixels is calculated to determine the average gradient magnitude.

5. The image processing-based autofocus method as described in claim 1, characterized in that, The process involves using a ResNet18 network to assign feature weights based on defect type, and then weighting and summing the results based on the Laplacian operator mean, image variance, and gradient magnitude mean to obtain the current focus score. This includes: One-hot coding is used to digitize the defect type, and the defect type coding vector and three feature values, namely the mean of the Laplacian operator, the image variance, and the mean of the gradient magnitude, are normalized. The normalized defect type encoding vector and the three normalized feature values ​​are concatenated to form the input vector of the ResNet18 network. The input vector is fed into the input layer of the ResNet18 network, and then passes through the network's convolutional layer, batch normalization layer and ReLU activation function in sequence to perform feature extraction and nonlinear transformation on the input vector; The processed feature vector is input into a global average pooling layer for dimensionality reduction, and then input into a fully connected layer. Through linear transformation, the feature dimension is mapped to 3 dimensions to obtain the initial weight vector. The initial weight vector is input into the Softmax activation function, and the elements of the initial weight vector are normalized to obtain the weight coefficients corresponding to the Laplacian operator mean, the image variance, and the gradient magnitude mean. The current focus score is calculated by weighting the weight coefficients corresponding to the Laplacian operator mean, the image variance, and the gradient magnitude mean.

6. The image processing-based autofocus method as described in claim 1, characterized in that, The DQN-based algorithm adjusts the movement direction and step size based on a comparison between the current focus score and historical focus scores, and updates the highest score and its corresponding position, including: Get the last score, last position, current focus score, current position, highest score, highest score position, and current step size, and collect defect type labels and historical focus score sequences at the same time; Determine if the previous score was 0. If so, determine the first score calculation without adjusting the direction or step size. If it is not 0, the historical focus score sequence is input into the GRU module. Through the synergistic effect of the reset gate and the update gate, a hidden state vector with fused temporal dependence is generated to capture the historical score change trend. The hidden state vector, the previous score, the previous position, the current focus score, the current position, the highest score, the highest score position, the current step size, and the defect type label are concatenated in sequence to form a high-dimensional input vector. The high-dimensional input vector is input into the DQN algorithm, the Q value is calculated, and the action with the largest Q value is selected as the initial proposed action of DQN. Calculate the ratio of the current focus score to the previous score. If the ratio is greater than or equal to 5, the step size is halved. If the ratio is less than 5, the step size is adjusted according to the DQN initial suggested action. If the current focus score is less than the previous score, the movement direction is set to negative, and the step size is halved again to obtain the final step size. If the current focus score is greater than the previous score, the movement direction remains positive, and the step size remains unchanged. Move to a new position based on the final step size and final direction of movement, acquire a focus image at the new position, and calculate a new focus score; Compare the new focus score, the previous score, and the highest score. Assign the score with the largest value to the highest score and assign the position corresponding to the highest score to the highest score position.

7. The image processing-based autofocus method as described in claim 6, characterized in that, The step of inputting a high-dimensional input vector into the DQN algorithm, calculating the Q-value, and selecting the action with the largest Q-value as the initial proposed action for DQN includes: high-dimensional input vector The input to the DQN algorithm is processed sequentially through convolutional layers and fully connected layers, and then fed into the NoisyLinear layer to calculate the weights of the NoisyLinear layer. and bias And calculate the output of the NoisyLinear layer. : in, , This represents the learnable mean parameter. , This represents the learnable standard deviation parameter. , ⊙ represents Gaussian noise, and ⊙ represents element-wise multiplication. The output of the NoisyLinear layer is passed to the Dueling module, and the Q value is calculated using the following formula: in, Represents the state value function. Represents the action advantage function. This represents the mean of the action advantage value. Indicates the current state. Indicates a candidate action.

8. An autofocus device based on image processing, characterized in that, The image processing-based autofocus device includes: The initialization module is used to identify defects in the original panel image using the MobileNetV3 network, and to set the light intensity, exposure time, initial direction and initial step size according to the defect type and objective lens parameters, and initialize the highest score and corresponding position. The calculation module is used to acquire defect location images, adaptively extract ROI regions and filter and denoise, and calculate the mean of the Laplacian operator, image variance and mean gradient magnitude of the ROI region. The weighted summation module is used to assign feature weights based on defect type using the ResNet18 network, and to obtain the current focus score by weighted summation based on the mean of the Laplacian operator, the image variance, and the mean of the gradient magnitude. The update module is used to adjust the movement direction and step size based on the DQN algorithm, comparing the current focus score with the historical focus scores, and to update the highest score and its corresponding position. The focusing module is used to terminate focusing and lock the optimal focusing position when the step size is less than or equal to 0.25μm, if the current position is the highest score position or the distance to the highest score position is less than or equal to 0.25μm.

9. An autofocus device based on image processing, characterized in that, The image processing-based autofocus device includes a memory and at least one processor, the memory storing instructions; the at least one processor invokes the instructions in the memory to cause the image processing-based autofocus device to perform the steps of the image processing-based autofocus method as described in any one of claims 1-7.

10. A computer-readable storage medium storing instructions thereon, characterized in that, When the instructions are executed by the processor, they implement the steps of the image processing-based autofocus method as described in any one of claims 1-7.