Automatic focusing method and system for narrow space imaging based on depth-of-field analysis

Through the method based on depth of field analysis, the problem of imaging quality degradation caused by dynamic environment and water medium scattering in imaging autofocus in narrow spaces is solved, and high-precision focus locking and scattering compensation are achieved, improving the accuracy of imaging autofocus.

CN120128798AActive Publication Date: 2025-06-10SCIVITA MEDICAL TECHNOLOGY CO LTD

Patent Information

Application Number
CN202510606207.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-12
Publication Date
2025-06-10
Estimated Expiration
2045-05-12

AI Technical Summary

Technical Problem

The prior art is difficult to adapt to the dynamically changing physiological environment and light scattering problems caused by aqueous media in imaging automatic focus in narrow spaces, resulting in a decline in imaging quality.

Method used

Using a depth of field analysis method, the refraction correction is performed by acquiring the original image data, analyzing the scattering interference, filtering the candidate focus, optimizing the exposure, calculating the locking threshold, and triggering focus locking and scattering compensation when the distance between the target position and the optimal imaging position is less than the locking threshold.

Benefits of technology

It improves the accuracy and imaging quality of imaging autofocus in a narrow space, and enhances the anti-interference ability and response speed of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120128798A_ABST
    Figure CN120128798A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of automatic focusing, and discloses a narrow space imaging automatic focusing method and system based on depth-of-field analysis, and the method comprises the steps: obtaining original image data, and carrying out the refraction correction according to the original image data, and obtaining an initial depth-of-field distribution diagram; carrying out scattering interference analysis according to the initial depth-of-field distribution diagram to obtain interference intensity distribution; performing focus analysis according to the interference intensity distribution to obtain a candidate focus set; performing exposure optimization according to the candidate focus set to obtain an optimized focus set; performing locking threshold calculation according to the optimized focus set to obtain a locking threshold of the optimal imaging position; and when the distance between the target position and the optimal imaging position is smaller than the locking threshold value, triggering focus locking, performing scattering compensation, and outputting a high-precision imaging result. The method has the following effect that the accuracy of automatic focusing of imaging in a narrow space can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of autofocus, and particularly to an autofocus method and system for imaging in a narrow space based on depth of field analysis. Background Art

[0002] At present, the application of imaging technology in the medical field is crucial, especially for accurate imaging in narrow spaces, which is directly related to the accuracy of diagnosis and the effectiveness of treatment. With the development of endoscope technology, how to obtain high-quality images in complex physiological environments has become a key driving force for the progress of medical imaging. Especially in special scenarios such as the uterine cavity water environment, the imaging system needs to overcome space limitations and medium interference to ensure image clarity and diagnostic reliability, which poses extremely high requirements for technological innovation.

[0003] In an existing technology, a common method is to adjust the focus position by measuring the distance between the target and the lens. The specific steps include: first, using technologies such as ultrasonic waves or infrared rays for distance measurement; then, calculating the optimal focal length according to the measurement results; finally, driving the lens to move to the calculated position to complete focusing.

[0004] Existing technologies mostly rely on static scene assumptions or simple distance measurements, and it is difficult to adapt to the dynamic physiological environment and the light scattering problem caused by the water medium. In the endoscope application scenario, where the light source and the camera are both located inside the probe, when the probe enters the human body cavity, the surrounding tissues will produce irregular reflection and absorption effects, resulting in an abnormal increase in the brightness of a local area (i.e., glare). At this time, if a focusing algorithm based on simple distance measurement is used, it will cause the focus to deviate from the position of the actual target, thereby affecting the imaging quality. In addition, the presence of the water medium further exacerbates this problem because it introduces additional light scattering and absorption, making the already complex optical path even more unpredictable. Therefore, the existing methods cannot quickly lock the focal length at the optimal imaging position under these specific conditions, resulting in low accuracy of autofocus. Summary of the Invention

[0005] The present invention provides an autofocus method and system for imaging in a narrow space based on depth of field analysis to improve the accuracy of autofocus for imaging in a narrow space.

[0006] In a first aspect, to solve the above technical problems, the present invention provides an autofocus method for imaging in a narrow space based on depth of field analysis, including: Obtaining original image data, and performing refraction correction according to the original image data to obtain an initial depth of field distribution map; Performing scattering interference analysis according to the initial depth of field distribution map to obtain an interference intensity distribution; Perform focus analysis based on the interference intensity distribution to obtain a candidate focus set; Perform exposure optimization based on the candidate focus set to obtain an optimized focus set; Calculate a locking threshold for the best imaging position based on the optimized focus set; When the distance between the target position and the best imaging position is less than the locking threshold, trigger focus locking, perform scattering compensation, and output a high-precision imaging result.

[0007] In an alternative embodiment, the obtaining of the original image data and performing refraction correction based on the original image data to obtain an initial depth-of-field distribution map includes: Obtain the original image data; Calculate a phase difference based on the original image data and a preset sensor array to obtain an image visual difference; Calculate the initial depth-of-field value through the following formula: ; Wherein, represents the initial depth-of-field value, represents the focal length, represents the baseline value, represents the image visual difference, represents the conversion coefficient; Perform refraction correction based on the initial depth-of-field value to obtain an initial depth-of-field distribution map.

[0008] In an alternative embodiment, the performing of scattering interference analysis based on the initial depth-of-field distribution map to obtain an interference intensity distribution includes: Perform image segmentation based on the initial depth-of-field distribution map to obtain an image foreground and an image background; Perform boundary detection based on the image foreground and the image background to obtain a light scattering boundary; Perform region growing based on the light scattering boundary to obtain a light scattering region; Calculate an interference intensity based on the light scattering region to obtain a scattering interference intensity; Perform smoothing filtering based on the scattering interference intensity to obtain an interference intensity distribution.

[0009] In an alternative embodiment, the performing of focus analysis based on the interference intensity distribution to obtain a candidate focus set includes: Perform region segmentation based on the interference intensity distribution to obtain local regions with different scattering intensities; Perform relevance analysis based on the clarity and depth-of-field parameters of the local regions to obtain a region relevance; When the region relevance is greater than or equal to a preset relevance threshold, determine that the local region is a valid region; When the region relevance is less than the relevance threshold, determine that the local region is invalid; Generate a focus based on the valid region to obtain an original focus set; Calculate the structural similarity according to the original focus set and a pre-stored target clarity template to obtain the focus structural similarity; Eliminate non-candidate points according to the focus structural similarity to obtain a valid focus set; Eliminate redundant points according to the valid focus set to obtain a candidate focus set.

