An image processing method
By employing a row straightening algorithm with least squares fitting and smoothing constraints, combined with a multi-threaded architecture and brightness adjustment, the background drift and tilt problems in high-speed scanning imaging of atomic force microscopy are solved, achieving high-precision image correction and data standardization, suitable for scanning complex and large-area samples.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SONGSHAN LAKE MATERIALS LAB
- Filing Date
- 2026-03-30
- Publication Date
- 2026-06-30
AI Technical Summary
During high-speed scanning imaging, atomic force microscopy is affected by factors such as piezoelectric ceramic hysteresis, thermal drift, and mechanical vibration, resulting in row-level background drift, stripe artifacts, and structural misalignment in the scanned data. Existing methods are difficult to accurately eliminate these issues, affecting the fidelity of image details and the reliability of analysis.
A line straightening algorithm combining least squares fitting and smoothing constraints is used to eliminate background drift, and the overall tilt is corrected by least squares plane fitting. A multi-threaded architecture is used to achieve real-time display and brightness adjustment, and standardized data export is supported.
It effectively eliminates row-level background drift and overall tilt, improves image detail consistency and readability, ensures smooth display and data compatibility under high-speed scanning, and is suitable for complex samples and large-area scanning.
Smart Images

Figure CN122312441A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of atomic force microscopy data processing technology, and more specifically, to an image processing method. Background Technology
[0002] During high-speed scanning imaging, atomic force microscopy (AFM) is subject to interference from various factors, including piezoelectric ceramic hysteresis, thermal drift, mechanical vibration, and sample tilt, leading to a variety of image quality problems in the scanned data. Among these, row-level background drift manifests as baseline shift in each row of scanned data, causing noticeable stripe artifacts and structural misalignments in the image. Existing row correction methods often employ simple first-order linear fitting, which struggles to accurately eliminate drift in complex curve morphologies and tends to excessively reduce the true micro- and nano-texture of the sample, affecting the fidelity of image details and the reliability of analysis. Summary of the Invention
[0003] In view of this, the purpose of this application is to provide an image processing method that aims to overcome at least one of the above-mentioned defects.
[0004] In a first aspect, this application provides an image processing method, comprising: The original height data is loaded in the user interface. The original height data is obtained by scanning the sample surface line by line with the probe of the atomic force microscope. The position of the probe in the vertical direction is changed in real time according to the undulation of the sample surface, and the vertical position is recorded as the height value of the corresponding scanning point. Receive the operation performed on the user interface to initiate line straightening correction; In response to the operation, the following processing is performed for each row of data in the original height data: the row of data is fitted using the least squares method to obtain an original fitted baseline that characterizes the background drift trend of the row of data; a smoothing constraint is applied to the original fitted baseline to obtain a smoothed fitted baseline; and the smoothed fitted baseline is subtracted from the row of data to obtain the corrected height data. Based on the correction height data corresponding to each row, a row straightening correction image is obtained and displayed in the user interface.
[0005] In one possible implementation, it also includes: Receive the operation performed on the user interface for initiating surface straightening correction; In response to the operation, a plane fitting is performed on the two-dimensional height matrix corresponding to the original height data to obtain a fitting plane that characterizes the overall tilt trend of the original height data; The fitted plane is subtracted from the two-dimensional height matrix to obtain a surface straightening correction image, which is then displayed in the user interface.
[0006] In one possible implementation, it also includes: The user interface provides a height range setting area, which includes a minimum value input box and a maximum value input box. Receive the minimum height value set by the user in the minimum value input box, and the maximum height value set by the user in the maximum value input box; In response to the setting, a linear transformation is performed on the height value of each pixel in the currently displayed image to map the height value to a preset grayscale range, and the mapping result is truncated according to the minimum height value and the maximum height value to obtain a brightness adjustment image, which is then displayed in the user interface.
[0007] In one possible implementation, it also includes: The user interface displays a scan parameter setting area, which includes multiple input boxes. It receives scan parameters entered by the user in the multiple input boxes and receives operations performed on the user interface to start a scan; In response to the operation, the acquisition thread, parsing thread, and rendering thread are started according to the scanning parameters input by the user; The acquisition thread receives raw height data in real time and writes the raw height data into a circular buffer. The parsing thread reads data from the circular buffer and performs correction processing. The rendering thread refreshes and displays the corrected image in real time in the image display area of the user interface.
[0008] In one possible implementation, it also includes: When the acquisition thread writes data to the circular buffer, a mutex lock is used to lock the write operation to prevent the parsing thread from reading data from the same location simultaneously. When the parsing thread reads data from the circular buffer, a mutex lock is used to lock the read operation to prevent the acquisition thread from writing data to the same location simultaneously.
[0009] In one possible implementation, it also includes: After the parsing thread completes image processing, it updates the image buffer pointer through atomic variables, so that the rendering thread updates the displayed image in the image display area according to the image buffer pointer.
[0010] In one possible implementation, it also includes: Receive operations performed on the user interface for saving data; In response to the operation, the height matrix corresponding to the target data is encapsulated into a standardized SPM file and exported for storage.
[0011] In one possible implementation, the height matrix corresponding to the currently displayed image is encapsulated into a standardized SPM file and exported for storage in the following manner: Get the preset SPM file template; A file header is constructed based on the meta-information of the height matrix, and the file header is written into the SPM file template to obtain the exported file; The height matrix is written line by line in binary format to the exported file, and each line of data is byte-aligned to obtain the standardized SPM file, which is then exported and stored.
[0012] In one possible implementation, the file header includes resolution, scan size, scan mode, number of channels, data offset, byte order, and calibration parameters.
[0013] Secondly, this application provides an image processing method, including: The raw height data is obtained by scanning the sample surface line by line with the probe of an atomic force microscope, changing the position of the probe in the vertical direction in real time according to the undulation of the sample surface, and recording the vertical position as the height value of the corresponding scanning point. For each row of data in the original height data, the following processing is performed: the row of data is fitted using the least squares method to obtain an original fitted baseline that characterizes the background drift trend of the row of data; a smoothing constraint is applied to the original fitted baseline to obtain a smoothed fitted baseline; and the smoothed fitted baseline is subtracted from the row of data to obtain the corrected height data. Based on the correction height data corresponding to each row, a row straightening correction image is obtained.
[0014] This application provides an image processing method, comprising: loading raw height data into a user interface; receiving an operation performed on the user interface to initiate row straightening correction; in response to the operation, performing the following processing for each row of data in the raw height data: performing a fitting calculation on the row of data according to the least squares method to obtain an original fitting baseline characterizing the background drift trend of the row of data; applying a smoothing constraint to the original fitting baseline to obtain a smoothed fitting baseline; subtracting the smoothed fitting baseline from the row of data to obtain corrected height data; obtaining a row straightening correction image based on the corrected height data corresponding to each row of data; and displaying the row straightening correction image in the user interface. This application achieves effective elimination of row-level background drift caused by piezoelectric hysteresis, feedback delay, and thermal drift in the raw height data of an atomic force microscope.
[0015] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 A flowchart illustrating an image processing method provided in an embodiment of this application; Figure 2 This is a schematic diagram of the user interface provided in an embodiment of this application; Figure 3 This is a system hardware architecture diagram provided in the embodiments of this application; Figure 4 A flowchart illustrating the surface straightening correction provided in this application embodiment; Figure 5 A flowchart illustrating brightness adjustment provided in an embodiment of this application; Figure 6 A flowchart illustrating multithreaded processing provided in an embodiment of this application; Figure 7 A flowchart illustrating the export of SPM files provided in this application embodiment; Figure 8(a) is a schematic diagram of the original image provided in the embodiment of this application; Figure 8(b) is a schematic diagram of the straightened image provided in the embodiment of this application; Figure 8(c) is a schematic diagram of a straightened surface image provided in an embodiment of this application; Figure 8(d) is a schematic diagram of the brightness dimming image provided in the embodiment of this application; Figure 8(e) is a schematic diagram of a brightness-enhanced image provided in an embodiment of this application; Figure 9 A three-dimensional topological image of the SPM file exported from the sample surface provided in the embodiments of this application; Figure 10 Typical height cross-section curves extracted from three-dimensional topography images are provided for embodiments of this application; Figure 11 A flowchart illustrating another image processing method provided in an embodiment of this application. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. Based on the embodiments of this application, every other embodiment obtained by those skilled in the art without inventive effort falls within the scope of protection of this application.
[0019] First, the applicable scenarios for this application will be introduced. This application can be applied to the field of atomic force microscopy data processing technology.
[0020] Research has shown that atomic force microscopy (AFM), as an important instrument for nanoscale characterization, is widely used in materials science, bioengineering, semiconductor manufacturing, and micro / nanostructure analysis. With the continuous advancement of high-speed scanning technology, the line frequency of AFM has gradually increased, resulting in an exponential increase in the amount of raw data acquired per unit time. High-speed scanning significantly improves imaging efficiency, but it also places higher demands on data processing, image correction, and display refresh capabilities. Traditional AFM software typically employs basic line correction and simple image straightening algorithms, combined with automatic brightness mapping for image display; its data processing mode is mostly single-threaded, and there is a lack of unified data format standards across different devices.
[0021] Under high-speed scanning conditions, existing technologies reveal significant shortcomings. First, influenced by factors such as piezoelectric ceramic hysteresis, probe stress fluctuations, thermal drift, and mechanical vibration, baseline drift of varying degrees often occurs between scanning lines, resulting in striped artifacts, local brightness abrupt changes, and even structural misalignment in the image. Traditional first-order correction is insufficient to effectively eliminate dynamic drift. Second, due to sample micro-tilt, stage unevenness, and scanner geometric errors, the overall image exhibits linear or planar tilt. Existing software's simple planar subtraction methods often fall short of correction and cannot handle complex deformations or large-area scanning. Third, affected by sample roughness differences and noise, traditional automatic contrast mapping is easily affected by extreme points in high-speed mode, leading to brightness jumps, and lacks stable and flexible manual height adjustment functionality. Furthermore, the data throughput of high-speed scanning far exceeds the processing capacity of single-threaded architectures, resulting in display delays, interface lag, and even data loss. Finally, various AFM devices use different data file structures, and custom formats are incompatible with mainstream analysis software, severely impacting data sharing, long-term storage, and research reproducibility.
[0022] In summary, existing high-speed AFM imaging technologies have significant shortcomings in core aspects such as line straightening, area straightening, brightness range adjustment, real-time multi-threaded processing, and standardized data export. They cannot simultaneously guarantee image fidelity, display smoothness, and data reproducibility under high-speed scanning conditions. The root cause lies in the lack of targeted correction capabilities for dynamic drift, the lack of a stable and flexible brightness adjustment mechanism, the lack of a parallel architecture capable of handling large-scale data, and the absence of a unified data export format compatible with international software. Therefore, there is an urgent need for a novel AFM data processing method that can effectively address these issues in high-speed scanning environments while ensuring image quality and data compatibility.
[0023] Based on this, embodiments of this application provide an image method aimed at overcoming at least one of the above-mentioned defects.
[0024] Please see Figure 1 and Figure 2 , Figure 1 This is a flowchart of an image processing method provided in an embodiment of this application. Figure 2 A schematic diagram of the user interface provided by an exemplary embodiment of this application is shown.
[0025] like Figure 2 As shown, the user interface includes a menu bar (File, View, Edit, Configuration), a scan parameter setting area (including input boxes for fast scan size, slow scan size, scan rate, and scan type selection), an image display area (for displaying height images, error images, phase images, etc.), a processing button area (including buttons for "Original Image," "Line Straightening (Row Straightening)," "Surface Straightening," "Adjust Data," and "Go"), and a brightness adjustment area (including input boxes for minimum and maximum values).
[0026] like Figure 1 As shown in the embodiments of this application, the image processing method includes: Step S101: Load the raw height data in the user interface.
[0027] Here, the raw height data is first loaded into the user interface. The raw height data is obtained by scanning the sample surface line by line with the probe of the atomic force microscope, changing the position of the probe in the vertical direction in real time according to the undulations of the sample surface, and recording the vertical position as the height value of the corresponding scan point.
[0028] Please see Figure 3 , Figure 3 This is a system hardware architecture diagram provided for an embodiment of this application.
[0029] The system architecture includes an FPGA, a position / displacement detection module (PSPD and LVDT), an execution and scanning control module, and a host computer software module. The position / displacement detection module acquires detection signals related to the scanning process and inputs them to the FPGA. The FPGA synchronously acquires and times-controls the detection signals, and drives the piezoelectric ceramic actuators to achieve X / Y / Z-axis scanning control of the nanostage, laser control, and tapping mode probe excitation axis control. Simultaneously, it uses an integrated motor to achieve coarse adjustment control of the Z-axis of the microstage. The host computer software adopts an MVVM architecture, interacts with the FPGA, and receives auxiliary imaging information from the CCD camera. The host computer software controls the movement of the camera's three axes and the microstage's X / Y axes via the integrated motor to complete alignment and positioning.
[0030] Specifically, this application collects raw height data through the above system architecture. After collecting the raw height data, the host computer software can obtain the raw height data from the hardware device.
[0031] Step S102: Receive the operation performed on the user interface to initiate line straightening correction.
[0032] In this embodiment, a "Line Straighten" button is provided in the user interface. When the user clicks this button, the software receives the operation instruction and triggers the line straightening correction function.
[0033] Step S103: In response to the operation, perform row straightening for each row of data in the original height data.
[0034] In this embodiment of the application, in response to the user clicking the "Straighten Lines (Straighten Rows)" button, the software performs row straightening processing on each row of data in the original height data.
[0035] The line straightening process includes: constructing a first-order or multi-order fitted baseline for each scan line based on the least squares method, and subtracting the baseline from the original height data to eliminate line-level background drift caused by piezoelectric hysteresis, feedback delay and thermal drift.
[0036] Specifically, for each line of scanned data, the type of drift is first determined. This application employs an order selection strategy: first-order linear fitting is prioritized. When the fitting residual exceeds a preset threshold (indicating nonlinear drift), a manual switch to second- or third-order polynomial fitting can be selected to adapt to curved scan lines or complex background trends. In this way, various forms of background drift can be accommodated, whether it be weak curve drift or curved scan lines.
[0037] Then, the least squares method was used to fit the data for this row. The original height data consists of the superposition of the sample's true morphology and the background drift. The true morphology reflects the micro-nano scale undulations of the sample surface and is a high-frequency signal, while the background drift is introduced by factors such as piezoelectric ceramic hysteresis and thermal drift and is a low-frequency signal. The least squares method is a mathematical optimization technique that finds the best function match for the data by minimizing the sum of squared errors. The fitted baseline reflects the overall background drift trend of the data for this row.
[0038] To prevent the original fitted baseline from excessively following the actual micro / nano texture of the sample, this embodiment applies a smoothing constraint to the fitted baseline. A smoothing constraint means limiting the curvature change of the baseline during fitting (i.e., forcing baseline smoothing), prohibiting drastic baseline fluctuations from following high-frequency signals that represent the true shape of the sample. Without this constraint, the algorithm might mistakenly identify tiny bumps and depressions (micro / nano textures) on the sample surface as "drift" and remove them, causing the sample to lose its original details. With the smoothing constraint applied, the baseline is forced to represent only slowly changing background trends (drift) and cannot fit rapidly changing real textures, thus avoiding excessive reduction of the original height profile and ensuring that the corrected scan lines retain the true micro / nano texture features.
[0039] Finally, the smoothed baseline is subtracted from the data in this row to obtain the corrected height data. "Subtraction" means performing subtraction pixel by pixel: for each pixel in this row, the corresponding value of the smoothed baseline at that point is subtracted from the original height value. Through this subtraction operation, background drift is eliminated, and what remains is the true shape of the sample.
[0040] Step S104: Obtain the row straightening correction image based on the correction height data corresponding to each row data, and display the row straightening correction image in the user interface.
[0041] In this embodiment, the corrected height data of all rows are recombined in the original scanning order to form a two-dimensional height matrix, which is the row straightening correction image. The software displays this image in the image display area of the user interface, allowing the user to directly observe the correction effect.
[0042] Please see Figure 4 , Figure 4 This is a flowchart illustrating the surface straightening correction provided in an embodiment of this application. Figure 4 As shown, it includes: Step S201: Receive the operation performed on the user interface for initiating surface straightening correction.
[0043] In this embodiment, a "Face Straightening" button is provided in the user interface. When the user clicks this button, the software receives the operation command and triggers the face straightening correction function.
[0044] It should be noted that face straightening correction and row straightening correction are optional operations. Users can perform row straightening, face straightening, or both separately, and they can be performed in any order without depending on each other.
[0045] Step S202: In response to the operation, perform plane fitting on the two-dimensional height matrix corresponding to the original height data to obtain a fitting plane that characterizes the overall tilt trend of the original height data.
[0046] In this embodiment of the application, in response to the user clicking the "Straighten Face" button, the software performs plane fitting on the two-dimensional height matrix corresponding to the original height data (or the data after straightening correction, depending on the user's selection) to obtain a fitting plane that represents the overall tilt trend.
[0047] Specifically, a least-squares plane fitting algorithm is employed, which improves the robustness of the overall tilt model by solving for all valid points in the entire height matrix. The plane fitting model is Z(x,y)=Ax+By+C, where A and B represent the tilt slopes of the image in the X and Y directions, respectively, and C represents the height of the plane at the origin. The parameters A, B, and C are solved using the least-squares method to minimize the sum of squared errors between the fitted plane and all data points.
[0048] Step S203: Subtract the fitted plane from the two-dimensional height matrix to obtain the surface straightening correction image, and display the surface straightening correction image in the user interface.
[0049] In this embodiment, for each pixel in the two-dimensional height matrix, its original height value is calculated by subtracting the height value of the fitted plane at that point, resulting in the corrected height value. In this way, the overall tilt of the entire image is eliminated, and the height reference of all pixels is unified to the same horizontal plane.
[0050] The image after surface straightening and correction is displayed in the image display area of the user interface. Users can switch between the original image, the straightened line image, and the straightened surface image for comparison, intuitively experiencing the effects of each processing step.
[0051] Please see Figure 5 , Figure 5 A flowchart illustrating brightness adjustment provided in an embodiment of this application. Figure 5 As shown, it includes: Step S301: Provide a height range setting area in the user interface, which includes a minimum value input box and a maximum value input box.
[0052] In this embodiment of the application, the user interface includes a height range setting area, which comprises a minimum value input box and a maximum value input box. For example... Figure 1 As shown, the brightness adjustment area is marked with minimum and maximum value input boxes, where users can enter values.
[0053] Step S302: Receive the minimum height set by the user in the minimum value input box and the maximum height set by the user in the maximum value input box.
[0054] In this embodiment, the software receives the set value after the user enters and confirms the value in the minimum and maximum value input boxes. For example, the user can set the minimum height to 0nm and the maximum height to 100nm, indicating that the user is interested in the morphological details within the height range of 0 to 100nm.
[0055] Step S303: In response to the setting, perform a linear transformation on the height value of each pixel in the currently displayed image, map the height value to a preset grayscale range, and truncate the mapping result according to the minimum and maximum height values to obtain a brightness adjustment image, and display the brightness adjustment image in the user interface.
[0056] In this embodiment, the preset grayscale range can be 0 to 255, and the brightness mapping adopts a linear transformation formula:
[0057] in, This is the height value of the current pixel. The minimum height set by the user. The maximum height set by the user. After transformation, the height value equals... The pixel is mapped to grayscale 0 (black), and the height value is equal to The pixel is mapped to grayscale 255 (white), and the middle height value is linearly mapped to the middle grayscale.
[0058] For height values exceeding the set range, truncation is performed: below... The pixel is mapped to grayscale 0, higher than 0. The pixel mapping is set to grayscale 255 to avoid outliers causing brightness overflow.
[0059] In a preferred embodiment, the data range mapping supports a reverse mode. When the user selects the reverse mode, execution is performed. This allows for greater visual gradation of height variations, microsteps, and uneven textures. This is because the human eye can distinguish more subtle differences in brightness in darker areas; after reversal, raised steps become darker and recessed scratches become lighter, making them easier for the naked eye to recognize.
[0060] Please see Figure 6 , Figure 6 A flowchart illustrating multithreaded processing provided in an embodiment of this application. Figure 6 As shown, it includes: Step S401: Display the scan parameter setting area in the user interface.
[0061] In this embodiment, the user interface includes a scanning parameter setting area, which contains multiple input boxes. For example... Figure 1 As shown, the scanning parameter setting area includes input boxes for fast scan size (in μm), slow scan size (in nm), scan rate (in Hz), scan type selection (Fast / Slow), probe speed (μm / s), and sample row number, etc. Users can set scanning parameters in this area.
[0062] Step S402: Receive scan parameters entered by the user in multiple input boxes, and receive the operation performed on the user interface to start the scan.
[0063] In this embodiment, after the user inputs the scanning parameters, they click the start button in the user interface. The software receives the operation instruction and triggers the scan to start.
[0064] Step S403: In response to the operation, start the built acquisition thread, parsing thread and rendering thread.
[0065] The acquisition thread receives raw height data in real time based on the scanning parameters input by the user and writes the raw height data into a circular buffer.
[0066] In this embodiment, the multi-threaded framework is built upon software startup. When the user clicks the start button, the three threads begin running. The acquisition thread is responsible for communicating with the hardware, receiving raw height data uploaded by the FPGA in real time according to the user-set scanning parameters (such as scanning rate and scanning range), and writing the data into a circular buffer.
[0067] A circular buffer is a data transfer mechanism used between the acquisition and parsing threads. It is a fixed-size circular queue that implements a producer-consumer pattern by separating read and write pointers. The circular buffer enables lock-free reading and writing in memory, allowing for efficient transmission of high-speed data streams and improving data throughput between threads.
[0068] Step S404: Read data from the circular buffer through the parsing thread and perform line straightening correction, surface straightening correction and brightness mapping processing.
[0069] In this embodiment, the parsing thread reads the data to be processed from the circular buffer and performs one of the user-selected line straightening correction, surface straightening correction, and brightness mapping processing. To improve processing efficiency, the parsing thread adopts a batch processing strategy, processing multiple lines of data at once and performing straightening and mapping simultaneously to reduce thread switching overhead and improve CPU utilization.
[0070] Step S405: The processed image is refreshed and displayed in real time in the image display area of the user interface through the rendering thread.
[0071] In this embodiment, the UI rendering thread updates the display area using an image buffer pointer and an asynchronous refresh mechanism. After completing image processing, the parsing thread stores the processing result in shared memory and updates the image buffer pointer.
[0072] In this embodiment of the application, when the acquisition thread writes data to the circular buffer, the write operation is synchronized by a mutex lock or a semaphore to prevent the parsing thread from reading data at the same location at the same time.
[0073] Here, although the circular buffer design separates read and write pointers, synchronization protection is still needed during certain critical operations (such as updating pointers and checking buffer status). Mutexes or semaphores are used to ensure that only one thread operates on the critical resource at a time. Specifically, when the acquisition thread writes data to the circular buffer, a mutex is used to lock the write operation to prevent parsing threads from reading data from the same location simultaneously; or a semaphore is used to control the write operation, causing the acquisition thread to wait when the buffer is full.
[0074] When the parsing thread reads data from the circular buffer, the read operation is synchronized by a mutex or semaphore to prevent the acquisition thread from writing data to the same location at the same time.
[0075] Here, the parsing thread also needs synchronization protection when reading data to prevent data corruption caused by simultaneous writing from the acquisition thread. This is achieved by using mutexes or semaphores to synchronize read operations, causing the parsing thread to wait when the buffer is empty.
[0076] After the parsing thread completes image processing, it updates the image buffer pointer through atomic variables, causing the rendering thread to update the displayed image within the image display area based on the image buffer pointer.
[0077] Here, the UI rendering thread updates the display area using an image buffer pointer and an asynchronous refresh mechanism. Specifically, after the parsing thread completes image processing, it stores the processed image data in shared memory and updates the image buffer pointer using atomic variables. This pointer points to the storage location of the latest image data in shared memory. The UI rendering thread runs independently of the parsing thread, reading the latest image data through the image buffer pointer and drawing it onto the image display area of the user interface. Through the image buffer pointer and asynchronous refresh mechanism, the UI rendering thread can refresh without waiting for the parsing thread to complete its calculations, ensuring smooth visual feedback even when the height changes frequently or the data volume is large.
[0078] During the computation process of the parsing thread, a reentrancy flag is set to prevent the parsing task from being triggered repeatedly before the previous computation is completed, using isReading or an equivalent variable. This avoids data races and processing chaos, ensuring the integrity of the processing task.
[0079] Please see Figure 7 , Figure 7 A flowchart illustrating the export of SPM files provided in this application embodiment. For example... Figure 7 As shown, it includes: Step S501: Receive the operation performed on the user interface for saving data.
[0080] In this embodiment of the application, when the user clicks the "Save" option under the "File" menu or clicks the save button, the software receives the operation instruction and triggers the file export function.
[0081] Step S502: In response to the operation, obtain the preset SPM file template.
[0082] The header of the SPM file template includes resolution, scan size, scan mode, number of channels, data offset, byte order, and calibration parameters.
[0083] In this embodiment, the SPM file template conforms to the data structure specifications of mainstream international AFM software (such as Bruker NanoScope, Gwyddion, WSxM, etc.). The file header contains metadata such as resolution, scan size, scan mode, number of channels, offset, byte order, scale factor, and calibration parameters, enabling external software to accurately reconstruct height information.
[0084] Step S503: Construct a file header based on the meta-information of the height matrix, and write the file header into the exported file.
[0085] In this embodiment, the fields in the file header are filled according to the actual parameters of the current image (such as resolution, scan size, scan mode, etc.), and information such as data area offset and byte order is calculated. After filling, the file header is written to the beginning of the exported file.
[0086] Step S504: Write the height matrix line by line into the SPM file in binary format, and align each line of data by bytes to obtain a standardized SPM file and export and store it.
[0087] In this embodiment, the height matrix data is stored in binary format, arranged as 16-bit or 32-bit floating-point numbers, and supports row alignment and end padding bytes to meet the data parsing specifications of external software. Simultaneously, the SPM file supports multi-channel extended fields, reserving storage space for future superposition of additional physical quantities such as force gradients, phases, amplitudes, and frequency shifts. After writing, the exported file is a standardized SPM file, which can be directly parsed and read by external software such as NanoScope and Gwyddion.
[0088] Please refer to Figure 8, which is a schematic diagram comparing the effects of different processing steps provided in the embodiments of this application. As shown in Figure 8, the embodiments of this application provide a comparison of the effects of atomic force microscope images under different processing steps, including Figure 8(a) the original image, Figure 8(b) the straightened row image, Figure 8(c) the straightened surface image, and Figure 8(d) the image with darkened brightness and Figure 8(e) the image with brightened brightness.
[0089] The original image may contain stripes and a tilted background introduced by scan drift, inter-line baseline changes, or overall planar tilt. Line straightening reduces line drift and stripe artifacts by baseline fitting and subtracting from the scan lines. Planar straightening eliminates global tilt and low-frequency trends by planar fitting and subtracting from the two-dimensional data, resulting in a smoother background. Furthermore, by enhancing or suppressing image brightness, adjustments are made to brighten or darken the image, improving the visibility and contrast of the target structure for real-time observation, subsequent analysis, and export.
[0090] Please see Figure 9 , Figure 9 This is a three-dimensional topological image of the SPM file exported from the sample surface provided in the embodiments of this application. For example... Figure 9As shown, the original scan resolution of the image is 256×256 pixels, corresponding to an actual scan area size of approximately 20μm×20μm, with a height range of approximately 100nm. The 3D topography reveals a regularly arranged square step structure on the sample surface. The top region of each step is relatively flat, while the sidewalls exhibit a distinct vertical steep rise. The bottom planar region is relatively uniform, indicating that the imaging noise is effectively suppressed and surface details are rendered with high fidelity under the forward and reverse reconstruction and smoothing algorithms proposed in this invention.
[0091] Figure 10 This illustration shows a typical height cross-sectional curve extracted from a three-dimensional topographic image, as provided in an exemplary embodiment of this application. (Example:) Figure 10 As shown, the cross-sectional curve passes horizontally through two square steps, clearly revealing a rapid height transition from the substrate to the top of the steps. The sidewalls exhibit a near-vertical height change, with a transition height of approximately 100 nm, consistent with the actual structural parameters of the sample. At the top of the two steps, the cross-sectional curve remains within a height range of approximately 100 nm, exhibiting slight texture fluctuations that reflect the true roughness of the surface microstructure. In the flat region between the steps, the height curve approaches zero nanometers, demonstrating excellent performance in background noise suppression and height baseline stability.
[0092] In summary, this application can achieve nanometer-level high-precision three-dimensional morphology restoration, and can still clearly present 100nm-level height differences at a resolution of 256 pixels and a scanning size of 20μm, proving that the system has good spatial resolution performance and height measurement accuracy.
[0093] Compared with the prior art, this application has the following advantages: 1. Effectively eliminates row-level drift and improves image detail consistency: This application employs a row straightening algorithm based on the least squares method, which can accurately fit and subtract row-by-row background shifts caused by factors such as piezoelectric ceramic hysteresis, feedback delay, thermal drift, and environmental vibration. Compared with traditional simple first-order subtraction methods, the row straightening processing of this application can more accurately identify complex linear trends or weak curve baseline changes, significantly improving the image in terms of inter-row brightness, background flatness, and detail continuity. This processing not only reduces stripe artifacts but also improves the stability of microstructures and fine textures in the image, enabling the lateral consistency of the entire image to reach a high standard of scientific research level.
[0094] 2. Eliminating image tilt for more accurate overall height reference: This application achieves surface straightening correction by performing planar fitting on the two-dimensional height matrix, effectively removing overall height offsets caused by sample stage tilt, incomplete horizontal mounting, or scanner geometric errors. Unlike the simple planar subtraction or averaging reference correction commonly used in existing software, the surface straightening process in this application can automatically adapt to the tilt characteristics of samples of different sizes, strokes, and materials, resulting in a final image with a uniform and highly accurate vertical reference. This step not only ensures the consistency of the image plane but also provides reliable basic data for subsequent height measurement, quantitative analysis of nanosteps, and 3D reconstruction.
[0095] 3. Supports user-controllable brightness range adjustment, enhancing image readability: This application allows users to set minimum and maximum height values according to actual needs, achieving flexible conversion from height data to brightness values through linear mapping. Unlike traditional automatic contrast adjustment methods, which are easily affected by extreme noise, leading to image flickering and brightness jumps, this application uses a manually adjustable brightness window to make image display more stable, while highlighting the texture details of specific micro-areas. Users can perform localized enhanced viewing of features such as roughness, pits, nanosteps, and particle distribution of different samples, thereby achieving more targeted microstructure analysis and significantly improving the readability and professional analytical value of AFM images.
[0096] 4. Real-time display under high-speed scanning using a multi-threaded architecture: To adapt to large-scale data streams under high-speed line frequency conditions, this application constructs a three-thread parallel architecture where acquisition, parsing, and UI rendering are independent. The acquisition thread ensures continuous data acquisition, the parsing thread is responsible for computationally intensive image correction and mapping operations, and the UI thread independently performs image refresh and rendering, thereby avoiding interface lag caused by processing blockage. This parallel structure enables the system to complete data reception, image calculation, and real-time display within a millisecond-level time window, maintaining smooth operation even in kHz-level high-speed scanning mode, significantly improving the user's real-time observation experience.
[0097] 5. Significantly Reduced Latency and Prevention of Data Backlog or Loss: This application utilizes thread decoupling, mutex lock synchronization, data queue buffering, and anti-reentrancy mechanisms to ensure efficient, stable, and continuous data flow throughout the entire processing chain. The complete separation of the parsing thread and the UI rendering thread prevents computationally intensive tasks from blocking the data acquisition process, effectively preventing issues such as data buffer overflow, frame loss, or parsing timeouts. Under high-speed scanning conditions, this application can significantly shorten the overall system latency, improve real-time feedback capabilities, make image display smoother, and ensure that every line of data during the imaging process is completely recorded and visualized.
[0098] 6. Standardized SPM file export structure improves data compatibility and reproducibility: The SPM file format designed in this application follows the mainstream international AFM data structure specification and adopts a structured file header and binary data segment separation method, enabling the exported data to be directly recognized and parsed by various scientific research software such as NanoScope, Gwyddion, and WSxM. The file format includes metadata such as resolution, scan size, scaling ratio, and data offset, ensuring data consistency and high reproducibility across different platforms. Furthermore, this application supports byte alignment, terminator control, and multi-channel extended fields, providing reliable guarantees for the long-term archiving, sharing, and cross-system use of scientific research data.
[0099] 7. Suitable for high-speed, large-area, and complex sample scanning applications: Due to its significant advantages in line straightening accuracy, surface straightening reliability, brightness mapping flexibility, and multi-threaded processing performance, this application is particularly suitable for AFM imaging tasks in high-speed scanning, ultra-large field-of-view scanning, multi-scale textured samples, and high-noise environments. Whether for macroscopic scanning of large-size samples or fine imaging of micro- and nanostructures, this application maintains image coherence, realism, and high consistency, significantly improving the applicability and stability of AFM in fields such as scientific research, semiconductor process control, biological sample observation, and material evaluation.
[0100] Based on the same inventive concept, this application also provides another image processing method corresponding to the image processing method. Since the principle of the device in this application to solve the problem is similar to the above-mentioned image processing method in this application, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0101] Please see Figure 11 , Figure 11 A flowchart of another image processing method provided in the embodiments of this application includes: S601, Obtain raw height data.
[0102] The raw height data is obtained by scanning the sample surface line by line with the probe of an atomic force microscope, changing the position of the probe in the vertical direction in real time according to the undulations of the sample surface, and recording the vertical position as the height value of the corresponding scanning point.
[0103] S602. Perform the following processing on each row of data in the original height data: perform fitting calculation on the row of data according to the least squares method to obtain the original fitting baseline used to characterize the background drift trend of the row of data, apply a smoothing constraint to the original fitting baseline to obtain the smoothed fitting baseline, and subtract the smoothed fitting baseline from the row of data to obtain the corrected height data.
[0104] S603. Obtain the row straightening correction image based on the correction height data corresponding to each row data.
[0105] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0106] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the shown or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
[0107] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0108] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0109] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0110] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The scope of protection of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this application. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. An image processing method, characterized in that, include: The original height data is loaded in the user interface. The original height data is obtained by scanning the sample surface line by line with the probe of the atomic force microscope. The position of the probe in the vertical direction is changed in real time according to the undulation of the sample surface, and the vertical position is recorded as the height value of the corresponding scanning point. Receive the operation performed on the user interface to initiate line straightening correction; In response to the operation, the following processing is performed for each row of data in the original height data: the row of data is fitted using the least squares method to obtain an original fitted baseline that characterizes the background drift trend of the row of data; a smoothing constraint is applied to the original fitted baseline to obtain a smoothed fitted baseline; and the smoothed fitted baseline is subtracted from the row of data to obtain the corrected height data. Based on the correction height data corresponding to each row, a row straightening correction image is obtained and displayed in the user interface.
2. The method according to claim 1, characterized in that, Also includes: Receive the operation performed on the user interface for initiating surface straightening correction; In response to the operation, a plane fitting is performed on the two-dimensional height matrix corresponding to the original height data to obtain a fitting plane that characterizes the overall tilt trend of the original height data; The fitted plane is subtracted from the two-dimensional height matrix to obtain a surface straightening correction image, which is then displayed in the user interface.
3. The method according to claim 1, characterized in that, Also includes: The user interface provides a height range setting area, which includes a minimum value input box and a maximum value input box. Receive the minimum height value set by the user in the minimum value input box, and the maximum height value set by the user in the maximum value input box; In response to the setting, a linear transformation is performed on the height value of each pixel in the currently displayed image to map the height value to a preset grayscale range, and the mapping result is truncated according to the minimum height value and the maximum height value to obtain a brightness adjustment image, which is then displayed in the user interface.
4. The method according to claim 3, characterized in that, Also includes: The user interface displays a scan parameter setting area, which includes multiple input boxes. It receives scan parameters entered by the user in the multiple input boxes and receives operations performed on the user interface to start a scan; In response to the operation, the acquisition thread, parsing thread, and rendering thread are started according to the scanning parameters input by the user; The acquisition thread receives raw height data in real time and writes the raw height data into a circular buffer. The parsing thread reads data from the circular buffer and performs correction processing. The rendering thread refreshes and displays the corrected image in real time in the image display area of the user interface.
5. The method according to claim 4, characterized in that, Also includes: When the acquisition thread writes data to the circular buffer, a mutex lock is used to lock the write operation to prevent the parsing thread from reading data from the same location simultaneously. When the parsing thread reads data from the circular buffer, a mutex lock is used to lock the read operation to prevent the acquisition thread from writing data to the same location simultaneously.
6. The method according to claim 4, characterized in that, Also includes: After the parsing thread completes image processing, it updates the image buffer pointer through atomic variables, so that the rendering thread updates the displayed image in the image display area according to the image buffer pointer.
7. The method according to claim 4, characterized in that, Also includes: Receive operations performed on the user interface for saving data; In response to the operation, the height matrix corresponding to the target data is encapsulated into a standardized SPM file and exported for storage.
8. The method according to claim 7, characterized in that, The height matrix corresponding to the currently displayed image is encapsulated into a standardized SPM file and then exported and stored using the following method: Get the preset SPM file template; A file header is constructed based on the meta-information of the height matrix, and the file header is written into the SPM file template to obtain the exported file; The height matrix is written line by line in binary format to the exported file, and each line of data is byte-aligned to obtain the standardized SPM file, which is then exported and stored.
9. The method according to claim 8, characterized in that, The file header includes resolution, scan size, scan mode, number of channels, data offset, byte order, and calibration parameters.
10. An image processing method, characterized in that, include: The raw height data is obtained by scanning the sample surface line by line with the probe of an atomic force microscope, changing the position of the probe in the vertical direction in real time according to the undulation of the sample surface, and recording the vertical position as the height value of the corresponding scanning point. For each row of data in the original height data, the following processing is performed: the row of data is fitted using the least squares method to obtain an original fitted baseline that characterizes the background drift trend of the row of data; a smoothing constraint is applied to the original fitted baseline to obtain a smoothed fitted baseline; and the smoothed fitted baseline is subtracted from the row of data to obtain the corrected height data. Based on the correction height data corresponding to each row, a row straightening correction image is obtained.