An infrared thermal imager automatic focusing method and system based on image sharpness evaluation

By constructing a temperature intensity field and calculating pixel-level two-dimensional gradient magnitude and direction, dividing directional channels, extracting clear and blurry candidate regions, and combining multi-dimensional gradient features for iterative optimization, the problem of inaccurate focal length positioning in the autofocusing of infrared thermal imagers is solved, thus improving imaging quality and stability.

CN122149648APending Publication Date: 2026-06-05JIANGXI HONGTAI ELECTRIC POWER IND & TRADE CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
JIANGXI HONGTAI ELECTRIC POWER IND & TRADE CO LTD
Filing Date
2026-04-17
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Existing automatic focusing methods for infrared thermal imagers fail to delve into the pixel-level two-dimensional gradient direction distribution and lack multi-scale adaptation and global topological relationships, resulting in flat-top or multi-peak evaluation curves that make it difficult to accurately locate the optimal focal length.

Method used

By constructing a temperature intensity field, calculating pixel-level two-dimensional gradient magnitude and direction, dividing directional channels, statistically analyzing gradient energy density, extracting clear and blurred candidate regions, and combining directional dispersion, tangential continuity, and cross-scale preservation, adjusting the local window size and the number of directional channels, iterative calculations are performed to determine the optimal focal length.

Benefits of technology

It has improved the precision, stability and imaging quality of infrared thermal imagers, accurately distinguished the clear area, transition area and blurry area, and enhanced the reliability and anti-interference ability of focus assessment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122149648A_ABST
    Figure CN122149648A_ABST
Patent Text Reader

Abstract

The application provides an infrared thermal imager automatic focusing method and system based on image sharpness evaluation, which comprises the following steps: obtaining a thermal image sequence with different focal lengths, correcting and constructing a temperature intensity field, calculating a two-dimensional gradient amplitude and direction of pixels, mapping and dividing a direction channel, counting a local window gradient energy density, extracting a clear and fuzzy candidate area, calculating a direction dispersion, a tangent continuity and a cross-scale retention, dividing a clear area, a transition area and a fuzzy area through an evaluation model, calculating an initial focus point evaluation value, iteratively updating the evaluation value, optimizing the evaluation value in combination with an area ratio, a spatial distribution and a boundary contact degree, determining a candidate focal length interval through differential analysis, positioning an optimal focal length according to a zero-crossing condition of an evaluation value change rate, driving a focusing mechanism to realize automatic focusing and improving infrared thermal image focusing accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of infrared thermal imagers, and in particular relates to an automatic focusing method and system for infrared thermal imagers based on image sharpness evaluation. Background Technology

[0002] In practical applications of infrared thermal imaging systems, acquiring clear, high-contrast thermal images is a prerequisite for subsequent target detection and accurate temperature measurement, and autofocus technology is the core element in achieving this goal. However, compared to visible light images, infrared thermal images represent the thermal radiation distribution of objects, inherently possessing limitations such as low contrast, blurred edges, lack of texture detail, and a relatively low signal-to-noise ratio. Traditional autofocus methods often rely on a global image sharpness evaluation function combined with hill-climbing search algorithms. Due to the lack of rich texture and the frequent presence of large areas of background interference, the changes in global gradient magnitude are often not drastic enough, leading to flat-top phenomena or multi-peak local optima in traditional sharpness evaluation curves. This makes it difficult for the focusing mechanism to accurately locate the optimal focal length, thus limiting the imaging quality and focusing efficiency of infrared thermal imagers in complex scenes.

[0003] Most existing methods focus only on the magnitude of the gradient, neglecting the differences in pixel-level two-dimensional gradient direction distribution between focused and defocused states. They fail to delve into directional structural features such as dispersion and tangential continuity, leading to inaccurate differentiation between sharp and blurred areas. Existing evaluation models typically employ fixed-size local windows and single-scale analysis strategies, unable to adjust to changes in target scale within infrared scenes, and prone to feature extraction bias when facing multi-scale heat sources. Furthermore, existing focus evaluation mechanisms often treat sharp and blurred areas in isolation, lacking the ability to utilize global topological relationships such as area ratio, spatial distribution, and boundary contact. These shortcomings result in insufficient sensitivity in the constructed evaluation curves of existing focusing methods, especially in deep depth-of-field or complex temperature fields. They cannot guarantee the unimodality and steepness of the evaluation curve, causing inaccurate positioning of candidate focal length ranges and repeated oscillations in focusing actions, failing to meet the requirements for high-precision and highly adaptable infrared autofocus. Summary of the Invention

[0004] To address the problem that existing technologies, due to neglecting gradient direction distribution, lack of multi-scale adaptation, and global topological relationships, result in flat-top or multi-peak evaluation curves, making it difficult to accurately locate the optimal focal length.

[0005] In the first aspect, this disclosure provides an automatic focusing method for an infrared thermal imager based on image sharpness evaluation, comprising: The thermal image sequences at each focal length position are obtained and corrected to construct a temperature intensity field. The pixel-level two-dimensional gradient magnitude and two-dimensional gradient direction are calculated. The two-dimensional gradient direction is mapped and divided into a preset number of directional channels. The gradient energy density of each directional channel is statistically analyzed within a local window. Based on the difference in gradient energy density between the center and the ring of the local window, clear candidate regions are extracted. Based on the distribution dispersion between relative directional channels, blurred candidate regions are extracted. For clear and blurred candidate regions, calculate directional dispersion, tangential continuity, and cross-scale retention. Input the directional dispersion, tangential continuity, and cross-scale retention into the evaluation model to divide the thermal image into clear, transition, and blurred regions. Calculate the initial focus evaluation value based on the directional concentration in the clear region and the directional diffusion in the blurred region. Iteratively calculate and update the initial focus evaluation value by adjusting the local window size and the number of directional channels based on the cross-scale retention. The initial focus evaluation value is adjusted by combining the area ratio, spatial distribution and boundary contact degree of the clear area and the blurred area to obtain the adjusted evaluation value. Differential analysis is performed on the adjusted evaluation value of each focal length position to determine the candidate focal length interval. The evaluation value change rate is calculated within the candidate focal length interval. The focal length position where the evaluation value change rate meets the zero crossing condition is output to the focusing mechanism to complete the automatic focusing of the infrared thermal imager.