[0010] In an alternative embodiment, the obtaining an optimized focus set by performing exposure optimization according to the candidate focus set includes: Perform region segmentation on the original image data according to the candidate focus set to obtain a first local region; Perform flare detection on the first local region to obtain a local flare region; Calculate the brightness gradient of the local flare region to obtain gradient distribution data; Perform smoothing filtering on the local flare region according to the gradient distribution data to obtain a brightness adjustment parameter; Perform set optimization according to the brightness adjustment parameter to obtain an optimized focus set.

[0011] In an alternative embodiment, the obtaining a locking threshold for the best imaging position by performing a locking threshold calculation according to the optimized focus set includes: Calculate the depth of field range and image clarity of each focus region according to the optimized focus set; Perform weighted summation according to the depth of field range and the image clarity to obtain a balance coefficient; When the balance coefficient is greater than a preset coefficient threshold, determine that the focus region is a candidate region for the best imaging; Calculate the geometric center of the candidate region as the best imaging position; Calculate the minimum distance from the best imaging position to the boundary as the locking threshold for the best imaging position.

[0012] In an alternative embodiment, the triggering of focus locking and performing scattering compensation and outputting a high-precision imaging result when the distance between the target position and the best imaging position is less than the locking threshold includes: Obtain the current frame image; Perform a fast Fourier transform on the current frame image to obtain the image frequency domain characteristics; Extract the proportion of high-frequency components according to the frequency-domain characteristics of the image; When the proportion of the high-frequency components is lower than a preset proportion threshold, optimize the clarity of the current frame image to obtain an optimized image; Input the optimized image into a pre-trained scattering compensation model to output a high-precision imaging result; Among them, the training process of the scattering compensation model includes: Train the scattering compensation model based on a deep learning model. The input layer is historical underwater images, and the output layer is scattering compensation images. When it is detected that the number of training times reaches a preset upper limit or the mean square error of the images is higher than a preset target value, obtain the trained model.

[0013] In a second aspect, the present invention provides a narrow-space imaging autofocus system based on depth-of-field analysis, including: A data acquisition module, configured to acquire original image data and perform refraction correction according to the original image data to obtain an initial depth-of-field distribution map; A scattering interference module, configured to perform scattering interference analysis according to the initial depth-of-field distribution map to obtain an interference intensity distribution; A candidate focus module, configured to perform focus analysis according to the interference intensity distribution to obtain a set of candidate foci; An exposure optimization module, configured to perform exposure optimization according to the set of candidate foci to obtain an optimized set of foci; A locking threshold module, configured to calculate a locking threshold for the best imaging position according to the optimized set of foci; A result output module, configured to trigger focus locking and perform scattering compensation when the distance between the target position and the best imaging position is less than the locking threshold, and output a high-precision imaging result.

[0014] In a third aspect, the present invention further provides an electronic device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements the narrow-space imaging autofocus method based on depth-of-field analysis described in any one of the above.

[0015] In a fourth aspect, the present invention further provides a computer-readable storage medium, which includes a stored computer program. Among them, when the computer program runs, it controls the device where the computer-readable storage medium is located to execute the narrow-space imaging autofocus method based on depth-of-field analysis described in any one of the above.

[0016] Compared with the prior art, the present invention has the following beneficial effects: (1)Obtain the original image data and perform refraction correction based on the original image data to obtain an initial depth-of-field distribution map. The original image data is captured by a high-precision sensor, and an advanced refraction correction algorithm is used to remove the imaging errors caused by medium inhomogeneity or surface reflection. This process significantly improves the accuracy of the depth-of-field information, provides a reliable data basis for the subsequent steps, and ensures the imaging quality.

[0017] (2)Perform scattering interference analysis based on the initial depth-of-field distribution map to obtain the interference intensity distribution. Professional image processing techniques are used to quantitatively analyze the scattering interference in the initial depth-of-field distribution map, identify and evaluate the interference intensity in different regions. This step helps to accurately identify the factors affecting imaging clarity, provides an important basis for further optimizing the focus position, and improves the anti-interference ability of the system.

[0018] (3)Perform focus analysis based on the interference intensity distribution to obtain a set of candidate foci. Based on the results of the interference intensity distribution, the system can intelligently screen out multiple potential optimal focus positions to form a set of candidate foci. This method not only considers the imaging quality but also takes into account the feasibility and stability in actual operation, ensuring high-quality imaging results even in complex environments.

[0019] (4)Perform exposure optimization based on the set of candidate foci to obtain an optimized set of foci. By optimizing and adjusting the exposure parameters of each candidate focus, the system can further improve the imaging quality. This step uses intelligent algorithms to calculate the optimal exposure settings, enabling each candidate focus to achieve the best imaging effect, thus forming an optimized set of foci and improving the stability and consistency of imaging.

[0020] (5)Calculate the locking threshold based on the optimized set of foci to obtain the locking threshold for the best imaging position. Combining the information of the optimized set of foci, the system can calculate a reasonable locking threshold for determining whether the target is at the best imaging position. This method based on multi-focus analysis ensures the scientificity and rationality of the locking threshold, enhances the response speed and positioning accuracy of the system.

[0021] (6)When the distance between the target position and the best imaging position is less than the locking threshold, trigger focus locking and perform scattering compensation to output a high-precision imaging result. In the last step, the system continuously monitors the change of the target position. Once it is found that the target is approaching or at the best imaging position, the focus locking mechanism is immediately triggered, and the existing scattering interference is compensated. This can not only quickly and stably lock the focus but also effectively eliminate various interference factors during imaging, and finally output a high-precision and high-clarity imaging result to meet the requirements of professional applications. Description of the Drawings

[0022] Figure 1 It is a schematic flowchart of an automatic focusing method for imaging in a narrow space based on depth of field analysis provided by the first embodiment of the present invention; Figure 2 It is a schematic structural diagram of an automatic focusing system for imaging in a narrow space based on depth of field analysis provided by the second embodiment of the present invention. Detailed implementation manners

[0023] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.

