MTF detection method and system based on image vision
The MTF detection method based on image vision solves the problems of insufficient real-time performance and efficiency in existing automatic focusing technology, and achieves a high-precision and fast focusing process, which is suitable for autonomous driving and industrial inspection.
Patent Information
- Application Number
- CN202511174924.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-21
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2045-08-21
AI Technical Summary
Existing image clarity detection methods lack real-time and efficiency in automatic focusing technology, making it difficult to meet high-performance requirements such as autonomous driving.
The MTF detection method based on image vision is adopted. The maximum inter-class variance algorithm is used to segment the image, extract the outline of the bright block, calculate the center point coordinates, construct the ROI image, perform grid matching and clarity calculation, and output the focusing instruction.
It improves focusing accuracy and real-time performance, reduces calculation workload, reduces manual dependence, adapts to different hardware platforms, and meets high-precision focusing requirements.
Smart Images

Figure CN120689345A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer vision and target detection, and in particular to an MTF detection method and system based on image vision. Background Art
[0002] Imaging technology is widely used in digital cameras, medical endoscopes, industrial inspection equipment, and many other fields. Clear images are essential for meeting the needs of various scenarios. Due to the limited depth of field of imaging systems, it is difficult to clearly image different parts of a scene simultaneously. Therefore, focusing is a critical step in ensuring that the target object is in the optimal imaging position.
[0003] Early focusing relied on manual operation, which was inefficient and required a high level of user experience. With the development of computer technology, automatic focusing technology has emerged. Traditional automatic focusing mostly uses distance measurement methods, which have problems such as large measurement errors, high costs, and reduced accuracy. After the 1990s, automatic focusing technology based on image processing became mainstream, driving focusing by analyzing image clarity evaluation values. In recent years, the development of artificial intelligence, deep learning, and new optical components has brought new opportunities for focusing technology, but existing image clarity detection methods still need to be improved in terms of real-time performance and efficiency, and it is difficult to meet the high-performance requirements of scenarios such as autonomous driving.
[0004] Therefore, there is an urgent need to provide a new technical solution to solve the above problems. Summary of the Invention
[0005] The present invention aims to overcome at least one technical problem existing in the prior art and provides an MTF detection method and system based on image vision.
[0006] On the one hand, an embodiment of the present invention provides an MTF detection method based on image vision, the detection method comprising: step S1, collecting standard projection chart image data containing regular bright blocks; step S2, segmenting the image data using a maximum inter-class variance algorithm to obtain a binary image, wherein the white area represents the detected bright block contour; step S3, extracting the bright block contours in the binary image, calculating the area of each bright block contour, and filtering out contours with an area less than a preset threshold; step S4, calculating the center point coordinates of each bright block contour among the remaining bright block contours, and brute-force searching for the N bright block contour center points with the smallest sum of Euclidean distances; step S5, extracting N bright block contours corresponding to the N bright block contour center points, and constructing the minimum circumscribed rectangle of the N bright block contours to obtain an ROI image; step S6, determining the bright block contour closest to the center point of the ROI image as the center block; step S7, dividing the ROI image into equal parts. The method comprises the following steps: a step of associating a bright block contour with a grid area by distance matching, achieving a one-to-one correspondence between the bright block contour and the grid area; a step of ignoring the central block, separating the bright block contour to obtain a horizontal line pair area and a vertical line pair area, and extracting a central narrow band of the horizontal line pair area and the vertical line pair area respectively; a step of calculating the grayscale curves of the horizontal line pairs and the vertical line pairs in the central narrow band; a step of calculating the MTF values of the horizontal line pair area and the vertical line pair area based on the grayscale curves; a step of obtaining the MTF value of the corresponding bright block contour by combining the MTF value of the horizontal line pair area and the MTF value of the vertical line pair area; and a step of outputting a corresponding focusing instruction based on the MTF values of the N bright block contours.
[0007] Furthermore, the step S4 includes: step S401, calculating the Euclidean distance between every two bright block contour center points based on the coordinates of the bright block contour center points; step S402, calculating the sum of the distances between each bright block contour center point and other bright block contour center points; step S403, obtaining N bright block contour center points with the smallest total distance.
[0008] Furthermore, the step S7 includes: step S701, The grid is marked based on the position of the bright block outline in the ROI image, and marked as area 1 to area N; step S702, the center block corresponds to The center area of the grid; step S703, calculate the center coordinates of the remaining N-1 bright block outlines, and calculate their distances to the center of the area 1 to area N respectively; step S704, assign the remaining N-1 bright block outlines to the area closest to them.
[0009] Furthermore, the step S8 includes: step S801, separating the bright block outline according to the grid position to obtain a left sub-area as a longitudinal line pair area and a right sub-area as a transverse line pair area; step S802, taking a center line along the width direction of the transverse line pair area, and expanding K pixels to the left and right to form a central narrow band; step S803, rotating the longitudinal line pair area 90 degrees, taking a center line along the width direction, and expanding K pixels to the left and right to form a central narrow band.
[0010] Furthermore, the step S8 further includes: for the central block, taking a central line along the width direction, and extending K pixels to the left and right to form a central narrow band.
[0011] Furthermore, the step S9 includes: step S901, calculating the grayscale average value of all pixels in each row of pixels in the central narrow band; step S902, forming a grayscale value curve based on the grayscale average value.
[0012] Furthermore, the step S10 includes: step S1001, using a one-dimensional Gaussian kernel function to process the gray value curve to obtain a smooth gray value curve g(x); step S1002, taking the first-order derivative of the smooth gray value curve g(x) to obtain a first-order gray value curve ; Step S1003, positioning the first-order gray value curve The peak value of the half width height corresponding to the peak value is calculated; step S1004, the half width height is calculated based on the preset conversion formula to obtain the MTF value of the horizontal line pair area and the vertical line pair area.
[0013] Furthermore, the step S1003 further includes: when the first-order gray value curve When there are multiple peaks, calculate the half-width height corresponding to each peak, and calculate the average value of multiple half-width heights as the first-order gray value curve The half-width height.
[0014] Furthermore, the step S12 includes: generating module front-to-back distance adjustment instructions, left-right rotation adjustment instructions, and up-down rotation adjustment instructions based on the MTF values of the brightness profiles at different positions.
[0015] In a second aspect, an embodiment of the present invention provides an MTF detection system based on image vision, which is implemented by the above-mentioned MTF detection method based on image vision. The detection system includes: an image data acquisition module, which is suitable for acquiring standard projection chart image data containing regular bright blocks; an image segmentation module, which is suitable for segmenting the image data using the maximum inter-class variance algorithm to obtain a binary image, wherein the white area represents the detected bright block contour; an ROI image extraction module, which is suitable for extracting the bright block contours in the binary image, calculating the area of each bright block contour, and screening out contours with an area less than a preset threshold; calculating the center point coordinates of each bright block contour in the remaining bright block contours, and brute-force searching for the N bright block contour center points with the smallest sum of Euclidean distances; extracting the N bright block contours corresponding to the N bright block contour center points, and constructing the minimum circumscribed rectangle of the N bright block contours to obtain the ROI image; a center block extraction module, which is suitable for determining the bright block contour closest to the center point of the ROI image as the center block; a bright block contour positioning module, which is suitable for dividing the ROI image into equal parts. A grid is provided, wherein the bright block contour and the grid area are associated by distance matching to achieve a one-to-one correspondence between the bright block contour and the grid area; a clarity index calculation module is adapted to ignore the central block, separate the bright block contour into a horizontal line pair area and a vertical line pair area, and extract the central narrow bands of the horizontal line pair area and the vertical line pair area respectively; calculate the grayscale curves of the horizontal line pairs and the vertical line pairs in the central narrow bands; calculate the MTF values of the horizontal line pair area and the vertical line pair area based on the grayscale curves; and obtain the MTF value of the corresponding bright block contour by combining the MTF values of the horizontal line pair area and the MTF values of the vertical line pair area; and a feedback module is adapted to output a corresponding focusing instruction based on the MTF values of the N bright block contours.
[0016] In a third aspect, an embodiment of the present invention further provides an electronic device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the above-mentioned image-vision-based MTF detection method when executed by the processor.
[0017] In a fourth aspect, an embodiment of the present invention further provides a readable storage medium, which, when the instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to perform the above-mentioned MTF detection method based on image vision.
[0018] Compared with the prior art, the present invention has the following beneficial effects: the image vision-based MTF detection method achieves multi-dimensional technical effects through targeted technical design and algorithm optimization, as follows: (1) Improve detection accuracy and ensure focusing accuracy: Through bright block segmentation, ROI extraction (screening 9 core bright areas) and center contour positioning, interference factors such as noise, shadows, and irrelevant background in the image are eliminated, and the calculation is focused on key areas sensitive to clarity (bright areas including horizontal / vertical stripes) to avoid interference from invalid areas on the results. The 8 non-central areas are divided into left and right parts, and the clarity is calculated for the horizontal and vertical stripe lines respectively (edge sharpness is quantified by the half-height width of the derivative curve). The sharpness of the stripe edge directly reflects the image clarity. The indicator has a clear physical meaning and can accurately capture the impact of focal length changes on image quality, ensuring the accuracy of focusing judgment. The clarity indicators of 17 key parts (8 areas × 2 parts + central area related reference) are integrated to avoid misjudgment caused by single area errors, comprehensively reflect the overall imaging quality of the projection module, and improve the reliability of focusing results.
[0019] (2) Reduce computational complexity and improve real-time performance: Through contour screening and minimum circumscribed moment fitting, the processing area is cropped from the entire image (4000×3000 pixels) to an ROI containing only 9 core bright areas, significantly reducing the computational scope and reducing the processing cost of invalid pixels. Mature and efficient image processing algorithms such as OTSU threshold segmentation and OpenCV contour detection are used, combined with optimization methods such as brute force search to screen clustered contours and Gaussian filtering to smooth noise, to avoid the high computational load of complex models or full-image traversal. The single-frame processing time is controlled at ≤30ms, meeting the real-time requirements of dynamic focus scenes. It can quickly respond to focal length changes and output adjustment instructions to ensure the continuity and efficiency of the focusing process.
[0020] (3) Automated operation reduces manual dependence: From image acquisition, preprocessing (grayscale conversion, binarization), region extraction to clarity calculation and focusing command output, no manual intervention is required throughout the entire process. Analysis and judgment are automatically completed through algorithms, reducing the impact of manual experience on focusing results and avoiding subjective errors.
[0021] (4) Technical universality and scalability: The system uses conventional industrial cameras (such as the Basler acA2440-75um) and a general image processing library (OpenCV), eliminating the need for specialized hardware, reducing deployment costs, and facilitating porting across different hardware platforms. The clarity index calculation logic (such as fringe direction and half-height width parameter K) can be adjusted to specific scene requirements (e.g., the K value can be modified as needed), adapting to test charts of varying fringe densities and sizes, and flexibly addressing diverse focus detection needs. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The present invention will be further described below with reference to the accompanying drawings and examples.
[0023] Figure 1 This is a flow chart of an MTF detection method based on image vision provided in Example 1 of the present invention.
[0024] Figure 2 This is a schematic diagram of image data of a standard projection chart card containing regular bright blocks provided by Example 1 of the present invention.
[0025] Figure 3 This is a schematic diagram of a binary image provided by Example 1 of the present invention.
[0026] Figure 4 This is a schematic diagram of an ROI image provided by Example 1 of the present invention.
[0027] Figure 5 This is a schematic diagram of a central block provided by Example 1 of the present invention.
[0028] Figure 6This is a method provided by Example 1 of the present invention after region marking. Grid diagram.
[0029] Figure 7 This is a schematic diagram of a one-to-one correspondence between a bright block outline and a grid area provided by Example 1 of the present invention.
[0030] Figure 8 This is a schematic diagram of a horizontal line pair area and a vertical line pair area provided in Example 1 of the present invention.
[0031] Figure 9 This is a schematic diagram of a central narrow band provided by Example 1 of the present invention.
[0032] Figure 10a This is a schematic diagram of an original grayscale value curve without Gaussian processing provided in Example 1 of the present invention.
[0033] Figure 10b This is a schematic diagram of a smoothed grayscale value curve after Gaussian processing provided by Example 1 of the present invention.
[0034] Figure 11 This is a schematic diagram of a first-order grayscale value curve provided by Example 1 of the present invention.
[0035] Figure 12 This is a schematic diagram of the structure of an MTF detection system based on image vision provided in Example 2 of the present invention.
[0036] Figure 13 This is a partial block diagram of an electronic device provided by Example 3 of the present invention. DETAILED DESCRIPTION
[0037] Before discussing the exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flow charts. Although the flow charts describe the various operations as sequential processes, many of the operations therein can be implemented in parallel, concurrently, or simultaneously. In addition, the order of the various operations can be rearranged. The process can be terminated when its operation is completed, but can also have additional steps not included in the accompanying drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0038] It should be understood that although the terms "first," "second," and the like may be used herein to describe various elements, these elements should not be limited by these terms. These terms are used solely to distinguish one element from another. For example, a first element may be referred to as a second element, and similarly, a second element may be referred to as a first element, without departing from the scope of the exemplary embodiments. The term "and / or" as used herein includes any and all combinations of one or more of the listed associated items.
[0039] The present invention will now be described in detail with reference to the accompanying drawings. This figure is a simplified schematic diagram, which only illustrates the basic structure of the present invention in a schematic manner, and therefore only shows the components related to the present invention.
[0040] Example 1 For ease of understanding, before elaborating on the specific solutions of this embodiment, the overall inventive concept of the present invention is summarized here: The present invention aims to address the problems of insufficient real-time performance and efficiency in focusing systems in the prior art, and provides an MTF detection method and system based on image vision. By optimizing the image acquisition, processing, and clarity calculation processes, the problems of insufficient real-time performance and efficiency in focusing systems caused by existing image clarity detection methods are addressed, providing a basis for precise fine-tuning of the focusing mechanism for application in high-precision focusing scenarios such as autonomous driving and industrial inspection. Specifically, the method is as follows: Image acquisition: A 12-megapixel industrial camera is used to capture a projection chart to obtain high-quality raw image data. The image features of the projection chart reflect the imaging quality of the focusing system, and the high pixel count ensures the preservation of image details. Bright block segmentation: The maximum inter-class variance algorithm (OTSU algorithm) is used to divide the image into a foreground bright block region and a background, maximizing the inter-class variance and achieving separation between the bright block and background, laying the foundation for subsequent operations. ROI Extraction: First, extract bright block contours, filter out contours with too small an area to remove noise. Then, by calculating the Euclidean distance between the contour center points, select the nine most clustered contours. Finally, fit their minimum circumscribed moments to determine the region of interest (ROI), reducing unnecessary computational effort. Center Contour Determination: Calculate the distance between the center points of the nine contours and the image center, identifying the contour with the smallest distance as the center contour to clarify the spatial reference of the detection area. Region Matching: Divide the ROI into 25 equal regions, calculate the coordinates of the center points of some regions, and use the Euclidean distance to match the eight contours other than the center contour to the nearest region to achieve orderly contour location. Region Subdivision and Jumping: Divide the eight non-center regions equally into a left region containing vertical line pairs and a right region containing horizontal line pairs. Sharpness calculation is performed using different processes for each region. Sharpness Calculation: Using horizontal line pairs as an example, the calculation region is first determined. Then, the average grayscale value of each line within the region is calculated to generate a grayscale value curve. After Gaussian filtering, the curve is differentiated according to the MTF calculation principle to calculate the peak width of the derivative curve, which is used as a sharpness indicator. Finally, the image quality is comprehensively judged based on the clarity indicators of multiple areas, and the focusing mechanism is assisted in fine-tuning.
[0041] The specific implementation is as follows: like Figure 1 FIG. 1 is a flow chart of an MTF detection method based on image vision provided by the present invention.
[0042] As an example, the detection method includes: step S1, collecting standard projection chart image data containing regular bright blocks; step S2, using the maximum inter-class variance algorithm to segment the image data to obtain a binary image, wherein the white area represents the detected bright block contour; step S3, extracting the bright block contours in the binary image, calculating the area of each bright block contour, and screening out contours with an area less than a preset threshold; step S4, calculating the center point coordinates of each bright block contour in the remaining bright block contours, and brute-force searching for the N bright block contour center points with the smallest sum of Euclidean distances; step S5, extracting N bright block contours corresponding to the N bright block contour center points, and constructing the minimum circumscribed rectangle of the N bright block contours to obtain an ROI image; step S6, determining the bright block contour closest to the center point of the ROI image as the center block; step S7, dividing the ROI image into equal parts. The grid is constructed by associating the bright block outline with the grid area through distance matching to obtain the grid position corresponding to each bright block outline; step S8, ignoring the central block, separating the bright block outline according to the grid position to obtain the horizontal line pair area and the vertical line pair area, and extracting the central narrow bands of the horizontal line pair area and the vertical line pair area respectively; step S9, calculating the grayscale curves of the horizontal line pairs and the vertical line pairs in the central narrow band; step S10, calculating the MTF values of the horizontal line pair area and the vertical line pair area based on the grayscale curves; step S11, combining the MTF values of the horizontal line pair area and the MTF values of the vertical line pair area to obtain the corresponding MTF value of the bright block outline; step S12, outputting the corresponding focusing instruction based on the MTF values of the N bright block outlines.
[0043] In some feasible embodiments, combined with Figure 2 As shown, step S1, capturing image data of a standard projection chart containing regular bright blocks, includes using a 12-megapixel industrial camera (e.g., the optional Basler acA2440-75um model, with a frame rate of 25 fps) to capture image data from the standard projection chart. The standard projection chart is a preset high-contrast test chart containing nine regularly spaced bright areas with horizontal and vertical stripe patterns within them. The camera is secured by a bracket, with the lens optical axis perpendicular to the plane of the projection chart. The acquisition environment is uniform white light (illuminance controlled within 500-800 lux), ensuring that the image is free of significant reflections or shadows. The captured original image is in RGB format with a resolution of 4000 × 3000 pixels and is stored in uncompressed BMP format for subsequent processing. It should be noted that there is no restriction on the camera model used here.
[0044] In some possible implementations, combined Figure 3As shown, step S2, segmenting the image data using the maximum inter-class variance algorithm to obtain a binary image, wherein the white areas represent the detected bright block outlines, includes: first converting the RGB image acquired in step S1 into a grayscale image (grayscale value calculation formula: Gray = 0.299R + 0.587G + 0.114B), and then using the maximum inter-class variance algorithm (OTSU algorithm) to perform bright block segmentation. By traversing the grayscale value range (0-255), calculating the inter-class variance when each grayscale value is used as a threshold, selecting the threshold with the largest inter-class variance (in this embodiment, the threshold range is typically 150-200), and dividing the image into foreground (bright blocks, grayscale value ≥ threshold) and background (grayscale value < threshold), thereby obtaining a binary image and achieving preliminary separation of bright blocks from background.
[0045] In some feasible implementations, step S3, extracting the bright block contours in the binary image, calculating the area of each bright block contour, and screening out contours with an area smaller than a preset threshold, includes: calculating the areas of all bright block contours obtained in step S2, and discarding those with too small an area (which may be noise or unimportant parts). Specifically, contour detection is performed on the binary image obtained in step S2 (using OpenCV's findContours function, with the detection mode being RETR_EXTERNAL and the approximation method being CHAIN_APPROX_SIMPLE), and all bright block contours are extracted. The area of each contour is calculated (in pixels²), and an area threshold is set to 500 pixels². Contours with an area smaller than the threshold are screened out, and interfering contours such as noise and small light spots are removed. It should be noted that setting the area threshold is not a restriction here.
[0046] In some feasible embodiments, step S4, calculating the coordinates of the center point of each bright block outline in the remaining bright block outlines and brute-force searching for N bright block outline center points with the smallest sum of Euclidean distances, includes: step S401, calculating the Euclidean distance between every two bright block outline center points based on the coordinates of the bright block outline center points; step S402, calculating the sum of the distances between each bright block outline center point and the other bright block outline center points; and step S403, obtaining the N bright block outline center points with the smallest sum of distances. N is 9.
[0047] Specifically, the center coordinates of the remaining bright block contours are calculated, for example, using contour moments. A brute force search is used to calculate the Euclidean distance between any two center points. The sum of the distances between each contour and every other contour is calculated, and the nine bright block contours with the smallest sum of distances (i.e., the nine contours that are most spatially clustered) are selected.
[0048] In some possible implementations, combined Figure 4As shown, step S5, extracting N bright block contours corresponding to the center points of the N bright block contours and constructing a minimum bounding rectangle of the N bright block contours to obtain an ROI image, includes: fitting the minimum bounding rectangle of the 9 screened bright block contours using the minAreaRect function to obtain a rectangular area containing the 9 bright block contours, determining the area as a region of interest (ROI), and cropping the ROI area for subsequent processing to reduce invalid calculation areas.
[0049] In some feasible implementations, the step S6 of determining the bright block contour closest to the center point of the ROI image as the center block includes: calculating the distance between the center points of the 9 bright block contours in step S5 and the center of the ROI area (the ROI center coordinates are (W / 2, H / 2), where W and H are the ROI width and height), selecting the contour with the smallest distance as the center block, and marking it as the "center area", such as Figure 5 The outline of the bright block in the center is shown.
[0050] In some feasible implementations, the step S7 is to divide the ROI image into equal parts. The grid is obtained by associating the bright block outline with the grid area through distance matching, including: step S701, The grid is marked based on the position of the bright block outline in the ROI image, and marked as area 1 to area N; step S702, the center block corresponds to The center area of the grid; step S703, calculate the center coordinates of the remaining N-1 bright block outlines, and calculate their distances to the center of the area 1 to area N respectively; step S704, assign the remaining N-1 bright block outlines to the area closest to them.
[0051] Preferably, combined Figure 6 As shown in FIG, the ROI image obtained in step S5 is equally divided into 25 sub-regions of the same size (5 rows in the horizontal direction and 5 columns in the vertical direction), wherein, according to the corresponding positions of the contours of different bright blocks in the ROI image, The grid area corresponding to the first row and first column in the grid is marked as area 1, the grid area corresponding to the first row and fifth column is marked as area 2, the grid area corresponding to the second row and second column is marked as area 5, the grid area corresponding to the second row and fourth column is marked as area 6, the grid area corresponding to the third row and third column is marked as the center block area, the grid area corresponding to the fourth row and second column is marked as area 7, the grid area corresponding to the fourth row and fourth column is marked as area 8, the grid area corresponding to the fifth row and first column is marked as area 3, and the grid area corresponding to the fifth row and fifth column is marked as area 4. Figure 7As shown, the eight bright block contours except the center block are traversed, the Euclidean distance between the center point of each bright block contour and the center points of regions 1 to 8 is calculated, and each bright block contour is matched to the region closest to it to complete the correspondence between the contour and the region.
[0052] Because the spatial position of the nine bright block outlines in the ROI image may fluctuate due to slight deviations in the shooting angle, slight displacement of the chart, etc., by matching them to the preset 25 sub-areas, the relative spatial position of each outline (such as the "upper left area" and "lower right area") can be fixed, avoiding errors caused by confusion in outline positions in subsequent calculations.
[0053] In some feasible implementations, step S8, ignoring the central block, separating the bright block outline according to the grid position to obtain a horizontal line pair area and a vertical line pair area, and extracting the central narrow bands of the horizontal line pair area and the vertical line pair area respectively, includes: step S801, separating the bright block outline according to the grid position to obtain a left sub-area as the vertical line pair area and a right sub-area as the horizontal line pair area; step S802, taking a center line in the horizontal line pair area along the width direction, and expanding K pixels to the left and right to form a central narrow band; step S803, rotating the vertical line pair area 90 degrees, taking a center line along the width direction, and expanding K pixels to the left and right to form a central narrow band.
[0054] Preferably, taking the center line along the width direction of the horizontal line pair region includes: dividing the eight regions matched in step S7 into two equal parts along the horizontal direction (such as Figure 8 As shown, the left side occupies 1 / 2 width and the right side occupies 1 / 2 width), wherein the left part contains vertical stripe line pairs and the right part contains horizontal stripe line pairs.
[0055] Preferably, combined Figure 9 As shown, in the horizontal line pair area, the center line is taken along the width direction, and K pixels are extended to the left and right to form a central narrow band. The process includes: taking the horizontal line pair as an example to illustrate: extracting the ROI sub-region where the horizontal line pair is located, setting the width of the sub-region to be L, drawing a vertical line at X=L / 2, and extending K=8 pixels to the left and right of the vertical line (the K value can be adjusted according to needs), and determining the size to be The calculation area of the (center narrow band) is shown in Figure 1 (P is the height of the ROI sub-region). It should be noted that when displaying vertical line pairs, they need to be rotated 90 degrees and displayed as horizontal line pairs. The center narrow band is extracted using the same method as for horizontal line pairs. Since the method for extracting the center narrow band is the same, the method for extracting the center narrow band for vertical line pairs is not described here.
[0056] Preferably, step S8 further includes: taking a center line along the width direction of the central block and expanding it to the left and right by K pixels to form a central narrow band. That is, the central block is a horizontal line pair region. When calculating its MTF value, the step of separating the bright block outline according to the grid position to obtain horizontal line pair regions and vertical line pair regions in step S8 is unnecessary. Instead, the process of extracting the central narrow band of the horizontal line pair region in step S8 can be directly performed.
[0057] In some feasible embodiments, the step S9, calculating the grayscale curves of the horizontal line pairs and the vertical line pairs in the central narrow band, includes: step S901, calculating the grayscale average value of all pixels in each row of pixels in the central narrow band; step S902, forming a grayscale value curve based on the grayscale average value.
[0058] Preferably, the average grayscale value of each row (horizontally) of pixels in the central narrow band is calculated, and these average values are arranged according to pixel coordinates to obtain a curve showing the grayscale value changing with pixel coordinates, such as Figure 10a Ideally, this curve should show a sharp jump (when clear) or a smooth transition (when blurred) at the intersection of black and white stripes.
[0059] In some feasible implementations, the step S10 includes: step S1001, using a one-dimensional Gaussian kernel function to process the gray value curve to obtain a smooth gray value curve g(x), such as Figure 10b shown.
[0060] Preferably, due to the quality of the image captured by the camera, the data is relatively discrete and there will be multiple extreme points, so the gray value curve obtained in step S902 is first Gaussian filtered. Gaussian filtering principle: Gaussian filtering is a linear smoothing filtering method that performs weighted averaging of the signal based on the Gaussian function. The core idea is to perform weighted averaging on each data point and the points in its neighborhood, and the weight is determined by the Gaussian distribution function. The formula of the Gaussian distribution function is: ; in: is the standard deviation, which controls the smoothness of the filter; is the position offset from the center point. The smaller it is, the narrower the Gaussian curve is, the weaker the smoothing effect is, and more details are retained; The larger it is, the wider the Gaussian curve is, the stronger the smoothing effect is, and the more details are lost. Here, σ=1.5 is preferred.
[0061] In some feasible implementations, the step S10 includes: step S1002, obtaining a first-order gray value curve by calculating the first-order derivative of the smooth gray value curve g(x) .
[0062] Preferably, the smoothed gray value curve g(x) is first-order derived to obtain the first-order gray value curve ,like Figure 11 As shown. Physical meaning: first-order gray value curve The absolute value of represents the speed (steepness) of the grayscale change. At the junction of black and white stripes, the derivative of a clear image will have a high peak (fast change); the peak of a blurred image is low and wide (slow change).
[0063] The step S10 includes: step S1003, positioning the first-order gray value curve The peak value of the half width height corresponding to the peak value is calculated; step S1004, the half width height is calculated based on the preset conversion formula to obtain the MTF value of the horizontal line pair area and the vertical line pair area.
[0064] Preferably, the MTF calculation principle is: the clarity is directly related to the transition width of the stripe edge from black to white (or white to black). The narrower the transition (the sharper the edge), the higher the clarity (the higher the MTF value). The calculation method includes: finding the first-order gray value curve The peak value on the image is calculated; the full width at half maximum (FWHM) of the peak is calculated: at half the height of the peak, the width w of the peak is measured. A small w value indicates that the peak is very narrow, the grayscale changes are very steep, the edges are sharp, and the clarity is high (a high MTF value). A large w value indicates that the peak is very wide, the grayscale changes are gentle, the edges are blurred, and the clarity is low (a low MTF value). The relationship between the w value and MTF includes: Although w is directly calculated here, w is inversely proportional to the MTF value (usually between 0 and 1). The smaller w, the higher the corresponding MTF value. In practical applications, w may be used directly as a clarity evaluation value, or converted to a more standard MTF value through a custom formula.
[0065] Preferably, the step S1003 further includes: when the first-order gray value curve When there are multiple peaks, calculate the half-width height corresponding to each peak, and calculate the average value of multiple half-width heights as the first-order gray value curve The half-width height.
[0066] In some feasible embodiments, step S11, combining the MTF value of the horizontal line pair area and the MTF value of the vertical line pair area to obtain the corresponding MTF value of the bright block profile includes: taking the average of the MTF value of the horizontal line pair area and the MTF value of the vertical line pair area as the MTF value of the bright block profile.
[0067] In some feasible embodiments, step S12, outputting corresponding focusing instructions based on the MTF values of the N bright block profiles, includes generating module front-to-back distance adjustment instructions, left-to-right rotation adjustment instructions, and up-to-down rotation adjustment instructions based on the MTF values of the brightness profiles at different positions. Specifically, the module's front-to-back clarity is determined by the MTF of the bright block profile corresponding to the center region. By adjusting the module's front-to-back distance, a real-time clarity value is obtained, and the module's optimal position in terms of front-to-back distance is determined. The module's left-to-right clarity is determined by the MTF values of the bright block profile corresponding to regions 5, 6, 7, 8, 1, 2, or 3, 9. By rotating the module left-to-right, the MTF changes in the left and right regions can be observed in real time, allowing the module's optimal left-to-right angular position to be found. The module's top-to-bottom clarity is determined by the MTF values of the bright block profile corresponding to regions 1, 3, 5, 7, 6, 8, or 2, 4. By rotating the module up and down, the MTF changes in the top and bottom regions can be observed, allowing the module's optimal top-to-bottom angular position to be found.
[0068] The above implementation analyzes only nine specific bright block areas (rather than the entire image), significantly reducing computational complexity. Within the bright blocks, only stripes in specific directions (horizontally / vertically) are analyzed. Within the stripe area, only a narrow central band (2K pixels wide) is analyzed. While a brute-force search of nine points is computationally expensive, it is feasible and efficient for scenes with a limited number of contours (small after area filtering) and a clear target (nine). It is faster than full-image complex feature detection, resulting in real-time and efficient overall computation. This method is designed for standard projection charts and utilizes their regularly arranged bright blocks and stripes in specific directions. Through geometric positioning (25-grid matching) and directional separation, the processing logic is simplified. Through area filtering, finding the nine most clustered points, center positioning, and area matching, it effectively resists the effects of image noise, slight deformation, or positional offset. Based on the MTF principle, using full width at half maximum (FWHM) as a sharpness metric, the results are objective, quantifiable, and meet optical evaluation standards. Detailed sharpness data for multiple areas is provided, providing a basis for precise fine-tuning of the focus mechanism. This embodiment reduces the amount of full-image computation through precise region extraction and targeted algorithm optimization, improving detection real-time performance (single-frame processing time ≤ 30ms) and accuracy. It can be effectively applied to scenarios requiring high-precision focusing, such as autonomous driving and industrial inspection.
[0069] Example 2 See also Figure 12 , this embodiment provides a structural schematic diagram of an MTF detection system based on image vision.
[0070] As an example, the detection system is implemented using the MTF detection method based on image vision for the standard projection chart described in Example 1. The detection system includes: The image data acquisition module 120 is adapted to acquire image data of a standard projection chart containing regular bright blocks.
[0071] The image segmentation module 121 is adapted to segment the image data using a maximum inter-class variance algorithm to obtain a binary image, wherein the white area represents the outline of the detected bright block.
[0072] The ROI image extraction module 122 is adapted to extract the bright block contours in the binary image, calculate the area of each bright block contour, and filter out contours with an area smaller than a preset threshold; calculate the coordinates of the center point of each bright block contour among the remaining bright block contours, and perform a brute force search for the N bright block contour center points with the smallest sum of Euclidean distances; extract the N bright block contours corresponding to the N bright block contour center points, and construct a minimum circumscribed rectangle of the N bright block contours to obtain the ROI image.
[0073] The center block extraction module 123 is adapted to determine the bright block contour closest to the center point of the ROI image as the center block.
[0074] The bright block outline is positioned to the module 124, which is adapted to divide the ROI image into equal parts. Grid, associate the bright block outline with the grid area through distance matching to obtain the grid position corresponding to each bright block outline.
[0075] The clarity index calculation module 125 is adapted to ignore the central block, separate the bright block outline into a horizontal line pair region and a vertical line pair region according to the grid position, and extract the central narrow bands of the horizontal line pair region and the vertical line pair region, respectively; calculate the grayscale curves of the horizontal line pairs and the vertical line pairs in the central narrow bands; calculate the MTF values of the horizontal line pair region and the vertical line pair region based on the grayscale curves; and combine the MTF values of the horizontal line pair region and the vertical line pair region to obtain the corresponding MTF value of the bright block outline.
[0076] The feedback module 126 is adapted to output a corresponding focus instruction based on the MTF values of the N bright block contours.
[0077] It is not difficult to find that this embodiment is a system embodiment corresponding to the first embodiment, and this embodiment can be implemented in conjunction with the first embodiment. The relevant technical details mentioned in the first embodiment are still valid in this embodiment, and to reduce repetition, they are not repeated here. Accordingly, the relevant technical details mentioned in this embodiment can also be applied to the first embodiment.
[0078] It is worth noting that all modules involved in this embodiment are logical units. In actual applications, a logical unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. Furthermore, to highlight the innovations of this invention, this embodiment does not include units that are not closely related to solving the technical problems proposed by this invention. However, this does not mean that other units do not exist in this embodiment.
[0079] Example 3 See also Figure 13 An embodiment of the present invention further provides an electronic device, comprising: a memory and a processor; the memory stores at least one program instruction; the processor implements the image vision-based MTF detection method provided in Example 1 by loading and executing the at least one program instruction.
[0080] The memory 702 and processor 701 are connected using a bus. The bus can include any number of interconnected buses and bridges, connecting various circuits of one or more processors 701 and memory 702. The bus can also connect various other circuits such as peripheral devices, voltage regulators, and power management circuits. These are all well known in the art and, therefore, are not described further herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be a single component or multiple components, such as multiple receivers and transmitters, providing a unit for communicating with various other devices over a transmission medium. Data processed by the processor 701 is transmitted over a wireless medium via an antenna. Furthermore, the antenna receives data and transmits it to the processor 701.
[0081] The processor 701 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management, and other control functions. The memory 702 can be used to store data used by the processor 701 when performing operations.
[0082] Example 4 An embodiment of the present invention further provides a storage medium storing an image-based MTF detection method. When executed by a processor, the image-based MTF detection program implements the steps of the image-based MTF detection method described above. Because this storage medium incorporates all the technical solutions of all the aforementioned embodiments, it possesses at least all the beneficial effects brought about by the technical solutions of the aforementioned embodiments, and therefore will not be further elaborated upon here.
[0083] The above is only an embodiment of the present invention. Common knowledge such as the known specific structures and characteristics in the scheme is not described in detail here. Ordinary technicians in the field are aware of all common technical knowledge in the technical field of the invention before the application date or priority date, can obtain all existing technologies in the field, and have the ability to apply conventional experimental means before that date. Ordinary technicians in the field can improve and implement this scheme in combination with their own abilities under the inspiration given by this application. Some typical known structures or known methods should not become obstacles for ordinary technicians in the field to implement this application. It should be pointed out that for those skilled in the art, without departing from the structure of the present invention, several variations and improvements can be made, which should also be regarded as the scope of protection of the present invention. These will not affect the effect of the implementation of the present invention and the practicality of the patent. The scope of protection required by this application shall be based on the content of its claims, and the specific implementation methods and other records in the specification can be used to interpret the content of the claims.
Claims
1. An MTF detection method based on image vision, characterized in that: The detection method comprises: Step S1, collecting image data of a standard projection chart containing regular bright blocks; Step S2: using the maximum inter-class variance algorithm to segment the image data to obtain a binary image, wherein the white area represents the detected bright block outline; Step S3, extracting bright block contours from the binary image, calculating the area of each bright block contour, and filtering out contours whose area is smaller than a preset threshold; Step S4: Calculate the coordinates of the center point of each bright block outline in the remaining bright block outlines, and search for the N bright block outline center points with the smallest sum of Euclidean distances by brute force; Step S5: extracting N bright block contours corresponding to the center points of the N bright block contours, and constructing a minimum circumscribed rectangle of the N bright block contours to obtain an ROI image; Step S6: Determine the bright block outline closest to the center point of the ROI image as the center block; Step S7: Divide the ROI image into Grid, associating the bright block outline with the grid area through distance matching to achieve a one-to-one correspondence between the bright block outline and the grid area; Step S8: Ignore the central block, separate the bright block contour to obtain a horizontal line pair region and a vertical line pair region, and extract the central narrow bands of the horizontal line pair region and the vertical line pair region respectively; Step S9, calculating the grayscale curves of the horizontal line pairs and the vertical line pairs in the central narrow band; Step S10: Calculating the MTF values of the horizontal line pair region and the vertical line pair region based on the grayscale curve; Step S11, combining the MTF value of the horizontal line pair area and the MTF value of the vertical line pair area to obtain the corresponding MTF value of the bright block outline; Step S12: outputting a corresponding focus instruction based on the MTF values of the N bright block contours.
2. The MTF detection method based on image vision according to claim 1, characterized in that: The step S4 comprises: Step S401: Calculate the Euclidean distance between every two bright block outline center points based on the coordinates of the bright block outline center points; Step S402: Calculate the total distance between each bright block outline center point and other bright block outline center points; Step S403: Obtain N bright block outline center points with the smallest total distance.
3. The MTF detection method based on image vision according to claim 1, characterized in that: The step S7 comprises: Step S701: The grid is marked as region 1 to region N based on the position of the bright block outline in the ROI image; Step S702: The central block corresponds to The central area of the grid; Step S703: Calculate the center coordinates of the remaining N-1 bright block outlines, and calculate their distances to the center of regions 1 to N respectively; Step S704: assign the remaining N-1 bright block contours to the areas closest to them respectively.
4. The MTF detection method based on image vision according to claim 1, characterized in that: The step S8 comprises: Step S801, separating the bright block outline according to the grid position to obtain a left sub-region as a longitudinal line pair region and a right sub-region as a transverse line pair region; Step S802: Take a center line in the width direction of the horizontal line pair area and expand it by K pixels to the left and right to form a center narrow band; Step S803: Rotate the longitudinal line pair region by 90 degrees, take the center line along the width direction, and expand K pixels to the left and right to form a central narrow band.
5. The MTF detection method based on image vision according to claim 1, characterized in that: The step S8 further includes: For the central block, a central line is taken along the width direction and extended by K pixels to the left and right to form a central narrow band.
6. The MTF detection method based on image vision according to claim 1, characterized in that: The step S9 includes: Step S901: calculating the grayscale average value of all pixels in each row of pixels in the central narrow band; Step S902: forming a grayscale value curve based on the grayscale average value.
7. The MTF detection method based on image vision according to claim 6, characterized in that: The step S10 includes: Step S1001: Processing the grayscale value curve using a one-dimensional Gaussian kernel function to obtain a smooth grayscale value curve g(x); Step S1002: Calculate the first-order derivative of the smooth gray value curve g(x) to obtain a first-order gray value curve ; Step S1003: Position the first-order grayscale value curve The peak value of , calculate the half width height corresponding to the peak value; Step S1004 : calculating the half width and half height based on a preset conversion formula to obtain the MTF values of the horizontal line pair area and the vertical line pair area.
8. The MTF detection method based on image vision according to claim 7, characterized in that: The step S1003 further includes: when the first-order gray value curve When there are multiple peaks, calculate the half-width height corresponding to each peak, and calculate the average value of multiple half-width heights as the first-order gray value curve The half-width height.
9. The MTF detection method based on image vision according to claim 1, characterized in that: The step S12 includes: generating module front-to-back distance adjustment instructions, left-right rotation adjustment instructions, and up-down rotation adjustment instructions based on the MTF values of the brightness profiles at different positions.
10. An image-based MTF detection system, wherein the detection system is implemented using the image-based MTF detection method according to any one of claims 1 to 9, characterized in that: The detection system comprises: Image data acquisition module, suitable for acquiring image data of standard projection charts containing regular bright blocks; An image segmentation module, adapted to segment the image data using a maximum inter-class variance algorithm to obtain a binary image, wherein the white area represents the outline of the detected bright block; The ROI image extraction module is adapted to extract bright block contours from the binary image, calculate the area of each bright block contour, and filter out contours with an area smaller than a preset threshold; calculate the coordinates of the center point of each bright block contour among the remaining bright block contours, and perform a brute force search for the N bright block contour center points with the smallest sum of Euclidean distances; extract the N bright block contours corresponding to the N bright block contour center points, and construct a minimum circumscribed rectangle of the N bright block contours to obtain the ROI image; A center block extraction module is adapted to determine the bright block contour closest to the center point of the ROI image as the center block; The bright block outline positioning module is suitable for dividing the ROI image into Grid, associating the bright block outline with the grid area through distance matching to achieve a one-to-one correspondence between the bright block outline and the grid area; a clarity index calculation module, adapted to ignore the central block, separate the bright block outline into a horizontal line pair region and a vertical line pair region, extract central narrow bands of the horizontal line pair region and the vertical line pair region, respectively; calculate grayscale curves of the horizontal line pairs and the vertical line pairs in the central narrow bands; calculate MTF values of the horizontal line pair region and the vertical line pair region based on the grayscale curves; and combine the MTF values of the horizontal line pair region and the vertical line pair region to obtain an MTF value of the corresponding bright block outline; The feedback module is adapted to output a corresponding focusing instruction based on the MTF values of the N bright block contours.
Citation Information
Patent Citations
Vehicle taillight recognition method and device and vehicle
CN108021856A
Super-agile satellite task planning method and system considering image MTF degradation
CN117332624A
Camera resolution evaluation method and device, electronic equipment and storage medium
CN117522833A