[0006] Further, the calculation of pixel-level two-dimensional gradient magnitude and two-dimensional gradient direction, mapping and dividing the two-dimensional gradient direction into a preset number of direction channels, and statistically analyzing the gradient energy density of each direction channel within a local window includes: The temperature intensity field is convolved using horizontal and vertical difference operators to obtain horizontal and vertical gradient components, respectively. The pixel-level two-dimensional gradient magnitude is calculated based on the square root of the sum of the squares of the horizontal and vertical gradient components, and the two-dimensional gradient direction is calculated based on the arctangent function of both. The gradient direction from 0 to 360° is divided into a preset number of directional channels, and the gradient direction of each pixel is assigned to the corresponding directional channel. Within a local window, the gradient magnitudes of pixels belonging to the same directional channel are accumulated to obtain the gradient energy density of each directional channel.

[0007] Furthermore, the extraction of sharp candidate regions based on the gradient energy density difference between the center and the annulus of the local window, and the extraction of fuzzy candidate regions based on the distribution dispersion between channels in relative directions, includes: The local window is divided into a central sub-region and an annular region surrounding the central sub-region, and the average gradient energy density of all directional channels within each sub-region is calculated. When the average gradient energy density difference between the central sub-region and the annular region is greater than the first threshold, the local window is marked as a clear candidate region. For local windows that are not marked as clear candidate regions, calculate the variance of gradient energy density between channels with relative directions that are 180° apart. When the variance is less than the second threshold and the sum of gradient energy densities is greater than the noise threshold, the local window is marked as a fuzzy candidate region.

[0008] Furthermore, the calculation of directional dispersion, tangential continuity, and cross-scale preservation for the sharp candidate region and the blurred candidate region, and the input of the directional dispersion, tangential continuity, and cross-scale preservation into the evaluation model to divide the thermal image into a sharp region, a transition region, and a blurred region, includes: Calculate directional dispersion based on the information entropy of the energy density of channel gradients in each direction; The connectivity length of the gradient magnitude of adjacent pixels is calculated along the edge direction perpendicular to the main gradient direction as the tangential continuity. Calculate the correlation coefficient of local window gradient energy density at adjacent scales as the cross-scale preservation factor; The directional dispersion, tangential continuity, and cross-scale preservation are input into the evaluation model, and the output is a region state discrimination value. When the region state discrimination value is greater than the first discrimination threshold, it is classified as a clear region; when it is less than the second discrimination threshold, it is classified as a blurred region; and when it is in between, it is classified as a transition region.

[0009] Further, the calculation of the initial focus evaluation value based on the directional concentration of the clear area and the directional diffusion of the blurred area includes: Extract the main directional channel with the highest gradient energy density within the clear region, and calculate the ratio of the energy of the main directional channel to the total energy of all directional channels as the directional concentration. Within the fuzzy region, the ratio of the mean to the maximum value of the gradient energy density of all directional channels, plus a preset constant, is used as the directional diffusion degree. The initial focus evaluation value is obtained by subtracting the weighted sum of the directional dispersion of all blurred areas from the sum of the directional concentration of all sharp areas in the current frame.

[0010] Further, the step of adjusting the initial focus evaluation value by combining the area ratio, spatial distribution, and boundary contact degree of the sharp area and the blurred area to obtain the adjusted evaluation value includes: The ratio obtained by dividing the total area of ​​the clear area by the sum of the total area of ​​the blurred area and a preset constant is used as the area ratio coefficient; Calculate the average Euclidean distance between the centroid of each sharp region and the image center, and construct a spatial distribution attenuation weight based on the average value; The number of boundary pixels adjacent to the clear area and the blurred area is counted, and the proportion of the number to the total boundary of the clear area is calculated as the boundary contact penalty coefficient. The initial focus evaluation value is multiplied sequentially by the area ratio coefficient and the spatial distribution attenuation weight, and the compensation term determined by the boundary contact penalty coefficient is subtracted to obtain the adjusted evaluation value.

[0011] On the other hand, this disclosure provides an automatic focusing system for infrared thermal imagers based on image sharpness evaluation, including the following modules: The acquisition module is used to acquire thermal image sequences at each focal length position, correct them to construct a temperature intensity field, calculate pixel-level two-dimensional gradient magnitude and two-dimensional gradient direction, map the two-dimensional gradient direction and divide it into a preset number of directional channels, count the gradient energy density of each directional channel within a local window, extract clear candidate regions based on the difference in gradient energy density between the center and the ring of the local window, and extract blurred candidate regions based on the distribution dispersion between relative directional channels. The calculation module is used to calculate the directional dispersion, tangential continuity, and cross-scale retention for clear and blurred candidate regions. The directional dispersion, tangential continuity, and cross-scale retention are input into the evaluation model to divide the thermal image into clear, transition, and blurred regions. The initial focus evaluation value is calculated based on the directional concentration in the clear region and the directional diffusion in the blurred region. The initial focus evaluation value is updated by iteratively calculating and adjusting the local window size and the number of directional channels based on the cross-scale retention. The output module is used to adjust the initial focus evaluation value by combining the area ratio, spatial distribution and boundary contact degree of the clear area and the blurred area to obtain the adjusted evaluation value, perform differential analysis on the adjusted evaluation value of each focal length position to determine the candidate focal length interval, calculate the evaluation value change rate in the candidate focal length interval, and output the focal length position where the evaluation value change rate meets the zero crossing condition to the focusing mechanism to complete the automatic focusing of the infrared thermal imager.

[0012] Preferably, the step of calculating the pixel-level two-dimensional gradient magnitude and direction, mapping and dividing the two-dimensional gradient direction into a preset number of directional channels, and calculating the gradient energy density of each directional channel within a local window includes: The temperature intensity field is convolved using horizontal and vertical difference operators to obtain horizontal and vertical gradient components, respectively. The pixel-level two-dimensional gradient magnitude is calculated based on the square root of the sum of the squares of the horizontal and vertical gradient components, and the two-dimensional gradient direction is calculated based on the arctangent function of both. The gradient direction from 0 to 360° is divided into a preset number of directional channels, and the gradient direction of each pixel is assigned to the corresponding directional channel. Within a local window, the gradient magnitudes of pixels belonging to the same directional channel are accumulated to obtain the gradient energy density of each directional channel.