[0024] Referring to Figure 1 , the first embodiment of the present invention provides an automatic focusing method for imaging in a narrow space based on depth of field analysis, including the following steps: S11, acquiring original image data, and performing refraction correction according to the original image data to obtain an initial depth of field distribution map; S12, performing scattering interference analysis according to the initial depth of field distribution map to obtain an interference intensity distribution; S13, performing focus analysis according to the interference intensity distribution to obtain a candidate focus set; S14, performing exposure optimization according to the candidate focus set to obtain an optimized focus set; S15, calculating a locking threshold according to the optimized focus set to obtain a locking threshold for the best imaging position; S16, when the distance between the target position and the best imaging position is less than the locking threshold, triggering focus locking, and performing scattering compensation to output a high-precision imaging result.

[0025] In step S11, original image data is acquired, and refraction correction is performed according to the original image data to obtain an initial depth of field distribution map.

[0026] In one implementation manner, original image data is acquired; According to the original image data and a preset sensor array, a phase difference is calculated to obtain an image visual difference; The initial depth of field value is calculated through the following formula: ; wherein, represents the initial depth of field value, represents the focal length, represents the baseline value, represents the image visual difference, Represents the conversion coefficient; Perform refractive correction based on the initial depth of field value to obtain an initial depth of field distribution map.

[0027] In one implementation, raw image data is obtained through the optical lens and sensor assembly of the endoscope: The camera at the front end of the endoscope (equipped with a CMOS or CCD sensor), with the assistance of a light source (such as an LED or fiber optic light guide), performs multi-focus or continuous focal plane image acquisition of the target tissue. During the process, the physical position or focal length parameters of the lens need to be synchronously recorded; the image data is transmitted in real time to the processing unit through the signal transmission channel of the endoscope (such as an optical fiber or digital interface), and then refractive correction is performed - the refractive distortion and lens aberration in the optical path are eliminated through a correction algorithm, and finally an initial depth of field distribution map containing multi-layer depth of field information is generated. The raw image data is stored in a lossless compression format (such as TIFF or PNG) or a medical imaging standard format (such as DICOM) to retain high-resolution details and metadata (such as acquisition time, device parameters, etc.), ensuring the accuracy and traceability of subsequent processing. Specifically, the raw image data collected by the endoscope is stored in the RGB format, with a resolution of 1920×1080 pixels and a frame rate of 30fps.

[0028] In one implementation, the phase difference data of the scene is obtained through a preset 4×4 optical sensor array (with a spacing of 5mm between each sensor), and the semi-global matching (SGM) algorithm is used to calculate the visual disparity, where the cost aggregation window size is set to 9×9 pixels, and the penalty coefficients are P1 = 50 and P2 = 200.

[0029] It should be noted that the initial depth of field value, that is, the depth range in which the target object can remain clear in the imaging system, reflects the preliminary quantitative estimation of the depth of field of the system, with the unit of millimeters; the focal length of the optical system refers to the distance from the optical center of the lens to the imaging plane (such as the sensor), with the unit of millimeters. The larger the focal length, the shallower the depth of field. The baseline value, that is, the physical distance between two imaging devices (such as the two lenses of a binocular endoscope), with the unit of millimeters, is a basic parameter for calculating depth information in stereoscopic vision; the image visual disparity refers to the horizontal displacement of corresponding pixel points of the same object in the images of two different perspectives (such as the left and right lenses), with the unit of pixels, dimensionless. The larger the disparity, the closer the object is to the imaging system. This formula combines the principles of geometric optics and the stereoscopic vision model through the mutual relationship of focal length, baseline, and disparity, quantifies the initial depth of field value, and provides a mathematical basis for the generation of the subsequent depth of field distribution map. The value of the conversion coefficient is 0.1mm / pixel, which is used for unit conversion from pixels to physical distances.

[0030] In one implementation, when performing refraction correction, first, for the refraction interference caused by the water medium, a mathematical model is constructed based on the law of refraction of light. The offset caused by refraction is accurately corrected through an iterative optimization algorithm (LM algorithm, with a maximum iteration count of 100 and a convergence threshold of 0.001). Subsequently, the resolution of the initial depth-of-field distribution map is increased to 3840×2160 using bicubic interpolation, and the depth-of-field details are retained at a 16-bit depth quantization level. Meanwhile, noise suppression is implemented synchronously during the calculation: the original depth data is smoothed using a 3×3 Gaussian filter (standard deviation = 5) to ensure that the edge retention rate of the filtered image is higher than 90%, and finally, a high-precision initial depth-of-field distribution map is generated.

