Automatic focus fixing method based on image and spectrum combination
By combining image clarity and spectral characteristic peak intensity, efficient and precise focusing of spectral acquisition is achieved, which solves the problem of poor spectral signal quality in existing technologies and improves the efficiency and accuracy of spectral data acquisition.
Patent Information
- Application Number
- CN202510522684.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-24
- Publication Date
- 2025-09-05
AI Technical Summary
Existing automatic focusing methods have difficulty in accurately determining the sample coordinates for spectral acquisition in transparent or tilted samples, resulting in poor spectral signal quality.
Combining image and spectral methods, the optimal spectral acquisition position is obtained by coarse focus determination through image clarity assessment and precise focus determination through spectral characteristic peak intensity analysis.
It improves the collection efficiency and accuracy of spectral data, reduces the interference of transparent samples, and ensures the comprehensiveness and reliability of data.
Smart Images

Figure CN120594033A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of spectrum analysis, and in particular relates to an automatic focusing method based on the combination of image and spectrum. Background Art
[0002] During the measurement process of laser spectroscopy, the effect of laser focusing seriously affects the quality of the signal. Poor laser focusing will cause the signal stability of the system to deteriorate. Therefore, in spectral analysis, accurate focusing of the sample is a key step to ensure data quality. On the one hand, the existing more common automatic focusing methods are mostly based on the evaluation of image clarity, which has certain limitations. Especially in transparent samples or tilted solid samples, it is difficult for imaging methods to distinguish the gas-solid / liquid interface. Although some signals can be collected within a certain depth of transparent samples, the attenuation of the sample will also cause the quality of the spectral signal to deteriorate. On the other hand, the sample plane with the best image clarity and the sample plane with the highest spectral signal intensity are not necessarily located on the same horizontal plane. Relying solely on image focusing to determine the sample coordinates in spectral acquisition is not accurate enough. Therefore, there is an urgent need for an automated spectral focusing solution that can both improve efficiency and ensure data accuracy.
[0003] In view of this, the present invention proposes an automatic focusing method based on the combination of image and spectrum, which realizes rapid and accurate focusing of the sample to be tested by combining the coarse focusing method of the image method and the precise focusing of the spectrum method. Summary of the Invention
[0004] The technical problem to be solved by the present invention is to overcome the shortcomings of the existing technology, solve the problem that the sample coordinates in spectral acquisition determined by image focusing are not accurate enough and the collected spectral signals are poor, and provide an automatic focusing method based on the combination of image and spectrum.
[0005] In order to solve the above technical problems, the basic concept of the technical solution adopted by the present invention is as follows:
[0006] An automatic focusing method based on the combination of image and spectrum includes obtaining the best definition image and its coordinate position in the preset direction according to the different definition of the sample plane in the preset direction, and determining the spectrum collection area in the image accordingly;
[0007] The spectrum acquisition area is divided into multiple sub-areas to obtain several segmentation area maps, and the target segmentation area map and the plane coordinate range of the area where it is located are obtained according to the average image intensity of the segmentation area map;
[0008] Short-time spectrum acquisition is performed according to the coordinate information of the target segmentation area map, and the optimal fixed focus position for sample spectrum acquisition is obtained based on the spectral characteristic peak intensity and data model.
[0009] As a further embodiment of the present application, the preset direction is the Z direction relative to the sample plane, and the plane coordinate range of the target segmentation region map includes the coordinate range of the XY axis.
[0010] As a further embodiment of the present application, obtaining the best definition image and its coordinate position in a preset direction includes:
[0011] The spectrum acquisition system performs image autofocus to obtain sample plane images in several Z directions;
[0012] The Tenengrad evaluation function is used to quantitatively evaluate the clarity of the sample plane image and calculate the average grayscale value of each image;
[0013] Select the best clear image with the largest average gray value and determine its Z direction position.
[0014] As a further embodiment of the present application, a method for calculating the average grayscale value of each image includes:
[0015] S1. Calculate the Sobel operator convolution kernel G from the operator matrix x , G y for:
[0016] G x =g(x-1,y+1)+2g(x,y+1)+g(x+1,y+1)-g(x-1,y-1)-2g(x,y-1)-g(x+1,y-1)
[0017] G y =g(x+1,y-1)+2g(x+1,y)+g(x+1,y+1)-g(x-1,y-1)-g(x-1,y)-g(x-1,y+1);
[0018] The corresponding operator matrix is:
[0019] S2, Sobel convolution kernel G obtained in step S1 x , G y , get the gradient of image I at point (x, y):
[0020] S3. Based on the S(x,y) value obtained in step S2, the Tenengrad value of the image is calculated as:
[0021] Where n is the total number of pixels in the image.
[0022] As a further embodiment of the present application, determining the spectrum collection area in the image includes:
[0023] The best clear image obtained is compared with the image data model that has been trained in the spectrum acquisition system, and the spectrum acquisition area is obtained according to the image features.
[0024] As a further embodiment of the present application, obtaining the target segmentation region map and the plane coordinate range of the region where it is located includes:
[0025] Divide the spectrum acquisition area into x rectangular sub-areas of N*N pixels, and obtain several segmentation area maps, where x ≥ 9 and N ≥ 5;
[0026] Calculate the average image intensity of each segmented region map and obtain the image intensity value of each segmented region map;
[0027] Sort the image intensity values in order of size, and discard the segmentation region maps corresponding to the first 10% of the image intensity values with the smallest values;
[0028] The image with the smallest intensity value in the remaining segmentation region maps is output as the target segmentation region map, and the plane coordinate range of the region where the target segmentation region map is located is output.
[0029] As a further embodiment of the present application, the determination of the spectral acquisition area also includes: after obtaining the Z-direction coordinates obtained by focusing the image, the sample platform is moved in a small range in the Z direction, multiple spectra are collected within a preset time range, and spectral characteristic peak analysis is performed to obtain the position with the highest spectral intensity as the optimal spectral focusing position.
[0030] As a further embodiment of the present application, the preset time for spectrum acquisition is 0.01-0.15s.
[0031] As a further embodiment of the present application, the automatic focusing method based on the combination of image and spectrum also includes: according to the optimal spectral focusing position of the sample, the spectral acquisition system systematically collects spectral data according to actual spectral acquisition parameters.
[0032] After adopting the above technical solution, the present invention has the following beneficial effects compared with the prior art:
[0033] The automatic focusing method based on the combination of image and spectrum proposed in this invention obtains high-quality spectral data through a series of steps: image automatic focusing, feature area extraction, image area segmentation and image intensity assessment, automatic focusing, data analysis and processing, and provides a reliable basis for spectral data analysis. In addition, the systematic evaluation and acquisition process is efficient, precise and automated, which greatly improves the efficiency and accuracy of spectral acquisition.
[0034] Based on the collected spectral data, the spectral intensity is normalized into a spectrum graph, which is then used to train the spectral classification model. By comparing the full spectral features, it is confirmed whether the acquisition area is the actual sample area, thus avoiding interference from transparent layered samples. If the spectrum differs significantly from the spectrum in the data model, Raman spectra are collected from large Z-axis intervals until a spectrum that meets the database requirements is found. Finally, based on a comprehensive evaluation of the intensity information of single or multiple characteristic peaks, the optimal spectral focus position is accurately determined. After obtaining the optimal spectral focus position, the system automatically modifies the acquisition parameters and systematically collects spectral data based on the actual spectral acquisition parameters to ensure the comprehensiveness and accuracy of the data.
[0035] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] The accompanying drawings, as part of this disclosure, are intended to provide a further understanding of the disclosure. The exemplary embodiments of the disclosure and their descriptions are intended to explain the disclosure and do not constitute undue limitations thereon. Obviously, the drawings described below are merely examples, and those skilled in the art can derive other drawings based on these drawings without inventive effort.
[0037] In the attached figure:
[0038] Figure 1 is a flow chart of the automatic focusing method based on the combination of image and spectrum in the present invention;
[0039] Figure 2 is the spectrum collection area in the image of the present invention;
[0040] Figure 3 is a spectrum acquisition region segmentation diagram in the image of the present invention;
[0041] Figure 4 is an image intensity value map of each segmented area in the present invention;
[0042] Figure 5 is an image intensity value sorting image of the segmented region in the present invention;
[0043] Figure 6 This is a comparison chart of the spectral intensity of the two methods: image focusing and automatic focusing combined with image and spectrum.
[0044] It should be noted that these drawings and textual descriptions are not intended to limit the conceptual scope of the present invention in any way, but rather to illustrate the concept of the present invention for those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0045] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. The following embodiments are used to illustrate the present invention but are not used to limit the scope of the present invention.
[0046] In the description of the present invention, it should be noted that the terms "upper", "lower", "front", "back", "left", "right", "vertical", "inside", "outside", etc., indicating directions or positional relationships, are based on the directions or positional relationships shown in the accompanying drawings. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific direction, be constructed and operated in a specific direction. Therefore, they cannot be understood as limiting the present invention.
[0047] In the description of the present invention, it should be noted that, unless otherwise expressly specified or limited, the terms "mounted," "connected," and "connected" should be understood broadly. For example, they may refer to fixed, detachable, or integral connections; mechanical or electrical connections; and direct or indirect connections through an intermediary. Those skilled in the art will understand the specific meanings of the above terms in the present invention based on the specific circumstances.
[0048] As attached Figure 1-5 As shown, an automatic focusing method based on the combination of image and spectrum includes obtaining the best clarity image and its coordinate position in the preset direction according to the different clarity of the sample plane in the preset direction, and determining the spectrum collection area in the image accordingly; dividing the spectrum collection area into multiple sub-areas to obtain several segmentation area maps, and obtaining the target segmentation area map and the plane coordinate range of the area according to the average image intensity of the segmentation area map; performing short-time spectrum collection according to the coordinate information of the target segmentation area map, and obtaining the best focusing position for sample spectrum collection based on the spectral characteristic peak intensity and the data model.
[0049] The aforementioned image- and spectral-based automated focusing method utilizes imaging for coarse focusing and spectral methods for fine focusing, thereby determining the optimal focus position for the sample and improving the efficiency and accuracy of spectral data acquisition. Furthermore, through clarity evaluation and spectral characteristic peak intensity analysis, the optimal focus position can be quickly and accurately determined, further improving the efficiency and accuracy of spectral acquisition.
[0050] As a further embodiment of the present application, during the automatic focusing process, an image with optimal clarity and its coordinate position in a preset direction are acquired based on the varying clarity of the sample plane in a preset direction. The preset direction is the Z direction relative to the sample plane, and the plane coordinate range of the target segmentation region map includes the coordinate range in the XY axis directions. By limiting the coordinate ranges in the Z and XY directions, the positioning accuracy of the spectral acquisition area is optimized, improving the practicality of the focusing method.
[0051] Furthermore, obtaining the best definition image and its coordinate position in the preset direction includes:
[0052] The spectrum acquisition system performs image autofocus to obtain sample plane images in several Z directions;
[0053] The Tenengrad evaluation function is used to quantitatively evaluate the clarity of the sample plane image and calculate the average grayscale value of each image;
[0054] Select the best clear image with the largest average gray value and determine its Z direction position.
[0055] As you can understand, the Tenengrad function is a commonly used function for evaluating image clarity, based on gradients. In image processing, well-focused images generally have sharper edges and, therefore, larger gradient function values. The Tenengrad function uses the Sobel operator to extract horizontal and vertical gradient values, effectively quantifying image clarity and improving focus accuracy. Furthermore, through automatic focus and clarity evaluation, the impact of manual focus intervention can be reduced, improving operational efficiency.
[0056] As a further embodiment of the present application, a method for calculating the average grayscale value of each image (Tenengrad evaluation function) includes the following steps:
[0057] S1. Calculate the Sobel operator convolution kernel Gx and Gy from the operator matrix:
[0058] Gx=g(x-1,y+1)+2g(x,y+1)+g(x+1,y+1)-g(x-1,y-1)-2g(x,y-1)-g(x+1,y-1)
[0059] Gy=g(x+1,y-1)+2g(x+1,y)+g(x+1,y+1)-g(x-1,y-1)-g(x-1,y)-g(x-1,y+1);
[0060] The corresponding operator matrix is:
[0061] In the Gx and Gy calculation equations above, x and y are the coordinate values of the image pixel, and g(x,y) represents the grayscale value of the pixel at the coordinate (x,y). The calculated Gx and Gy are the horizontal and vertical gradient values of that point.
[0062] S2. Based on the Sobel convolution kernels Gx and Gy obtained in step S1, the gradient of image I at point (x, y) is obtained:
[0063] S3. Based on the S(x,y) value obtained in step S2, the Tenengrad value of the image is calculated as:
[0064] Where n is the total number of pixels in the image.
[0065] It should be noted that the Tenengrad gradient method uses the Sobel operator to calculate horizontal and vertical gradients. For the same scene, higher gradient values indicate clearer images. The metric used for measurement is the average grayscale value (Tenengrad value) of the image after Sobel processing. A higher average grayscale value indicates clearer images. Based on this average grayscale value, the system analyzes image clarity and identifies the Z-position of the image with optimal clarity. This Z-position serves as the coordinate basis for subsequent spectral focusing.
[0066] As a further embodiment of the present application, determining the spectrum collection area in the image includes:
[0067] The best clear image obtained is compared with the image data model that has been trained in the spectrum acquisition system, and the spectrum acquisition area is obtained according to the image features.
[0068] As a further embodiment of the present application, obtaining the target segmentation region map and the plane coordinate range of the region where it is located includes:
[0069] As attached Figure 3 As shown, the spectrum acquisition area is divided into x rectangular sub-areas of N*N pixels, and several segmentation area maps are obtained, where x ≥ 9 and N ≥ 5;
[0070] As attached Figure 4 As shown, the average image intensity of each segmented region map is calculated to obtain the image intensity value of each segmented region map;
[0071] As attached Figure 5 As shown, the image intensity values are sorted in order of size, and the segmentation region maps corresponding to the first 10% of the image intensity values with smaller values are discarded; the image with the smallest image intensity value in the remaining segmentation region maps is output as the target segmentation region map, and the plane coordinate range of the area where the target segmentation region map is located is output.
[0072] For example, as shown in the attached Figure 5 As shown, the image intensity values are sorted in order of size, and the modules "71", "65", "72", "70", "58", and "69" with smaller image intensity values in the segmentation region map are discarded, and the modules "66", "68", "67", ... "8", "6", "9", and "10" with larger image intensity values remain. Among the modules with larger image intensity values, the module with the smallest image intensity value "66" is taken as the target segmentation region map, and the plane coordinate range of the area where the target segmentation region map "66" is located is output.
[0073] It should be noted that after determining the spectral acquisition area in the image, regional segmentation is performed on the spectral acquisition area to clearly distinguish different areas in the image, facilitating further evaluation of the image intensity performance of each area. In a grayscale image, the image intensity value is the image grayscale value, so the average image intensity value of each segmented area is calculated and sorted in sequence according to the intensity value. In this group of sorted image areas, the top 10% of the areas are discarded to avoid errors introduced by special noise in the image. The XY coordinate range with the largest grayscale value in the remaining area is output, and this range will be established as the XY area for spectral fixed-focus acquisition. By dividing the area and screening the intensity, low-intensity areas are discarded, the system data processing volume is reduced, and image analysis is focused on high-intensity areas, thereby improving the pertinence and accuracy of spectral acquisition.
[0074] As a further embodiment of the present application, the determination of the spectral acquisition area also includes: after obtaining the Z-direction coordinates obtained by focusing the image, the sample platform is moved in a small range in the Z direction, multiple spectra are collected within a preset time range, and spectral characteristic peak analysis is performed to obtain the position with the highest spectral intensity as the optimal spectral focusing position.
[0075] During the process of determining the actual spectral acquisition area, the spectral intensity is normalized into a spectrum graph, which is then used to train the spectral classification model. Full-spectral feature comparison is used to confirm whether the acquisition area is the actual sample area to avoid interference from transparent, layered samples. If the spectrum differs significantly from the spectrum in the data model, a large Z-axis interval area is acquired until a Raman spectrum that meets the database requirements is found. Finally, based on a comprehensive evaluation of the intensity information of a single or multiple characteristic peaks, the optimal spectral focusing position is accurately determined. After obtaining the optimal spectral focusing position, the system automatically modifies the acquisition parameters and systematically collects spectral data based on the actual spectral acquisition parameters to ensure the comprehensiveness and accuracy of the data.
[0076] Furthermore, the preset time for spectrum acquisition is 0.01-0.15s. Those skilled in the art can determine the spectrum acquisition time based on the actual situation of spectrum data acquisition. By moving the spectrum in a small range and acquiring multiple times within a certain period of time, the optimal spectrum focus position can be more accurately located, thereby improving the quality of the spectrum data.
[0077] As a further embodiment of the present application, the automatic focusing method based on the combination of image and spectrum also includes: according to the optimal spectral focusing position of the sample, the spectral acquisition system systematically collects spectral data according to actual spectral acquisition parameters.
[0078] After obtaining the optimal spectral focus position, the system systematically collects accurate spectral data based on the actual spectral acquisition parameters. During this process, external interference, background noise, and other factors can affect the quality of the spectral data, so appropriate strategies are required to ensure data validity. Each acquired data set is stored and subsequently analyzed. The data model utilizes machine learning algorithms to identify and classify characteristic peaks, further enhancing the accuracy of data analysis. Based on the acquired spectral data, the spectral data model and characteristic peak intensity analysis allow for precise assessment of sample characteristics, enabling better subsequent analysis and application.
[0079] As attached Figure 6 As shown, compared with the image focusing method alone, the sample spectrum intensity obtained by the fixed-focus method based on the combination of image and spectrum in the present application is 2 to 3 times the spectrum intensity obtained by image focusing, which greatly improves the characteristic peak intensity of the spectrum and improves the accuracy of the obtained data.
[0080] The present invention, after adopting the above embodiments, has the following outstanding essential features and beneficial technical effects:
[0081] The automatic focusing method based on the combination of images and spectra proposed in the present invention obtains high-quality spectral data through a series of steps: image automatic focusing, feature area extraction, image area segmentation and image intensity evaluation, Raman spectrum automatic focusing, data analysis and processing, and provides a reliable basis for spectral data analysis. In addition, through a systematic evaluation and acquisition process, it is efficient, precise, and automated, greatly improving the efficiency and accuracy of spectral acquisition.
[0082] Based on the collected spectral data, the spectral intensity is normalized into a spectrum graph, which is then used to train the spectral classification model. By comparing the full spectral features, it is confirmed whether the acquisition area is the actual sample area, thus avoiding interference from transparent layered samples. If the spectrum differs significantly from the spectrum in the data model, Raman spectra are collected from large Z-axis intervals until a spectrum that meets the database requirements is found. Finally, based on a comprehensive evaluation of the intensity information of single or multiple characteristic peaks, the optimal spectral focus position is accurately determined. After obtaining the optimal spectral focus position, the system automatically modifies the acquisition parameters and systematically collects spectral data based on the actual spectral acquisition parameters to ensure the comprehensiveness and accuracy of the data.
[0083] The above description is merely a preferred embodiment of the present invention and does not constitute any form of limitation to the present invention. Although the present invention has been disclosed as above in terms of a preferred embodiment, it is not intended to limit the present invention. Any technician familiar with this patent can make slight changes or modifications to equivalent embodiments of equivalent changes using the above-mentioned technical contents without departing from the scope of the technical solution of the present invention. The implementation schemes in the above-mentioned embodiments can also be further combined or replaced. However, any simple modifications, equivalent changes and modifications made to the above-mentioned embodiments based on the technical essence of the present invention without departing from the content of the technical solution of the present invention are still within the scope of the solution of the present invention.
Claims
1. An automatic focusing method based on the combination of image and spectrum, characterized in that: include: According to the different clarity of the sample plane in the preset direction, the best clarity image and its coordinate position in the preset direction are obtained, and the spectrum collection area in the image is determined accordingly; Dividing the spectrum acquisition area into multiple sub-areas to obtain a plurality of segmentation area maps, and obtaining a target segmentation area map and a plane coordinate range of the area where the target segmentation area map is located according to the average image intensity of the segmentation area map; Short-time spectrum acquisition is performed according to the coordinate information of the target segmentation area map, and the optimal fixed focus position for sample spectrum acquisition is obtained based on the spectral characteristic peak intensity and the data model.
2. The automatic focusing method based on image and spectrum combination according to claim 1, characterized in that: The preset direction is the Z direction relative to the sample plane, and the plane coordinate range of the target segmentation region map includes the coordinate range of the XY axis.
3. The automatic focusing method based on image and spectrum combination according to claim 2, characterized in that: The acquisition of the best definition image and its coordinate position in the preset direction includes: The spectrum acquisition system performs image autofocus to obtain sample plane images in several Z directions; Performing a quantitative valuation process on the sample plane image for clarity using the Tenengrad evaluation function, and calculating the average grayscale value of each image; Select the best clear image with the largest average gray value and determine its Z direction position.
4. The automatic focusing method based on image and spectrum combination according to claim 3, characterized in that: The method for calculating the average grayscale value of each image includes: S1. Calculate the Sobel operator convolution kernel G from the operator matrix x , G y for: G x =g(x-1,y+1)+2g(x,y+1)+g(x+1,y+1)-g(x-1,y-1)-2g(x,y-1)-g(x+1,y-1) G y =g(x+1,y-1)+2g(x+1,y)+g(x+1,y+1)-g(x-1,y-1)-g(x-1,y)-g(x-1,y+1); The corresponding operator matrix is: S2, Sobel convolution kernel G obtained in step S1 x , G y , get the gradient of image I at point (x, y): S3. Based on the S(x,y) value obtained in step S2, the Tenengrad value of the image is calculated as: Where n is the total number of pixels in the image.
5. The automatic focusing method based on image and spectrum combination according to claim 3, characterized in that: Determining the spectrum acquisition area in the image includes: The best clear image obtained is compared with the image data model that has been trained in the spectrum acquisition system, and the spectrum acquisition area is obtained according to the image features.
6. The automatic focusing method based on image and spectrum combination according to any one of claims 1 to 5, characterized in that: Obtaining the target segmentation region map and the plane coordinate range of the region where it is located includes: Divide the spectrum acquisition area into x rectangular sub-areas of N*N pixels, and obtain several segmentation area maps, where x ≥ 9 and N ≥ 5; Calculate the average image intensity of each segmented region map and obtain the image intensity value of each segmented region map; Sort the image intensity values in order of size, and discard the segmentation region maps corresponding to the first 10% of the image intensity values with the smallest values; The image with the smallest image intensity value among the remaining segmented region maps is output as the target segmented region map, and the plane coordinate range of the region where the target segmented region map is located is output.
7. The automatic focusing method based on image and spectrum combination according to claim 6, characterized in that: Determination of the spectral acquisition area also includes: after obtaining the Z-direction coordinates obtained by focusing the image, the sample platform is moved in a small range in the Z-direction, multiple spectral acquisitions are performed within a preset time range, spectral characteristic peak analysis is performed, and the position with the highest spectral intensity is obtained as the optimal spectral focusing position.
8. The automatic focusing method based on image and spectrum combination according to claim 7, characterized in that: The preset time for spectrum acquisition is 0.01-0.15s.
9. The automatic focusing method based on image and spectrum combination according to claim 1, characterized in that: Also includes: According to the optimal spectral focusing position of the sample, the spectral acquisition system systematically collects spectral data based on the actual spectral acquisition parameters.