[0013] Preferably, the step of extracting sharp candidate regions based on the gradient energy density difference between the center and the annulus of the local window, and extracting fuzzy candidate regions based on the distribution dispersion between channels in relative directions, includes: The local window is divided into a central sub-region and an annular region surrounding the central sub-region, and the average gradient energy density of all directional channels within each sub-region is calculated. When the average gradient energy density difference between the central sub-region and the annular region is greater than the first threshold, the local window is marked as a clear candidate region. For local windows that are not marked as clear candidate regions, calculate the variance of gradient energy density between channels with relative directions that are 180° apart. When the variance is less than the second threshold and the sum of gradient energy densities is greater than the noise threshold, the local window is marked as a fuzzy candidate region.

[0014] Preferably, the step of calculating the directional dispersion, tangential continuity, and cross-scale preservation for the clear candidate region and the blurred candidate region, and inputting the directional dispersion, tangential continuity, and cross-scale preservation into the evaluation model to divide the thermal image into clear regions, transition regions, and blurred regions includes: Calculate directional dispersion based on the information entropy of the energy density of channel gradients in each direction; The connectivity length of the gradient magnitude of adjacent pixels is calculated along the edge direction perpendicular to the main gradient direction as the tangential continuity. Calculate the correlation coefficient of local window gradient energy density at adjacent scales as the cross-scale preservation factor; The directional dispersion, tangential continuity, and cross-scale preservation are input into the evaluation model, and the output is a region state discrimination value. When the region state discrimination value is greater than the first discrimination threshold, it is classified as a clear region; when it is less than the second discrimination threshold, it is classified as a blurred region; and when it is in between, it is classified as a transition region.

[0015] Preferably, the calculation of the initial focus evaluation value based on the directional concentration of the clear area and the directional diffusion of the blurred area includes: Extract the main directional channel with the highest gradient energy density within the clear region, and calculate the ratio of the energy of the main directional channel to the total energy of all directional channels as the directional concentration. Within the fuzzy region, the ratio of the mean to the maximum value of the gradient energy density of all directional channels, plus a preset constant, is used as the directional diffusion degree. The initial focus evaluation value is obtained by subtracting the weighted sum of the directional dispersion of all blurred areas from the sum of the directional concentration of all sharp areas in the current frame.

[0016] Preferably, the step of adjusting the initial focus evaluation value by combining the area ratio, spatial distribution, and boundary contact degree of the sharp area and the blurred area to obtain the adjusted evaluation value includes: The ratio obtained by dividing the total area of ​​the clear area by the sum of the total area of ​​the blurred area and a preset constant is used as the area ratio coefficient; Calculate the average Euclidean distance between the centroid of each sharp region and the image center, and construct a spatial distribution attenuation weight based on the average value; The number of boundary pixels adjacent to the clear area and the blurred area is counted, and the proportion of the number to the total boundary of the clear area is calculated as the boundary contact penalty coefficient. The initial focus evaluation value is multiplied sequentially by the area ratio coefficient and the spatial distribution attenuation weight, and the compensation term determined by the boundary contact penalty coefficient is subtracted to obtain the adjusted evaluation value.

[0017] This invention constructs a temperature intensity field and calculates pixel-level two-dimensional gradient magnitude and direction. By statistically analyzing the gradient energy density of each directional channel within a local window, it can deeply explore the multi-dimensional gradient features of infrared images, thereby accurately extracting clear and blurred candidate regions. By comprehensively calculating directional dispersion, tangential continuity, and cross-scale preservation, the thermal image is accurately divided into clear, transitional, and blurred regions. Initial evaluation values ​​are obtained based on the directional concentration and diffusion of each region. Iterative optimization is performed by adjusting the window size and number of channels based on cross-scale characteristics, enhancing the reliability and anti-interference capability of focus assessment. The evaluation values ​​are adjusted using the spatial distribution, area ratio, and boundary contact degree between clear and blurred regions. Combined with differential analysis and zero-crossing conditions, the optimal focal length position is locked, improving the accuracy, stability, and imaging quality of infrared thermal imager focusing. Attached Figure Description

[0018] Figure 1 This is a flowchart of an automatic focusing method for infrared thermal imagers based on image sharpness evaluation; Figure 2 A schematic diagram of the physical response of multi-directional energy channel distribution in a two-dimensional space of a pixel; Figure 3 A schematic diagram of scatter projection of clear classification decision features for local sliding overlapping windows. Detailed Implementation

[0019] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0020] In the first embodiment, the present invention proposes an automatic focusing method for infrared thermal imagers based on image sharpness evaluation, such as... Figure 1 As shown, it includes: S1. Acquire thermal image sequences at each focal length position and perform correction to construct a temperature intensity field. Calculate pixel-level two-dimensional gradient magnitude and two-dimensional gradient direction. Map the two-dimensional gradient direction and divide it into a preset number of directional channels. Statistically calculate the gradient energy density of each directional channel within a local window. Extract clear candidate regions based on the difference in gradient energy density between the center and the ring of the local window. Extract blurred candidate regions based on the distribution dispersion between relative directional channels.