[0031] In one implementation, when performing refraction correction for the water medium, the specific process is as follows: First, a geometric correction model is constructed based on Snell's law of refraction by establishing the relationship between the angle of incidence of the incident light and the normal (air medium) and the angle of refraction (water medium) (sin / sin = / , where = 1.0 is the refractive index of vacuum, and the refractive index of the water medium is taken as 1.33), the light path parameters of each pixel in the original depth data are parameterized as a refraction path in a three-dimensional coordinate system. Subsequently, the refraction offset error function E = Σ(Δx_i² + Δy_i²) is defined, where Δx_i and Δy_i are the refraction offsets of the i-th pixel in the xy plane. Nonlinear least squares optimization is performed using the Levenberg-Marquardt (LM) algorithm: the refractive index error parameter ε (initial value set to 0.01) is initialized, and the current refractive index ' = The theoretical offset Δx_i' and Δy_i' corresponding to (1 + ε) are calculated, and the residual E' = Σ(Δx_i - Δx_i')² + Σ(Δy_i - Δy_i')² is computed. The parameter ε is updated through the Jacobian matrix until the number of iterations reaches 100 or the residual reduction is lower than 0.001%. The corrected depth data is super-resolution reconstructed by bicubic interpolation, using the Catmull-Rom spline interpolation kernel function, to isotropically magnify the original depth-of-field map to a resolution of 3840×2160, while retaining depth gradient changes at the 0.0001 mm level with 16-bit floating-point precision. Noise suppression is synchronously implemented during the iterative optimization process: the original depth data is first subjected to 3×3 Gaussian filtering (σ = 5 pixels), but the edge regions are identified through edge detection preprocessing (the Canny operator threshold is set to 1.5 times the depth variance), full filtering is performed in non-edge regions, and only directional smoothing (filtering along the direction perpendicular to the gradient, where the gradient direction is calculated by the Sobel operator) is applied in edge regions to ensure that the change rate of the standard deviation of the intensity of edge pixels ≤ 5%. The finally generated depth-of-field map is verified to have an edge retention rate (calculated by Canny edge coincidence) of over 92% and a signal-to-noise ratio improvement of 3.2 dB.

[0032] It should be noted that the initial depth-of-field distribution map is a two-dimensional depth information map generated from the original image data collected by the endoscope after refraction correction, iterative optimization (such as offset correction by the LM algorithm), and noise suppression processing. The value of each pixel represents the depth estimation value of the corresponding scene position, and it can reflect the clarity distribution of the target object at different depths. This map is stored in a high-precision format, such as TIFF or PNG format with 16-bit depth quantization (supporting lossless compression) or DICOM format compliant with medical imaging standards, to retain high-resolution details (such as 3840×2160 pixels) and complete metadata (such as acquisition parameters, correction information, etc.), while ensuring the accuracy and data traceability of subsequent processing (such as interpolation, filtering).

[0033] In step S12, scattering interference analysis is performed based on the initial depth-of-field distribution map to obtain the interference intensity distribution.

[0034] In one implementation, image segmentation is performed based on the initial depth-of-field distribution map to obtain the image foreground and the image background; boundary detection is performed based on the image foreground and the image background to obtain the light scattering boundary; region growing is performed based on the light scattering boundary to obtain the light scattering region; interference intensity calculation is performed based on the light scattering region to obtain the scattering interference intensity; and smoothing filtering is performed based on the scattering interference intensity to obtain the interference intensity distribution.

[0035] It should be noted that the interference intensity distribution is a two-dimensional data matrix generated by analyzing the initial depth of field distribution map. Its spatial mapping corresponds exactly to the original image (such as 3840×2160 resolution). The interference intensity of each pixel or local area is quantified by a normalized value (in the range of 0-1). The higher the value, the more significant the scattering interference in that area. Its core components include: ① the spatial position of the scattering area identified by image segmentation and region growing algorithms, such as the abnormally highlighted areas formed by the reflection of blood or tissue fluid in a medical endoscope; ② the quantification indicators include depth gradient (characterizing the degree of depth of field mutation), brightness difference (gray level difference between local and background), medium refractive index difference (optical path distortion effect), and noise level (standard deviation of residual noise after Gaussian filtering), where the noise level is negatively correlated with the interference intensity; ③ the regional area weight mechanism, that is, the larger the area of the scattering area, the higher its contribution value to the overall interference intensity. By integrating the above elements, this distribution map realizes the spatial positioning, intensity quantification, and influence range assessment of scattering interference in different scenarios. For example, in medical imaging, it can accurately label the interference degree of blood aggregation areas, providing data support for subsequent correction.

[0036] It should be noted that the specific process of image segmentation based on the initial depth of field distribution map is as follows: First, based on the depth value of each pixel in the depth of field distribution map (such as the depth of field data after 16-bit quantization), the segmentation threshold between the foreground and the background is determined by analyzing the depth difference. For example, the depth threshold interval is determined by histogram analysis or an adaptive threshold algorithm (such as the Otsu method); Second, a segmentation algorithm based on depth information (such as region growing, graph cut optimization, or deep learning model) is used to segment the depth of field map. The area corresponding to the target object and with a depth value conforming to the foreground characteristics is marked as the image foreground, and the remaining areas are classified as the image background; During the segmentation process, combined with the detailed features of the high-resolution depth of field map (3840×2160), the edge-preserving characteristics (such as the edge retention rate > 90% after the previous Gaussian filtering) are used to optimize the segmentation boundary to ensure that the boundary between the foreground and the background is clear and there is no obvious noise interference; Finally, the segmentation result in binary or mask form is output, the pixel areas of the foreground and the background are respectively extracted, and the segmented image layer is saved in a format compatible with the original data (such as PNG or DICOM).

[0037] It should be noted that the specific process of boundary detection based on the foreground and background of the image is as follows: First, based on the depth information and grayscale image of the segmented foreground and background, calculate the depth gradient and grayscale gradient at the junction of the two regions, and suppress noise interference through the edge-preserving characteristics after Gaussian filtering (edge retention rate > 90%); Second, use the Canny edge detection algorithm or Sobel operator to extract the high-gradient region at the junction of the foreground and background, and combine the depth mutation characteristics caused by light scattering in the depth of field distribution map (such as local depth outliers caused by refraction or scattering), and further locate the light scattering boundary through adaptive threshold segmentation or morphological operations (such as opening operation, closing operation); Finally, register the detected boundary with the physical depth value of the original depth of field map, ensure the high-resolution (3840×2160) boundary positioning accuracy through bicubic interpolation, and output the light scattering boundary contour in vector format or binary mask form, while retaining the depth quantization level (16bit) and metadata information to support subsequent processing.

[0038] It should be noted that the process of region growing based on the light scattering boundary is as follows: First, use the scattering contour obtained by boundary detection as the initial seed region, set the growth criterion (such as depth value similarity threshold, grayscale gradient or texture feature), and then gradually incorporate the pixels that meet the conditions in the boundary neighborhood (such as adjacent pixels with similar scattering characteristics or depth mutations in the depth of field distribution map) into the scattering region; Expand the region range in an iterative manner until all eligible pixels are completely included or reach the preset termination condition (such as similarity threshold breakthrough, region area convergence); Finally, generate a connected region consistent with the light scattering phenomenon, while retaining the high resolution (3840×2160) and depth quantization accuracy (16bit), and can optimize the boundary smoothness by combining morphological operations (such as erosion, dilation).

[0039] It should be noted that the scattering interference intensity is calculated by the following formula: ; where represents the scattering interference intensity, represents the pixel number, represents the scattering region, represents the th depth gradient of the pixel in the scattering region, represents the difference between the average grayscale of the th pixel in the scattering region and the background region, represents the refractive index of the medium, represents the physical depth value of this pixel to the lens, represents the pixel area of the scattering region, represents the standard deviation of the residual noise after Gaussian filtering.

[0040] It should be noted that the scattering interference intensity is a dimensionless index used to describe the degree of interference of scattering on imaging. The depth gradient is dimensionless, the average gray level is dimensionless, the refractive index of the medium is dimensionless, the physical depth value is in millimeters, and the pixel area of the scattering region is in square millimeters. The standard deviation of the residual noise is dimensionless.

[0041] It should be noted that This term characterizes the intensity of the deflection effect of the optical path due to the sudden change in the refractive index at the medium interface by quantifying the refractive index gradient per unit distance. Specifically, the refractive index difference reflects the degree of deflection of the optical path at the interface between two media (such as tissue and body fluid), and (the physical depth from the pixel to the lens, in millimeters) is used as a distance parameter to normalize the spatial influence range of this gradient. When the refractive index difference between the two media is large (such as body fluid = 1.36 and tissue = 1.33) and occurs at a relatively shallow depth ( small), the rate of change of the refractive index per unit distance will increase significantly, resulting in more severe deflection of the optical path and thus exacerbating the scattering interference. Conversely, if the interface is located at a deeper depth ( large), the gradient effect of the same refractive index difference will be diluted and the interference intensity will be reduced. By explicitly modeling the physical relationship between the refractive index difference and the depth, this term couples the local effect of the optical path deflection with imaging features such as the depth-of-field gradient and gray level difference, providing a physical basis for the quantitative calculation of the scattering interference intensity. For example, in a medical endoscope, if the interface between the blood region ( ) and the tissue ( ) is close to the lens ( small), its value will be larger, resulting in stronger optical path distortion and scattering interference, which is consistent with the phenomenon that the interference in the superficial region is more significant in actual observations.

[0042] It should be noted that the specific process of smoothing filtering according to the scattering interference intensity is as follows: First, take the calculated scattering interference intensity distribution map as the input, and use a Gaussian filter to perform spatial domain smoothing on the image. By adjusting the window size and parameters of the filter, local noise fluctuations are eliminated while the characteristics of large-range interference intensity changes are retained. Second, for the edge regions in the image (such as near the light scattering boundary), bilateral filtering technology is adopted to retain edge details while suppressing noise, ensuring the clarity and continuity of the image edges. Finally, the processed interference intensity distribution map is saved in a high-precision 16-bit depth format (such as TIFF or PNG), and methods such as histogram equalization are combined to optimize the contrast of the intensity distribution, making the interference intensity differences in different regions more obvious. At the same time, the high resolution (such as 3840×2160 pixels) and metadata information of the original image are maintained, providing clear and stable intensity distribution data for subsequent interference correction.

[0043] In step S13, according to the interference intensity distribution, focus analysis is performed to obtain a candidate focus set.

[0044] In one implementation, according to the interference intensity distribution, region segmentation is performed to obtain local regions with different scattering intensities; Relevance analysis is performed according to the clarity and depth of field parameters of the local regions to obtain region relevance; When the region relevance is greater than or equal to a preset relevance threshold, it is determined that the local region is a valid region; When the region relevance is less than the relevance threshold, it is determined that the local region is invalid; Focus generation is performed according to the valid regions to obtain an original focus set; Structural similarity calculation is performed according to the original focus set and a pre-stored target clarity template to obtain focus structural similarity; Non-candidate point elimination is performed according to the focus structural similarity to obtain a valid focus set; Redundant point elimination is performed according to the valid focus set to obtain a candidate focus set.

[0045] It should be noted that when performing region segmentation according to the interference intensity distribution, first, by analyzing the statistical characteristics of the intensity distribution map (such as histogram peaks or gradient changes), multiple thresholds are set to divide the intensity range into several intervals; then, threshold segmentation or clustering algorithms (such as K-means) are used to divide the image into local regions corresponding to different scattering intensities, ensuring significant differences in interference intensity between adjacent regions; finally, morphological optimization (such as denoising and connected component analysis) is performed on the segmentation result to generate a clearly labeled intensity grading region map, providing a basis for subsequent targeted correction.

[0046] It should be noted that when performing correlation analysis based on the clarity and depth-of-field parameters of the local area, first, clarity indicators (such as image gradient energy, focus metric values) and depth-of-field parameters (such as depth-of-field value or depth gradient) are extracted for each area separately. Then, the Spearman rank correlation coefficient is used to evaluate the correlation between the two. The specific steps include: assigning ranks (i.e., the ranked order after sorting) to the clarity and depth-of-field data according to their numerical sizes, calculating the sum of the squared differences between the two sets of ranks, and substituting them into the Spearman formula to obtain the correlation coefficient (the value range is from -1 to 1). An absolute value of the coefficient close to 1 indicates a strong monotonic correlation (positive or negative) between the two, and close to 0 indicates no significant association. This method does not require assuming the data distribution form and can effectively reveal the dependence relationship between clarity and depth-of-field parameters in the local area, providing a quantitative basis for subsequent correction.

[0047] It should be noted that the focus generation process is as follows: First, the golden section search method is used to optimize the focus adjustment step size. The initial search range is set to 0 - 1 mm, and the accuracy is controlled at 0.5 mm. The optimal focus position is gradually narrowed down through iteration. In each iteration, the bicubic interpolation method (grid spacing 5 pixels) is used to reconstruct the virtual focal plane image, and the edge energy map (threshold 3) is generated through Sobel edge detection.

[0048] It should be noted that the structural similarity index (SSIM, using an 8×8 pixel sliding window to evaluate local similarity) between the reconstructed image and the target clarity template is calculated; then, combined with non-maximum suppression (NMS, neighborhood radius 3 pixels) and density clustering (DBSCAN, neighborhood threshold ε = 2 mm, minimum sample number 5), candidate focus positions are generated and screened, and redundant points are removed to form a refined focus set; for dynamic scenes, the Farneback optical flow algorithm (pyramid level 3, analysis window 20×20 pixels) is introduced to estimate the target displacement in real time, and the motion offset between consecutive frames is compensated to ensure the continuity and stability of the focus candidate positions in time series. The entire process realizes high-precision focus positioning through a closed-loop of optimization, reconstruction, evaluation, screening, and dynamic compensation.

[0049] It should be noted that the screening process combining non-maximum suppression (NMS) and density-based spatial clustering of applications with noise (DBSCAN) is as follows: First, local redundancy elimination is performed on the candidate focus positions through NMS. Within the set 3-pixel neighborhood radius, only the candidate points with the highest sharpness score (such as SSIM value or gradient energy) are retained, and neighboring sub-optimal points are suppressed. Subsequently, the screened candidate points are input into the DBSCAN algorithm. With a neighborhood threshold of 2 mm (which needs to be converted to pixel distance according to the image resolution) and a minimum sample number of 5 points, the core clusters in the high-density regions are identified, and the non-core points in the isolated points or small-scale clusters are removed. Finally, through the local suppression of NMS and the global density grouping of DBSCAN, redundant candidate points are removed, and a set of foci that are evenly distributed and cover the key areas is retained, which not only avoids overcrowding in the dense areas but also ensures the sufficient presence of the focused candidate points at the key positions, providing an efficient and accurate focus position basis for subsequent processing.

[0050] In step S14, exposure optimization is performed according to the candidate focus set to obtain an optimized focus set.

[0051] In one implementation, the original image data is regionally segmented according to the candidate focus set to obtain a first local region; Flare detection is performed according to the first local region to obtain a local flare region; Brightness gradient calculation is performed on the local flare region to obtain gradient distribution data; Smoothing filtering is performed on the local flare region according to the gradient distribution data to obtain a brightness adjustment parameter; Set optimization is performed according to the brightness adjustment parameter to obtain an optimized focus set.

[0052] It should be noted that the process of regionally segmenting the original image data according to the candidate focus set is as follows: First, the screened candidate focus positions are used as key reference points. According to their spatial distribution and sharpness weights, local regions centered on these foci are delimited in the original image. Specific methods include setting a fixed or adaptive neighborhood radius (such as based on depth of field parameters or sharpness gradient) with each candidate focus as the center, or associating adjacent high-sharpness regions with the focus positions through connected component analysis to form continuous local regions. In addition, combining the depth of field distribution map and the interference intensity distribution, the regions around the candidate foci with similar depth of field characteristics, high sharpness, and low interference are classified as the "first local region" to preferentially retain or optimize the imaging quality of these regions. This segmentation process aims to divide the image into key sub-regions centered on effective foci, providing a basis for targeted processing such as subsequent focusing optimization, detail enhancement, or dynamic tracking.

[0053] It should be noted that the specific method for glare detection based on the first partial region is as follows: First, for the segmented first partial region (such as a high-definition or key focus region), extract its luminance channel or the highlighted region in the RGB color space, identify the abnormally bright pixel clusters through histogram analysis or adaptive threshold segmentation (such as the Otsu method), mark them as local glare regions, and generate corresponding binary masks for subsequent masking or correction processing.

[0054] It should be noted that the specific process for calculating the luminance gradient of the local glare region is as follows: First, for the marked local glare region, calculate the luminance gradient value (including gradient magnitude and direction) of each pixel through a gradient operator (such as the Sobel or Scharr operator), and statistically analyze its distribution characteristics (such as the histogram of gradient magnitude, the spatial distribution of high-gradient regions); Subsequently, design an adaptive smoothing strategy based on the gradient distribution data: in the smooth region with a lower gradient (such as the highlighted region at the center of the glare), use Gaussian filtering or bilateral filtering for intensity attenuation, while in the edge region with a higher gradient (such as the glare contour), retain details to avoid blurring key boundaries; By iteratively adjusting the filtering parameters (such as filter window size, intensity attenuation coefficient), calculate the luminance adjustment parameters for different gradient regions (such as the attenuation coefficient matrix); Finally, combine the luminance adjustment parameters with the original candidate focus set, and recalculate the weights or coordinates of the focus positions through an optimization algorithm (such as least squares fitting or weighted fusion) to eliminate the influence of luminance distortion caused by glare on focus positioning, and finally generate an optimized focus set that eliminates glare interference and has a more accurate distribution.

[0055] In step S15, calculate the locking threshold according to the optimized focus set to obtain the locking threshold for the best imaging position.

[0056] In one implementation, calculate the depth of field range and image sharpness of each focus region according to the optimized focus set; Perform weighted summation according to the depth of field range and the image sharpness to obtain a balance coefficient; When the balance coefficient is greater than a preset coefficient threshold, determine that the focus region is a candidate region for the best imaging; Calculate the geometric center of the candidate region as the best imaging position; Calculate the minimum distance from the best imaging position to the boundary as the locking threshold for the best imaging position.

[0057] It should be noted that, first, for each focal region, the depth-of-field values of all pixels within the region are extracted in combination with the depth-of-field distribution map, and the effective depth-of-field range of the region (i.e., the maximum depth interval with acceptable front and back sharpness) is determined through statistical analysis. Second, when evaluating the image sharpness, an edge detection algorithm (such as the Sobel operator) is used to calculate the gradient magnitude of the pixels within the region, the Tenengrad function is used as a sharpness metric to quantify the local detail sharpness, and at the same time, the structural similarity index (SSIM) is combined with a preset sharpness template for comparison to comprehensively generate the sharpness.

[0058] It should be noted that the specific process according to the above steps is as follows: First, a weighted calculation is performed on the depth-of-field range (such as the clear depth interval) and the image sharpness (such as edge sharpness or SSIM score) of each focal region, and the two are weighted and summed according to preset weights (such as a depth-of-field weight of 0.6 and a sharpness weight of 0.4) to obtain a comprehensive evaluation value - the balance coefficient. If this coefficient exceeds a preset threshold (such as 0.8), it indicates that the region achieves a good balance between depth-of-field coverage and imaging sharpness and is determined as a candidate region for the best imaging. Subsequently, the geometric center of all candidate regions (such as the average of pixel coordinates) is calculated as the potential best imaging position, and the minimum distance from this position to the image boundary (such as the shortest distance in the horizontal or vertical direction) is further evaluated and set as the "locking threshold" - which is used to ensure that the imaging position meets both the sharpness and depth-of-field requirements and is far from the image edge to avoid the influence of edge distortion or sensor blind spots during subsequent focusing. This process finally determines a stable and high-precision imaging region through multi-dimensional quantitative evaluation and spatial constraints.

[0059] In step S16, when the distance between the target position and the best imaging position is less than the locking threshold, focus locking is triggered, and scattering compensation is performed to output a high-precision imaging result.

[0060] In one implementation, the current frame image is acquired; The current frame image is subjected to a fast Fourier transform to obtain the image frequency domain characteristics; The proportion of high-frequency components is extracted according to the image frequency domain characteristics; When the proportion of high-frequency components is lower than a preset proportion threshold, the current frame image is optimized for sharpness to obtain an optimized image; The optimized image is input into a pre-trained scattering compensation model to output a high-precision imaging result; Among them, the training process of the scattering compensation model includes: The scattering compensation model is trained based on a deep learning model. The input layer is historical underwater images, and the output layer is scattering compensation images. When it is detected that the number of training times reaches a preset upper limit or the mean square error of the images is higher than a preset target value, the trained model is obtained.

[0061] It should be noted that, first, perform frequency-domain analysis on the current frame image (such as through Fourier transform or wavelet transform), extract and count the energy proportion of its high-frequency components (such as high-frequency components corresponding to image edges and texture details) in the overall spectrum. If the proportion of high-frequency components is lower than a preset threshold (such as 30%), it indicates that the image has problems such as blurriness, insufficient details, or low contrast; at this time, the system will trigger the clarity optimization process, enhance image details by enhancing high-frequency information (such as applying the Unsharp Masking sharpening algorithm, high-pass filtering, or adaptive contrast enhancement), and at the same time suppress noise interference, and finally generate an optimized image. This process quantifies the image clarity through frequency-domain features, dynamically triggers targeted enhancement, and ensures that the output image improves the visibility of details while maintaining a natural look and feel.

[0062] In one implementation, the training process of the scattering compensation model based on the U-Net network is as follows: First, use 5000 labeled underwater images as the training set, where the input is the original underwater image with scattering interference, and the output is the scattering compensation image of the artificial restoration or ideal scenario (such as a clear target image generated by the laboratory standard method). The model adopts the U-Net architecture, which includes an encoder-decoder structure and cross-layer feature fusion (skip connection) to retain spatial details and enhance the feature expression ability. During training, the input image is input into the network after data augmentation (such as random cropping, rotation) and normalization processing, and the compensated image prediction result is generated through forward propagation. The loss function uses the mean square error (MSE) to measure the pixel-level difference between the predicted image and the target image, and the gradient is backpropagated through the Adam optimizer to update the network parameters. The training process continues to iterate and terminates when one of the following conditions is met: 1) reaching the preset maximum number of training epochs (such as 500); 2) the MSE on the validation set has not decreased for several consecutive epochs, or the current MSE is lower than the preset target threshold (such as 0.01). The finally converged model is the trained scattering compensation model, which can effectively learn the suppression law of underwater scattering and output a clear image after removing scattering.