[0021] Through the infrared detector hardware interface, raw 14-bit infrared image sequences at different focal length positions controlled by multiple stepper motors are acquired. First, two-point non-uniformity correction is performed, followed by blind pixel removal using the cubic spline interpolation algorithm from the NumPy library, and smoothing using the cv2.medianBlur median filtering algorithm from the OpenCV library. The corrected grayscale values ​​are linearly mapped to the true temperature values ​​to construct a temperature intensity field. The cv2.Sobel operator from the OpenCV library is used to calculate the first-order partial derivatives in the horizontal and vertical directions, respectively. Then, the cv2.cartToPolar function is called to calculate the two-dimensional gradient magnitude and the two-dimensional gradient direction from 0 to 360 degrees for each pixel. The 360-degree directional space is linearly mapped at equal intervals and divided into N directional channels. For each pixel, an 11×11 local window is constructed. All pixels within the window are traversed, and the gradient magnitude is accumulated into the energy accumulator of the corresponding channel based on the directional channel index of each pixel, obtaining the gradient energy density of each directional channel. The local window is divided into a central region and an outer ring region. The difference between the average gradient energy density of the central region and the ring region across all directional channels is calculated. When the difference is greater than a preset threshold, the local window is marked as a clear candidate region. Simultaneously, the gradient energy density differences between relative directional channels within the local window that are 180 degrees apart are calculated. The variance of all relative directional channel differences is calculated as the distribution dispersion. Local windows with a variance less than the dispersion threshold are classified as blurry candidate regions.

[0022] In one possible embodiment, the calculation of pixel-level two-dimensional gradient magnitude and two-dimensional gradient direction, mapping and dividing the two-dimensional gradient direction into a preset number of direction channels, and calculating the gradient energy density of each direction channel within a local window includes: The temperature intensity field is convolved using horizontal and vertical difference operators to obtain horizontal and vertical gradient components, respectively. The pixel-level two-dimensional gradient magnitude is calculated based on the square root of the sum of the squares of the horizontal and vertical gradient components, and the two-dimensional gradient direction is calculated based on the arctangent function of both. The gradient direction from 0 to 360° is divided into a preset number of directional channels, and the gradient direction of each pixel is assigned to the corresponding directional channel. Within a local window, the gradient magnitudes of pixels belonging to the same directional channel are accumulated to obtain the gradient energy density of each directional channel.

[0023] A 3×3 Sobel operator is used, with the horizontal operator [-1,0,1; -2,0,2; -1,0,1] and the vertical operator [1,2,1; 0,0,0; -1,-2,-1] performing discrete two-dimensional convolution with the non-uniformity-corrected temperature intensity field, and the horizontal gradient component is extracted pixel by pixel. With vertical gradient components Using formulas Calculate the two-dimensional gradient magnitude M for each pixel, and simultaneously based on the arctangent function. Combined with four-quadrant positive and negative logic judgment, the obtained angle values ​​are linearly translated and mapped to the full circumferential range of 0 to 360 degrees. The complete directional space from 0 to 360 degrees is evenly divided into N directional channels at equal intervals. To balance computational resources and directional resolution, the number of channels N is preferably 16, that is, each directional channel is given an angular span of 22.5 degrees. For example, the angle range from 0 to 22.5 degrees is normalized and mapped to channel 0, and so on. A sliding local window with a spatial size preferably of 11×11 pixels is constructed in the entire thermal imaging area, and the image is scanned by traversing the overlapping sliding window with a step size of 1 pixel. Inside the infrared pixels defined by the current local window, a 16-dimensional floating-point energy array initialized to 0 is initialized. The pixels inside the window are traversed, the pre-allocated directional channel index of each pixel is extracted, and the gradient magnitude M is accumulated and mapped to the array memory slot of the corresponding index number. After all pixels are accumulated, the output is a 16-dimensional gradient energy density vector representing the convergence characteristics of local infrared high-frequency texture. The 16-dimensional gradient energy density distribution of a typical sharp region is as follows: Figure 2 As shown, the gradient energy is highly concentrated in a few main directional channels, exhibiting a single-peak towering feature, indicating the directional convergence of edge textures within a clear region.

[0024] In one possible embodiment, the extraction of sharp candidate regions based on the gradient energy density difference between the center and the annulus of the local window, and the extraction of blurred candidate regions based on the distribution dispersion between channels in relative directions, includes: The local window is divided into a central sub-region and an annular region surrounding the central sub-region, and the average gradient energy density of all directional channels within each sub-region is calculated. When the average gradient energy density difference between the central sub-region and the annular region is greater than the first threshold, the local window is marked as a clear candidate region. For local windows that are not marked as clear candidate regions, calculate the variance of gradient energy density between channels with relative directions that are 180° apart. When the variance is less than the second threshold and the sum of gradient energy densities is greater than the noise threshold, the local window is marked as a fuzzy candidate region.

[0025] For a local window with a spatial size of 11×11 pixels, a concentric matrix masking algorithm is used to divide the local window into two isolated blocks from the center outwards. A 5×5 pixel array at the very center is directly designated as the central sub-region, covering 25 pixels. The annular region remaining after removing the central sub-region from the overall 11×11 matrix is ​​designated as the annular zone region, covering 96 pixels. The absolute values ​​of the gradient energies of all pixels within the two isolated regions distributed across the 16 directional channels are summed, and then divided by the corresponding pixel base area to output the dimensionally normalized average energy of the central sub-region. and the average energy of the annular region In an uncooled infrared detector imaging scenario with 14-bit grayscale depth, a first threshold is pre-set to identify the boundary of abrupt changes in the real scene. The preferred value is 18.5. When determining the algebraic difference... When the value is strictly greater than 18.5, it indicates that the central block has sharp, high-contrast edge features. The memory state of this local window is then set to 1 and marked as a clear candidate region.

[0026] For those who failed For unlabeled local windows that have undergone threshold testing, gradient energy distribution matrices are extracted for 16 directional channels. An 8-group relative directional channel array, matched with an 8-channel index offset, is established using a phase difference constraint method. These arrays correspond to directions with an absolute phase difference of 180 degrees in space, such as 0 and 8, and 1 and 9. The sum of squares of the energy differences between each relative directional channel is calculated and divided by 8 to obtain the directional distribution variance. Subsequently, a dual-channel test is performed in parallel, and a second threshold is set to measure the divergence disorder characteristics. The preferred value is set to 5.0, which sets the noise threshold for suppressing false positive responses in a flat, temperature-difference-free background. The preferred value is 120.0. Only when the system detects that the variance of the distribution calculated for the current window is less than 5.0, and the sum of the local gradient energy densities obtained after adding all 16 channels is greater than the 120.0 noise threshold, is the current sub-block determined to be a defocused image feature area exhibiting blur spots, and marked as a blur candidate region. The scatter plot of candidate region classification based on the center-ring difference and relative direction variance is shown below. Figure 3 As shown.