[0063] In summary, the present invention discloses an automatic focusing method for imaging in a narrow space based on depth of field analysis, which can improve the accuracy and focusing speed of automatic focusing for imaging in a narrow space.

[0064] Referring to Figure 2 , the second embodiment of the present invention provides an automatic focusing system for imaging in a narrow space based on depth of field analysis, including: A data acquisition module, configured to acquire original image data and perform refraction correction according to the original image data to obtain an initial depth of field distribution map; A scattering interference module, configured to perform scattering interference analysis based on the initial depth-of-field distribution map to obtain an interference intensity distribution; A candidate focus module, configured to perform focus analysis based on the interference intensity distribution to obtain a set of candidate foci; An exposure optimization module, configured to perform exposure optimization based on the set of candidate foci to obtain an optimized focus set; A locking threshold module, configured to calculate a locking threshold for the best imaging position based on the optimized focus set; A result output module, configured to trigger focus locking and perform scattering compensation when the distance between the target position and the best imaging position is less than the locking threshold, and output a high-precision imaging result.

[0065] It should be noted that an automatic focusing system for imaging in a narrow space based on depth-of-field analysis provided by an embodiment of the present invention is used to execute all the process steps of an automatic focusing method for imaging in a narrow space based on depth-of-field analysis in the above embodiment. The working principles and beneficial effects of the two correspond one by one, and thus will not be elaborated here.

[0066] An embodiment of the present invention further provides an electronic device. The electronic device includes: a processor, a memory, and a computer program stored in the memory and executable on the processor, such as a data acquisition program. When the processor executes the computer program, the steps in the above embodiments of the automatic focusing method for imaging in a narrow space based on depth-of-field analysis are implemented, such as Figure 1 the step S11 shown. Alternatively, when the processor executes the computer program, the functions of each module / unit in the above device embodiments are implemented, such as the data acquisition module.

[0067] Exemplarily, the computer program can be divided into one or more modules / units. The one or more modules / units are stored in the memory and executed by the processor to complete the present invention. The one or more modules / units can be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program in the electronic device.

[0068] The electronic device can be a computing device such as a desktop computer, a notebook, a palm computer, and a smart tablet. The electronic device may include, but is not limited to, a processor and a memory. Those skilled in the art can understand that the above components are only examples of the electronic device, and do not constitute a limitation to the electronic device. It may include more or fewer components than the above, or combine some components, or different components. For example, the electronic device may further include input / output devices, network access devices, a bus, etc.

[0069] The so-called processor may be a Central Processing Unit (CPU), or may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The processor is the control center of the electronic device, and connects various parts of the entire electronic device through various interfaces and lines.

[0070] The memory can be used to store the computer programs and / or modules. The processor realizes various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory, and by calling the data stored in the memory. The memory mainly includes a program storage area and a data storage area. Among them, the program storage area can store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.); the data storage area can store data created according to the use of the mobile phone (such as audio data, phone book, etc.). In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, at least one magnetic disk storage device, a flash memory device, or other volatile solid-state storage devices.