[0027] S2, calculate the directional dispersion, tangential continuity, and cross-scale retention for the clear candidate region and the blurred candidate region. Input the directional dispersion, tangential continuity, and cross-scale retention into the evaluation model to divide the thermal image into clear region, transition region, and blurred region. Calculate the initial focus evaluation value based on the directional concentration in the clear region and the directional diffusion in the blurred region. Iteratively calculate and update the initial focus evaluation value by adjusting the local window size and the number of directional channels based on the cross-scale retention.

[0028] The Shannon entropy of the histogram of the directional channels around a pixel is calculated as the directional dispersion. The number of connected pixels perpendicular to the gradient direction is searched as the tangential continuity. A Gaussian image pyramid is constructed by calling `cv2.pyrDown`, and the gradient magnitude correlation coefficient between corresponding spatial locations of adjacent layers is calculated as the cross-scale preservation factor. These three features are extracted to form a feature vector. An evaluation model is built using the `sklearn.svm.SVC` support vector machine algorithm from the Scikit-learn library. The feature vector is input into this support vector machine model pre-trained with a radial basis function kernel. The model outputs three-class labels, thus dividing the entire infrared thermal image pixel-level into sharp, transition, and blurred regions. The `numpy.sum` function from the NumPy library is used to calculate the proportion of the maximum directional channel energy in the sharp region to the total energy, as the directional concentration. The ratio of the mean to the maximum directional channel energy plus a preset constant in the blurred region is calculated as the directional diffusion. The initial focus evaluation value is obtained by subtracting the weighted sum of the directional diffusion values ​​of all blurred regions from the sum of the directional concentration values ​​of all sharp regions in the current frame. If the cross-scale retention is lower than the set scale threshold, the size of the local window is increased proportionally, and the number of directional channels is increased proportionally. The above steps are then re-executed using the updated parameters for iterative calculation until the cross-scale retention is greater than or equal to the scale threshold, thereby outputting the updated initial focus evaluation value.

[0029] In an alternative embodiment, the calculation of directional dispersion, tangential continuity, and cross-scale preservation for sharp and blurred candidate regions, and the input of these parameters into an evaluation model to divide the thermal image into sharp, transition, and blurred regions, includes: Calculate directional dispersion based on the information entropy of the energy density of channel gradients in each direction; The connectivity length of the gradient magnitude of adjacent pixels is calculated along the edge direction perpendicular to the main gradient direction as the tangential continuity. Calculate the correlation coefficient of local window gradient energy density at adjacent scales as the cross-scale preservation factor; The directional dispersion, tangential continuity, and cross-scale preservation are input into the evaluation model, and the output is a region state discrimination value. When the region state discrimination value is greater than the first discrimination threshold, it is classified as a clear region; when it is less than the second discrimination threshold, it is classified as a blurred region; and when it is in between, it is classified as a transition region.

[0030] When performing the first-dimensional feature operation to calculate the directional dispersion, the energy of each element in the 16-dimensional directional channel is divided by the sum of the total energy densities of all channels to obtain the independent probability generation function within each channel. According to the formula Calculate the 16-axis Shannon entropy. Since the maximum extreme entropy limit of the 16-channel distribution is fixed at 4.0, the absolute value of the entropy H is truncated and assigned as a directional dispersion parameter. The larger the dispersion, the worse the focusing performance. For the extraction of the second-dimensional feature tangential continuity, it is necessary to retrieve the main direction channel angle corresponding to the current window gradient energy extreme value. For example, if the second channel is found to be the maximum value angle of 45°, then the judgment angle is orthogonally rotated by 90° to generate a tangential search trajectory line of 135°. Set the amplitude threshold value to 30.0, and perform an 8-neighborhood connected component search along the tangential direction. The number of connected uninterrupted edge pixels L that meet the amplitude value higher than 30.0 is defined as the tangential continuity parameter. Under ideal focal plane conditions, the preferred length value is distributed within 5 to 15 pixels. To avoid subsequent normalization overflow, the upper limit of L is constrained to 15, i.e., L=min(L,15). For the measurement calculation of cross-scale preservation, a level 0 pyramid layer of the original image with a scale ratio of 1:0.5 and smooth downsampling are constructed. Figure 1 Level pyramid, using a size of [size missing] for lower layer images. The window, To ensure the same region is covered by the same central geometric coordinate system, the pyramid window is applied using the same side length of the upper window. The linear correlation coefficient r is obtained by comparing the linear correlation of the two sets of 16-dimensional gradient energy density vectors extracted from the corresponding window spatial positions using the Pearson correlation equation. To adapt to subsequent discriminant value calculations, r is normalized using the following normalization formula: =(r+1) / 2.

[0031] The obtained directional dispersion H, tangential continuity L, and cross-scale preservation r are used as network input data and simultaneously loaded into a shallow multivariate linear network evaluation model with fixed pre-configured weights. The shallow multivariate linear network evaluation model is a single-layer feedforward neural network. Its network structure includes an input layer that receives multi-dimensional feature data and a single-node output layer responsible for predicting the discrimination score. The input layer contains three neurons and has no hidden layers. Each node in the input layer is fully connected to the output layer node through preset network weight parameters. The network input of the shallow multivariate linear network evaluation model consists of three scalar evaluation feature data (directional dispersion H, tangential continuity L, and cross-scale preservation r) output from the feature extraction stage. These three sets of floating-point data are fed forward into the corresponding neurons in the input layer. The network output of the shallow multivariate linear network evaluation model is a single scalar region state comprehensive discrimination floating-point value S, which is obtained by the single node of the output layer using an internally fixed linear activation function to weight and fuse the three-dimensional feature data of the network input. The decision function formula for configuring this model is: The weights of the three sets of focusing constraint influencing factors are pre-set as follows: =0.4、 =0.3 and =0.3.

[0032] A region state comprehensive discrimination floating-point value S, ranging from 0 to 1, is generated through a fully weighted convergence mapping. A first discrimination threshold is configured to identify the focus state. The preferred value is 0.65, which is the second discrimination threshold for determining high defocus dispersion. The preferred configuration is 0.35. Local areas with an output S value greater than 0.65 are identified as high-confidence sharp areas; local areas with an output S value less than 0.35 are identified as deep-blurred areas; local areas in the range of 0.35 to 0.65 are marked as transition areas and ignored to prevent disturbance to the subsequent focus smoothing curve.

[0033] In one possible embodiment, calculating the initial focus evaluation value based on the directional concentration of the sharp area and the directional diffusion of the blurred area includes: Extract the main directional channel with the highest gradient energy density within the clear region, and calculate the ratio of the energy of the main directional channel to the total energy of all directional channels as the directional concentration. Within the fuzzy region, the ratio of the mean to the maximum value of the gradient energy density of all directional channels, plus a preset constant, is used as the directional diffusion degree. The initial focus evaluation value is obtained by subtracting the weighted sum of the directional dispersion of all blurred areas from the sum of the directional concentration of all sharp areas in the current frame.

[0034] For all analytical slices marked as high-confidence clear areas in the thermal image, the maximum value index traversal instruction is used to lock the channel containing the maximum accumulated value within its respective 16-element length-direction energy density floating-point array structure. The energy algebra within this unique channel is defined as the main direction channel energy. This maximum single value is used as the numerator, and the summation algebraic value of all 16 directions of energy corresponding to the local slice is used as the denominator for division, thereby extracting the polarization coefficient FC representing a single edge abrupt change as the directional concentration parameter. This value FC is limited to 0 to 1, and the in-focus clear area parameter is mostly located in the preferred range of 0.60 to 0.95. The in-focus state is the state where the lens is accurately focused and the target image is the clearest. In parallel, a reverse diffusion evaluation is performed on all slices marked as deep blur areas, and the equal average of the sum of the 16 directional energy channels for each such defocused and blurred area is calculated. With global maximum term extreme value Set a zero constant to prevent removal. The preferred value is 0.5. Calculate the directional diffusivity FD = This represents the non-convergent tendency parameter of the gradient direction spreading randomly and flatly in the 360-degree spatial direction. Due to the approximate equal distribution of multi-directional energy in the blurred bokeh state, the measured values ​​of the FD variable usually show an upward approximation of the 1.0 limit. All region concentration and dispersion feature values ​​are orthogonally extracted from each block matrix of the heatmap to integrate a thermal evaluation snapshot. To balance the difference in the number of sharp and blurred areas, a weighting factor λ=0.2 is set. The sum of the directional concentration of all sharp areas in the current frame image is calculated, and then the sum of the directional diffusion of all blurred areas is calculated and multiplied by λ. Subtracting the latter from the former yields the initial focus evaluation value.

[0035] S3, combine the area ratio, spatial distribution and boundary contact degree of the clear area and the blurred area to adjust the initial focus evaluation value to obtain the adjusted evaluation value, perform differential analysis on the adjusted evaluation value of each focal length position to determine the candidate focal length interval, calculate the evaluation value change rate in the candidate focal length interval, and output the focal length position where the evaluation value change rate meets the zero crossing condition to the focusing mechanism to complete the automatic focusing of the infrared thermal imager.

[0036] The total number of pixels in the sharp and blurred areas are counted separately, and their area ratios are calculated. The first-order spatial moment of the sharp area is calculated using the `cv2.moments` function of the OpenCV library. The Euclidean distance between the centroid of the sharp area and the image center is obtained as a spatial distribution feature. The number of boundary pixels adjacent to the sharp and blurred areas is counted as the boundary contact degree. The adjusted evaluation value is obtained by multiplying the area ratio coefficient by the spatial distribution attenuation weight and subtracting the product of k times the boundary contact penalty coefficient and the initial evaluation value. The first-order derivative sequence of all focal length positions arranged by motor steps is calculated using the `numpy.gradient` function of the NumPy library. Continuous step intervals with absolute values ​​of the first-order derivative greater than the noise threshold are selected as candidate focal length intervals. Within these candidate focal length intervals, the index position in the first-order derivative sequence where the sign changes from positive to negative and the absolute value is close to zero is found. This index is mapped back to the corresponding stepper motor absolute coordinate command. This command position is output via serial communication protocol and written to the motor drive control register of the infrared thermal imager's focusing lens, driving the motor to that focal point, thus completing automatic focusing.

[0037] In one possible embodiment, adjusting the initial focus evaluation value by combining the area ratio, spatial distribution, and boundary contact degree of the sharp area and the blurred area to obtain the adjusted evaluation value includes: The ratio obtained by dividing the total area of ​​the clear area by the sum of the total area of ​​the blurred area and a preset constant is used as the area ratio coefficient; Calculate the average Euclidean distance between the centroid of each sharp region and the image center, and construct a spatial distribution attenuation weight based on the average value; The number of boundary pixels adjacent to the clear area and the blurred area is counted, and the proportion of the number to the total boundary of the clear area is calculated as the boundary contact penalty coefficient. The initial focus evaluation value is multiplied sequentially by the area ratio coefficient and the spatial distribution attenuation weight, and the compensation term determined by the boundary contact penalty coefficient is subtracted to obtain the adjusted evaluation value.

[0038] The entire image pixels are analyzed using a target binary mask, and a pixel count accumulation operation is performed to obtain two independent sets representing the total value parameter. The total number of pixels in the clear area is then used as the dividend. Based on the absolute pixel count obtained from the global blurred region, which is used as the divisor, a preset constant with a fixed compensation for singularity prevention is applied. The optimal value is kept constant at 1000 pixels. The area ratio coefficient of the overall field of view of the current optical system is obtained. Then, based on the infrared resolution grating specifications, a global coordinate system is established to solve for the abscissa of the entire image in the two-dimensional Euclidean central absolute coordinate system. with the vertical axis Using these coordinates as an aiming reference, the centroid of any single, pre-classified, scattered area of ​​sharpness is calculated individually; that is, the linear distance of the centroid point relative to the system's geometric centroid. Centroid shift for all clear areas detected and recorded. The average distance of the absolute centrality centripetal theoretical parameter is calculated by applying the scalar summation and dividing by the number of independent regions. .