[0071] Among them, if the modules / units integrated in the electronic device are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, to implement all or part of the processes in the above-described embodiment methods of the present invention, it can also be completed by a computer program instructing relevant hardware. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above-described various method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file, or some intermediate form, etc. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disc, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium, etc. It should be noted that the content included in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.

[0072] It should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. In addition, in the attached drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that they have a communication connection, which can be specifically implemented as one or more communication buses or signal lines. Those of ordinary skill in the art can understand and implement it without creative efforts.

[0073] The specific embodiments described above have further elaborated on the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only the specific embodiments of the present invention and is not used to limit the protection scope of the present invention. It is particularly pointed out that for those skilled in the art, any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for automatically focusing in narrow space imaging based on depth of field analysis, characterized in that: include: Acquiring original image data, and performing refraction correction according to the original image data to obtain an initial depth of field distribution map; Perform scattering interference analysis according to the initial depth of field distribution map to obtain interference intensity distribution; Performing focus analysis according to the interference intensity distribution to obtain a candidate focus set; Performing exposure optimization according to the candidate focus set to obtain an optimized focus set; Calculate the locking threshold according to the optimized focus set to obtain the locking threshold of the optimal imaging position; When the distance between the target position and the optimal imaging position is less than the locking threshold, focus locking is triggered, and scattering compensation is performed to output a high-precision imaging result.