[0039] Establish the spatially distributed decay weight mapping curve equation with an exponentially decreasing suppression function. To suppress the interference of high-contrast heat sources at the edges on the imaging of the main target, among which This represents the extreme pixel length of the diagonal line. The advanced image morphology edge detection module is triggered to calculate the boundary contact penalty term. The outer perimeter of the edge closure layer of the extracted fully connected clear block is used as the total boundary pixel count. Along this boundary, an 8-axis search algorithm is used to locate which perimeter points lie on and directly connect to the topological structure of the contact-calibrated blurred pixels. The absolute count of the boundary contact pixels is counted to obtain the number of adjacent pixels. This number of adjacent pixels is then divided by the total clear boundary pixels from the first step to obtain the ratio within the closed interval of 0 to 1, generating a boundary contact penalty coefficient to determine if it is affected by defocus aberration. .

[0040] The adjusted evaluation value calculation method is to use the initial focus evaluation value. Multiply by the area ratio coefficient and the spatial distribution attenuation weight in sequence, then subtract... This operation suppresses edge interference through spatial weights and reduces spurious peaks through penalty terms, ultimately yielding an evaluation value with good single-peak characteristics and strong noise resistance.

[0041] In a second embodiment, the present invention also provides an automatic focusing system for an infrared thermal imager based on image sharpness evaluation, comprising the following modules: The acquisition module is used to acquire thermal image sequences at each focal length position, correct them to construct a temperature intensity field, calculate pixel-level two-dimensional gradient magnitude and two-dimensional gradient direction, map the two-dimensional gradient direction and divide it into a preset number of directional channels, count the gradient energy density of each directional channel within a local window, extract clear candidate regions based on the difference in gradient energy density between the center and the ring of the local window, and extract blurred candidate regions based on the distribution dispersion between relative directional channels. The calculation module is used to calculate the directional dispersion, tangential continuity, and cross-scale retention for clear and blurred candidate regions. The directional dispersion, tangential continuity, and cross-scale retention are input into the evaluation model to divide the thermal image into clear, transition, and blurred regions. The initial focus evaluation value is calculated based on the directional concentration in the clear region and the directional diffusion in the blurred region. The initial focus evaluation value is updated by iteratively calculating and adjusting the local window size and the number of directional channels based on the cross-scale retention. The output module is used to adjust the initial focus evaluation value by combining the area ratio, spatial distribution and boundary contact degree of the clear area and the blurred area to obtain the adjusted evaluation value, perform differential analysis on the adjusted evaluation value of each focal length position to determine the candidate focal length interval, calculate the evaluation value change rate in the candidate focal length interval, and output the focal length position where the evaluation value change rate meets the zero crossing condition to the focusing mechanism to complete the automatic focusing of the infrared thermal imager.

[0042] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0043] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. An automatic focusing method for infrared thermal imagers based on image sharpness evaluation, characterized in that, include: The thermal image sequences at each focal length position are obtained and corrected to construct a temperature intensity field. The pixel-level two-dimensional gradient magnitude and two-dimensional gradient direction are calculated. The two-dimensional gradient direction is mapped and divided into a preset number of directional channels. The gradient energy density of each directional channel is statistically analyzed within a local window. Based on the difference in gradient energy density between the center and the ring of the local window, clear candidate regions are extracted. Based on the distribution dispersion between relative directional channels, blurred candidate regions are extracted. For clear and blurred candidate regions, calculate directional dispersion, tangential continuity, and cross-scale retention. Input the directional dispersion, tangential continuity, and cross-scale retention into the evaluation model to divide the thermal image into clear, transition, and blurred regions. Calculate the initial focus evaluation value based on the directional concentration in the clear region and the directional diffusion in the blurred region. Iteratively calculate and update the initial focus evaluation value by adjusting the local window size and the number of directional channels based on the cross-scale retention. The initial focus evaluation value is adjusted by combining the area ratio, spatial distribution and boundary contact degree of the clear area and the blurred area to obtain the adjusted evaluation value. Differential analysis is performed on the adjusted evaluation value of each focal length position to determine the candidate focal length interval. The evaluation value change rate is calculated within the candidate focal length interval. The focal length position where the evaluation value change rate meets the zero crossing condition is output to the focusing mechanism to complete the automatic focusing of the infrared thermal imager.

2. The method according to claim 1, characterized in that, The calculation of pixel-level two-dimensional gradient magnitude and direction, mapping the two-dimensional gradient direction and dividing it into a preset number of direction channels, and statistically analyzing the gradient energy density of each direction channel within a local window includes: The temperature intensity field is convolved using horizontal and vertical difference operators to obtain horizontal and vertical gradient components, respectively. The pixel-level two-dimensional gradient magnitude is calculated based on the square root of the sum of the squares of the horizontal and vertical gradient components, and the two-dimensional gradient direction is calculated based on the arctangent function of both. The gradient direction from 0 to 360° is divided into a preset number of directional channels, and the gradient direction of each pixel is assigned to the corresponding directional channel. Within a local window, the gradient magnitudes of pixels belonging to the same directional channel are accumulated to obtain the gradient energy density of each directional channel.

3. The method according to claim 1, characterized in that, The extraction of sharp candidate regions based on the gradient energy density difference between the center and the annulus of the local window, and the extraction of fuzzy candidate regions based on the distribution dispersion between channels in relative directions, include: The local window is divided into a central sub-region and an annular region surrounding the central sub-region, and the average gradient energy density of all directional channels within each sub-region is calculated. When the average gradient energy density difference between the central sub-region and the annular region is greater than the first threshold, the local window is marked as a clear candidate region. For local windows that are not marked as clear candidate regions, calculate the variance of gradient energy density between channels with relative directions that are 180° apart. When the variance is less than the second threshold and the sum of gradient energy densities is greater than the noise threshold, the local window is marked as a fuzzy candidate region.