2. The method for automatically focusing narrow space imaging based on depth of field analysis according to claim 1, characterized in that: The acquiring of original image data and performing refraction correction according to the original image data to obtain an initial depth of field distribution map includes: Get the original image data; Performing phase difference calculation based on the original image data and a preset sensor array to obtain image visual difference; The initial depth of field value is calculated by the following formula: ; in, represents the initial depth of field value, represents the focal length, represents the baseline value, represents the visual difference of the image, Indicates the conversion factor; Refraction correction is performed according to the initial depth of field value to obtain an initial depth of field distribution map.

3. The method for automatically focusing narrow space imaging based on depth of field analysis according to claim 1, characterized in that: The performing scattering interference analysis according to the initial depth of field distribution map to obtain interference intensity distribution includes: Perform image segmentation according to the initial depth of field distribution map to obtain an image foreground and an image background; Perform boundary detection based on the image foreground and the image background to obtain a light scattering boundary; Performing region growing according to the light scattering boundary to obtain a light scattering region; Calculating interference intensity according to the light scattering area to obtain scattering interference intensity; Smoothing filtering is performed according to the scattering interference intensity to obtain interference intensity distribution.

4. The method for automatically focusing narrow space imaging based on depth of field analysis according to claim 1, characterized in that: The performing focus analysis according to the interference intensity distribution to obtain a candidate focus set includes: Performing region segmentation according to the interference intensity distribution to obtain local regions with different scattering intensities; Performing correlation analysis based on the clarity and depth of field parameters of the local area to obtain regional correlation; When the region correlation is greater than or equal to a preset correlation threshold, determining that the local region is a valid region; When the region correlation is less than the correlation threshold, determining that the local region is invalid; Generate focus according to the effective area to obtain an original focus set; Performing structural similarity calculation based on the original focus set and a pre-stored target clarity template to obtain focus structure similarity; Eliminate non-candidate points according to the focus structure similarity to obtain a valid focus set; Redundant points are eliminated according to the effective focus set to obtain a candidate focus set.

5. The method for automatically focusing narrow space imaging based on depth of field analysis according to claim 1, characterized in that: The step of performing exposure optimization according to the candidate focus set to obtain an optimized focus set includes: Performing region segmentation on the original image data according to the candidate focus set to obtain a first local region; Performing glare detection according to the first local area to obtain a local glare area; Calculating the brightness gradient of the local glare area to obtain gradient distribution data; Performing smoothing filtering on the local glare area according to the gradient distribution data to obtain a brightness adjustment parameter; The set is optimized according to the brightness adjustment parameters to obtain an optimized focus set.

6. The method for automatically focusing narrow space imaging based on depth of field analysis according to claim 1, characterized in that: The step of calculating the locking threshold value according to the optimized focus set to obtain the locking threshold value of the optimal imaging position includes: Calculate the depth of field range and image clarity of each focus area according to the optimized focus set; Performing weighted summation according to the depth of field range and the image clarity to obtain a balance coefficient; When the balance coefficient is greater than a preset coefficient threshold, determining that the focus area is a candidate area for optimal imaging; Calculating the geometric center of the candidate area as the optimal imaging position; The minimum distance from the optimal imaging position to the boundary is calculated as a locking threshold of the optimal imaging position.

7. The method for automatically focusing narrow space imaging based on depth of field analysis according to claim 1, characterized in that: When the distance between the target position and the optimal imaging position is less than the locking threshold, the focus locking is triggered, scattering compensation is performed, and a high-precision imaging result is output, including: Get the current frame image; Performing a fast Fourier transform on the current frame image to obtain image frequency domain features; Extracting the proportion of high-frequency components according to the frequency domain features of the image; When the proportion of the high-frequency component is lower than a preset ratio threshold, the clarity of the current frame image is optimized to obtain an optimized image; Inputting the optimized image into a pre-trained scattering compensation model to output a high-precision imaging result; The training process of the scattering compensation model includes: The scatter compensation model is trained based on a deep learning model, the input layer is a historical underwater image, and the output layer is a scatter compensation image. When it is detected that the number of training times reaches a preset upper limit or the mean square error of the image is higher than a preset target value, the trained model is obtained.

8. A narrow space imaging autofocus system based on depth of field analysis, characterized in that: include: A data acquisition module, used to acquire original image data, and perform refraction correction according to the original image data to obtain an initial depth of field distribution map; A scattering interference module, used to perform scattering interference analysis according to the initial depth of field distribution map to obtain interference intensity distribution; A candidate focus module, used for performing focus analysis according to the interference intensity distribution to obtain a candidate focus set; an exposure optimization module, configured to perform exposure optimization according to the candidate focus set to obtain an optimized focus set; A locking threshold module, used to calculate the locking threshold according to the optimized focus set to obtain the locking threshold of the optimal imaging position; The result output module is used to trigger focus locking when the distance between the target position and the optimal imaging position is less than the locking threshold, perform scattering compensation, and output high-precision imaging results.

9. An electronic device, characterized in that: The invention comprises a processor, a memory and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the method for automatically focusing narrow space imaging based on depth of field analysis as described in any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the narrow space imaging automatic focusing method based on depth of field analysis as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Endoscope objective optical system and imaging device

    CN104246573A

  • Photographing method and mobile terminal

    CN105163034A

  • Aberration correction method and optical device

    CN110520779A

  • Confocal optical device, and spherical-aberration correction method

    US20060098213A1

Cited By

  • Microscope camera imaging virtual focus detection method and system based on calibration plate

    CN121540394A

  • Machine vision automatic precision focusing method and system based on dual-mode evaluation

    CN121832041A

  • A machine vision automatic precision focusing method and system based on dual-mode evaluation

    CN121832041B