4. The method according to claim 1, characterized in that, The calculation of directional dispersion, tangential continuity, and cross-scale preservation for sharp and blurred candidate regions, followed by inputting these parameters into the evaluation model to divide the thermal image into sharp, transition, and blurred regions, includes: Calculate directional dispersion based on the information entropy of the energy density of channel gradients in each direction; The connectivity length of the gradient magnitude of adjacent pixels is calculated along the edge direction perpendicular to the main gradient direction as the tangential continuity. Calculate the correlation coefficient of local window gradient energy density at adjacent scales as the cross-scale preservation factor; The directional dispersion, tangential continuity, and cross-scale preservation are input into the evaluation model, and the output is a region state discrimination value. When the region state discrimination value is greater than the first discrimination threshold, it is classified as a clear region; when it is less than the second discrimination threshold, it is classified as a blurred region; and when it is in between, it is classified as a transition region.

5. The method according to claim 3, characterized in that, The calculation of the initial focus evaluation value based on the directional concentration of the clear area and the directional diffusion of the blurred area includes: Extract the main directional channel with the highest gradient energy density within the clear region, and calculate the ratio of the energy of the main directional channel to the total energy of all directional channels as the directional concentration. Within the fuzzy region, the ratio of the mean to the maximum value of the gradient energy density of all directional channels, plus a preset constant, is used as the directional diffusion degree. The initial focus evaluation value is obtained by subtracting the weighted sum of the directional dispersion of all blurred areas from the sum of the directional concentration of all sharp areas in the current frame.

6. The method according to claim 1, characterized in that, The process of adjusting the initial focus evaluation value by combining the area ratio, spatial distribution, and boundary contact degree of the sharp area and the blurred area to obtain the adjusted evaluation value includes: The ratio obtained by dividing the total area of ​​the clear area by the sum of the total area of ​​the blurred area and a preset constant is used as the area ratio coefficient; Calculate the average Euclidean distance between the centroid of each sharp region and the image center, and construct a spatial distribution attenuation weight based on the average value; The number of boundary pixels adjacent to the clear area and the blurred area is counted, and the proportion of the number to the total boundary of the clear area is calculated as the boundary contact penalty coefficient. The initial focus evaluation value is multiplied sequentially by the area ratio coefficient and the spatial distribution attenuation weight, and the compensation term determined by the boundary contact penalty coefficient is subtracted to obtain the adjusted evaluation value.

7. An automatic focusing system for an infrared thermal imager based on image sharpness evaluation, characterized in that, Includes the following modules: The acquisition module is used to acquire thermal image sequences at each focal length position, correct them to construct a temperature intensity field, calculate pixel-level two-dimensional gradient magnitude and two-dimensional gradient direction, map the two-dimensional gradient direction and divide it into a preset number of directional channels, count the gradient energy density of each directional channel within a local window, extract clear candidate regions based on the difference in gradient energy density between the center and the ring of the local window, and extract blurred candidate regions based on the distribution dispersion between relative directional channels. The calculation module is used to calculate the directional dispersion, tangential continuity, and cross-scale retention for clear and blurred candidate regions. The directional dispersion, tangential continuity, and cross-scale retention are input into the evaluation model to divide the thermal image into clear, transition, and blurred regions. The initial focus evaluation value is calculated based on the directional concentration in the clear region and the directional diffusion in the blurred region. The initial focus evaluation value is updated by iteratively calculating and adjusting the local window size and the number of directional channels based on the cross-scale retention. The output module is used to adjust the initial focus evaluation value by combining the area ratio, spatial distribution and boundary contact degree of the clear area and the blurred area to obtain the adjusted evaluation value, perform differential analysis on the adjusted evaluation value of each focal length position to determine the candidate focal length interval, calculate the evaluation value change rate in the candidate focal length interval, and output the focal length position where the evaluation value change rate meets the zero crossing condition to the focusing mechanism to complete the automatic focusing of the infrared thermal imager.

8. The system according to claim 7, characterized in that, The calculation of pixel-level two-dimensional gradient magnitude and direction, mapping the two-dimensional gradient direction and dividing it into a preset number of direction channels, and statistically analyzing the gradient energy density of each direction channel within a local window includes: The temperature intensity field is convolved using horizontal and vertical difference operators to obtain horizontal and vertical gradient components, respectively. The pixel-level two-dimensional gradient magnitude is calculated based on the square root of the sum of the squares of the horizontal and vertical gradient components, and the two-dimensional gradient direction is calculated based on the arctangent function of both. The gradient direction from 0 to 360° is divided into a preset number of directional channels, and the gradient direction of each pixel is assigned to the corresponding directional channel. Within a local window, the gradient magnitudes of pixels belonging to the same directional channel are accumulated to obtain the gradient energy density of each directional channel.

9. The system according to claim 7, characterized in that, The extraction of sharp candidate regions based on the gradient energy density difference between the center and the annulus of the local window, and the extraction of fuzzy candidate regions based on the distribution dispersion between channels in relative directions, include: The local window is divided into a central sub-region and an annular region surrounding the central sub-region, and the average gradient energy density of all directional channels within each sub-region is calculated. When the average gradient energy density difference between the central sub-region and the annular region is greater than the first threshold, the local window is marked as a clear candidate region. For local windows that are not marked as clear candidate regions, calculate the variance of gradient energy density between channels with relative directions that are 180° apart. When the variance is less than the second threshold and the sum of gradient energy densities is greater than the noise threshold, the local window is marked as a fuzzy candidate region.

10. The system according to claim 7, characterized in that, The calculation of directional dispersion, tangential continuity, and cross-scale preservation for sharp and blurred candidate regions, followed by inputting these parameters into the evaluation model to divide the thermal image into sharp, transition, and blurred regions, includes: Calculate directional dispersion based on the information entropy of the energy density of channel gradients in each direction; The connectivity length of the gradient magnitude of adjacent pixels is calculated along the edge direction perpendicular to the main gradient direction as the tangential continuity. Calculate the correlation coefficient of local window gradient energy density at adjacent scales as the cross-scale preservation factor; The directional dispersion, tangential continuity, and cross-scale preservation are input into the evaluation model, and the output is a region state discrimination value. When the region state discrimination value is greater than the first discrimination threshold, it is classified as a clear region; when it is less than the second discrimination threshold, it is classified as a blurred region; and when it is in between, it is classified as a transition region.