A CUDA acceleration-based fast correction method for pillow-shaped distortion of microscopic images
The method for fast correction of pincushion distortion in microscopic images based on CUDA acceleration solves the problem of slow correction speed in microscopic image distortion, and realizes rapid correction and high-quality stitching of microscopic images.
Patent Information
- Application Number
- CN202310365443.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-07
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2043-04-07
AI Technical Summary
Existing microscopic image distortion correction algorithms are slow and cannot meet the rapid correction requirements in practical applications of microscopic images. Furthermore, traditional methods are not applicable to the distortion characteristics of microscopic cameras.
A fast correction method for pincushion distortion in microscopic images based on CUDA acceleration is adopted. By reading the square grid image captured by the microscope camera, the coordinate mapping relationship of the grid center point before and after distortion is calculated, the perspective transformation coefficient is calculated in blocks, and the GPU is used for parallel computing to achieve fast distortion correction.
It enables rapid correction of microscopic images, meets real-time requirements, provides the possibility for subsequent microscopic image stitching, and improves the image stitching quality.
Smart Images

Figure CN116739910B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the field of digital image processing, and particularly relates to a method for quickly correcting pillow-shaped distortion of microscopic images based on CUDA acceleration. BACKGROUND
[0002] Microscopy is an indispensable part of modern medical examination. In recent years, with the development of technology, more and more automatic microscopes are widely used in various hospitals and research institutes to replace traditional manual microscopy. In traditional manual microscopy, doctors control the microscope to observe the state of pathological sections in the continuous field of view and make a diagnosis. In the automatic microscope, a microscopic camera automatically captures microscopic images to replace the manual movement of the microscope field of view by the doctor, greatly improving the work efficiency of the doctor. Due to the limitation of magnification, the range captured by the microscopic camera is small, and the entire pathological section cannot be observed. Therefore, it is required to splice the continuous pathological microscopic images to expand the field of view. Due to the inherent characteristics of the optical lens, the microscopic images captured by the CCD camera are distorted, especially at the edge of the field of view, the image will be obviously curved. The influence of this distortion on a single digital microscopic image can be ignored, but when multiple images are spliced to obtain a larger field of view, the images to be spliced cannot be completely matched under the influence of distortion, and obvious gaps will be generated at the splicing position, which seriously affects the splicing effect. Therefore, to obtain a high-quality large-field-of-view spliced image, it is particularly important to perform distortion correction preprocessing on a single microscopic image.
[0003] Most of the existing distortion correction algorithms are used for ordinary cameras, which can capture images at different angles to obtain camera distortion parameters. However, the microscopic camera has high magnification, small field of view, and cannot change the angle of view, so the traditional method cannot be used. At the same time, the existing distortion correction algorithm is slow and cannot meet the fast correction requirements in the practical application of microscopic images. SUMMARY
[0004] The purpose of the present application is to provide a method for quickly correcting the pillow-shaped distortion of microscopic images based on CUDA acceleration to overcome the shortcomings of the prior art. The method is aimed at the limitations of the microscopic camera and the application scenario, and realizes the fast correction of the distortion of the microscopic image.
[0005] The specific technical scheme to achieve the purpose of the present application is as follows:
[0006] A method for quickly correcting the pillow-shaped distortion of microscopic images based on CUDA acceleration, the method comprising the following steps:
[0007] Step 1: read in a square grid image captured by a microscopic camera, extract the grid contour using an image algorithm, and calculate the mapping relationship between the coordinates of the grid center points before and after distortion;
[0008] Step 2: Calculate the image pillow-shaped distortion parameters, and at the same time, block the image, and calculate the perspective transformation coefficients in each area;
[0009] Step 3: Read in the micrograph to be processed, upload to the graphics processing unit GPU (Graphics Processing Unit), and use the parallel computing CUDA (Compute Unified Device Architecture) to accelerate; Step 4: According to the pillow-shaped distortion correction formula, calculate the distorted coordinates (x g1 ,y g1 ) of the current position, and according to the perspective transformation formula, calculate the distorted coordinates (x g2 ,y g2 ) of the current position, and the weighted average of the two distorted coordinates is obtained.
[0010] Step 5: Use bicubic interpolation to obtain the pixel value of the distorted coordinates, and place it in the current position to complete the image distortion correction.
[0011] Step 1 uses the image algorithm to extract the grid contour, and calculates the mapping relationship of the grid center point coordinates before and after distortion, which specifically includes the following steps:
[0012] Step 1.1: Read in the square grid image taken by the micro camera, do white balance processing and convert it into a gray-scale image;
[0013] Step 1.2: Use the OTSU algorithm to perform threshold segmentation on the gray-scale image, and extract the contour of the segmented binary image;
[0014] Step 1.3: Calculate the average size of all contours, filter the contours according to the contour area, calculate the average size of the contours, and remove the contours with an area less than 1 / 3 of the average size of the contours;
[0015] Step 1.4: Use the morphological processing algorithm on the remaining contours to obtain the standard grid contour;
[0016] Step 1.5: Calculate the center point of each contour to obtain the center point coordinates of the grid, which are the coordinates of the distorted grid;
[0017] Step 1.6: According to the position, the center point coordinates of the 5*5 grid in the center of the image are screened out, and according to the lens distortion characteristics of the camera, it is determined that the area has not been distorted. Take the center point of the most central grid in the image as the starting point, and calculate the pre-distortion coordinates of the other grid center points according to the starting point coordinates and the grid position.
[0018] The step 2 is specifically:
[0019] Step 2.1: Establish the pillow-shaped distortion correction formula, substitute the corresponding coordinates before and after the distortion, and obtain the distortion correction parameters k1, k2 and k3 and save them;
[0020] Step 2.2: Select the center point of the center grid of the 5*5 grid as the starting point of the standard grid, and divide the image into several standard square regions with the standard distance as the width;
[0021] Step 2.3: Process the square regions divided from the image in turn, involving 2*2 adjacent grids in one square region, containing 4 grid center points in total. To prevent the coordinates after the perspective transformation from exceeding the range of the square region, the square region is expanded outward by one-half of the standard distance width, and the perspective transformation is performed in the expanded local region. The perspective transformation coefficients are calculated, and the inverse transformation coefficients m 00 , m 01 , m 02 , m 10 , m 11 , m 12 , m 20 , m 21 and m 22 are calculated and saved in order.
[0022] The step 4 specifically comprises:
[0023] Step 4.1: In each thread opened by GUP, the coordinates (x correct ,y correct ) of the pixel processed by the current thread are obtained according to the thread ID, and it is judged whether the current coordinates exceed the image range;
[0024] Step 4.2: Obtain the pillow-shaped distortion correction parameters, substitute the current coordinates and k1, k2, k3 into the pillow-shaped distortion correction formula, and obtain the coordinates (x g1 ,y g1 ) after the distortion;
[0025] Step 4.3: Determine which square region range the current coordinates belong to, and obtain the perspective transformation coefficients in the region;
[0026] Step 4.4: Expand the square region outward, calculate the local coordinates of the current coordinates in the expanded region, substitute them into the perspective transformation formula, and convert them into global coordinates to obtain the coordinates (x g2 ,y g2 ) after the distortion;
[0027] Step 4.5: Set the coefficient a, 0≤a≤1, calculate the weighted average of the two coordinates after the distortion, and finally obtain the position (x grid ,y grid ) after the distortion of the current position.
[0028] The present application is based on the fact that traditional image correction algorithms are not suitable for microscopic image correction and are slow, and in view of the distortion characteristics of microscopic images and the real-time requirements in the actual application of microscopic image distortion correction, the present application realizes fast correction of the distortion of microscopic images, and provides the possibility for subsequent real-time microscopic image stitching and other requirements. BRIEF DESCRIPTION OF DRAWINGS
[0029] Figure 1 is a grid image obtained by using a microscopic camera to shoot a square grid slide;
[0030] Figure 2 is a part of the profile of the grid image obtained by processing the grid image;
[0031] Figure 3 is a schematic diagram of image blocking;
[0032] Figure 4 is a schematic diagram of a local area after expansion of a blocking area;
[0033] Figure 5 is a schematic diagram of a slide used to shoot the grid image;
[0034] Figure 6 is a schematic diagram of Figure 1 the grid image after distortion correction;
[0035] Figure 7 is a flowchart of the present application. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical scheme and advantages of the present application clearer, the present application will be described in detail below in combination with the drawings and examples.
[0037] Referring to Figure 7 , the present application discloses a CUDA-accelerated microscopic image fast pincushion distortion correction method, which includes two parts: preprocessing and fast correction algorithm. The preprocessing algorithm uses image algorithms to obtain the coordinate correspondence before and after distortion, and calculates and saves the overall and local distortion correction coefficients; the fast distortion correction algorithm uses the aforementioned distortion correction coefficients to obtain the coordinates of each pixel in the distorted image, and superimposes the correction effect to obtain the final corrected image.
[0038] The first part is the preprocessing algorithm for distortion correction, which includes:
[0039] Step 1: read in the square grid image shot by using a microscopic camera, as shown in Figure 1 , use image algorithms to extract the grid profile, calculate the mapping relationship of the grid center point coordinates before and after distortion, specifically:
[0040] A square grid image taken by a microscopic camera is read in, white balance is processed and converted into a gray scale image; a 0TSU threshold algorithm is used to segment the threshold of the gray scale image, and the extracted contour is extracted from the binary image after segmentation; the average value of all contour sizes is calculated, the contour is screened according to the contour size, and the smaller impurities and other non-grid contours are removed; the remaining contour is processed using morphological processing, and an opening operation is performed to obtain a more standard grid contour, and finally a part of the obtained contour is as shown in Figure 2 ;
[0041] For each contour, the x and y coordinates of all points on the contour are summed in turn, and then divided by the length of the contour to obtain the center point of the grid contour, and the center point coordinates of the grid are obtained; the contour center point sequence is sorted according to the y coordinate, and the center points are classified according to the value of the y coordinate, starting from the 0th row, each row is stored as a sub-vector, and all center points are stored as a two-dimensional vector, a total of N row rows; for each row, sorting is performed according to the x coordinate, and the arrangement is from left to right, a total of N col columns;
[0042] Check the number of grid center points, whether there is a missing, if the number of missing points is less than 2, locate the number of abnormal rows, use the average value of the coordinates of the four adjacent grid center points to replace the value at this position, if the number of missing points is greater than or equal to 2, report an exception, re-shoot and return;
[0043] Check the number of grid center points, whether there is a surplus, if the surplus number is less than 2, locate the number of abnormal rows, judge the difference value of the adjacent grid center point coordinates, if the difference value is obviously smaller than the distance between the grid center points, delete the coordinates, if the surplus points cannot be accurately located or the number of surplus points is greater than or equal to 2, report an exception, re-shoot and return; check the value of the grid center point, and the average value of the coordinates of the adjacent upper and lower grid center points, if the difference is large, compare it with the average value of the coordinates of the adjacent left and right grid center points, if the difference is still large, use the average value of the coordinates of the four adjacent grid center points to replace the value at this position;
[0044] According to the position, the center point coordinates of the 5*5 grid in the center of the image are screened out, according to the lens distortion characteristics of the camera, it is determined that the area has not been distorted, and the distance between the grid center points in this area is taken as the standard distance W. In the two-dimensional grid center point coordinate vector of N row rows and N col columns, the point with subscript (N row / 2, N col / 2) is the center point of the grid located in the center of the image, the coordinates of the point are (X START , Y START ), and the contour center point coordinates of the grid located in the i-th row and j-th column in the grid image are (xgrid y grid ), its corresponding coordinates before distortion (x correct y correct It can be obtained from the formula, specifically:
[0045] x correct =X START +(jN col / 2)*W
[0046] y correct =Y START +(iN row / 2)*W
[0047] By processing each grid cell, a total of N cells can be obtained. row *N col For corresponding points before and after distortion.
[0048] Step 2: Calculate the pincushion distortion parameters of the image, and simultaneously divide the image into blocks, calculating the perspective transformation coefficients for each region, specifically:
[0049] With (X) START Y START Using as the center point, establish the formula for correcting pincushion deformity:
[0050] x grid -X START =(x correct -X START )*(1+k1r 2 +k2r 4 +k3r 6 )
[0051] y grid -Y START =(y correct -Y START )*(1+k1r 2 +k2r 4 +k3r 6 )
[0052] Where r is (x correct y correct Distance point (X) START Y START Distance:
[0053] r = (x correct -X START ) 2 +(y correct -Y START ) 2
[0054] Before distortion (x) correcty correct ) and corresponding distorted coordinates (x) grid y grid Substitute them into the equations respectively to obtain the distortion correction parameters k1, k2, and k3 and save them.
[0055] With point (X) START Y START Starting from a point (e.g., ) and with a standard distance W as the width, the image is divided into several standard square regions. Each square region involves adjacent 2x2 grids and contains a total of 4 grid center points, such as... Figure 3 As shown, the solid lines represent the grid outline, and the dashed lines represent image block regions. A perspective transformation is applied to this region for correction, and the perspective transformation coefficients are calculated. To prevent the coordinates from exceeding the square region after the perspective transformation, the square region is expanded outward by W / 2, forming a local region for the perspective transformation, as shown below. Figure 4 As shown, perform perspective transformation within this local area;
[0056] Within a local area, the coordinates of the center point of the contour are (u grid v grid ), its corresponding coordinates before distortion (u correct v correct Then we have:
[0057] u grid =x grid -W / 2
[0058] v grid =y grid -W / 2
[0059] u correct =x correct -W / 2
[0060] v correct =y correct -W / 2
[0061] Substitute into the perspective transformation formula:
[0062]
[0063] Substituting the coordinate pairs before and after distortion, the perspective transformation coefficient m within each square region is calculated. 00 m 01 m 02 m 10 m 11 m 12 m 20 m 21 and m 22 And save them in order;
[0064] The second part is a CUDA-based fast distortion correction implementation, which includes the following steps:
[0065] Step 3: Read in the micrograph image to be processed and upload it to the graphics processing unit (GPU) for parallel computing using CUDA acceleration. The specific steps are as follows:
[0066] Upload the image to be processed, a blank image for storing the correction results, the pillow-shaped distortion correction parameters, and the perspective transformation coefficients to the GPU. In the GPU, several threads are opened, each thread processing one pixel. In each thread, the same processing is performed.
[0067] Step 4: Calculate the distorted coordinates (x g1 ,y g1 ) at the current position according to the pillow-shaped distortion correction formula, and calculate the distorted coordinates (x g2 ,y g2 ) at the current position according to the perspective transformation formula. The final distorted coordinates are obtained by weighted averaging of the two distorted coordinates. The specific steps are as follows:
[0068] According to the thread ID, the coordinates (x correct ,y correct ) of the pixel processed by the current thread are obtained. The specific steps are as follows:
[0069] x correct =threadIdx.x+blockIdx.x*blockDim.x
[0070] y correct =threadIdx.y+blockIdx.y*blockDim.y
[0071] Determine whether the current coordinates exceed the image range. If so, do not process. Obtain the pillow-shaped distortion correction parameters k1, k2, and k3, and substitute the current coordinates and k1, k2, and k3 into the pillow-shaped distortion correction formula to obtain the distorted coordinates (x g1 ,y g1 ). The pillow-shaped distortion correction formula is as follows:
[0072] x grid -X START =(x correct -X START )*(1+k1r 2 +k2r 4 +k3r 6 )
[0073] y grid -Y START =(y correct -Y START )*(1+k1r 2 +k2r4 +k3r 6 )
[0074] Where r is (x correct y correct Distance point (X) START Y START Distance:
[0075] r = (x correct -X START ) 2 +(y correct -Y START ) 2
[0076] To determine which square region the current coordinates belong to, we need to obtain the row number i and column number j of the square region. Specifically:
[0077] i = x correct / W
[0078] j = y correct / W
[0079] Calculate the coordinates (x, y) of the pixel being processed by the current thread. correct y correct Local coordinates (u) within the local area of the square region correct v correct Specifically, these include:
[0080] u correct =x correct %W+W / 2
[0081] v correct =y correct %W+W / 2
[0082] Obtain the perspective transformation coefficient m within this region. 00 m 01 m 02 m 10 m 11 m 12 m 20 m 21 m 22 Substituting the local coordinates and perspective transformation coefficients into the perspective transformation formula, we obtain the distorted coordinates (u) within the local region. grid v grid Specifically, these include:
[0083]
[0084]
[0085] According to (u)grid , u grid ), specifically as follows: g2 , y g2 ), specifically as follows:
[0086] x g2 = u grid + j * W - W / 2
[0087] y g2 = v grid + i * W - W / 2
[0088] Set a coefficient a (0≤a≤1), and comprehensively consider two kinds of distortion correction parameters, finally get the position (x grid , y grid ) of the pixel after distortion, specifically as follows:
[0089] x grid = x g1 * a + x g2 * (1-a)
[0090] y grid = y g1 * a + y g2 * (1-a)
[0091] Step 5: using bicubic interpolation method, get the image after distortion, that is, the pixel value of the image to be processed located at (x grid , y grid ) is placed in the blank image (x correct , y correct ), specifically as follows:
[0092] For the pixel to be interpolated (x grid , y grid ), where x grid , y grid are floating-point numbers, take their 4x4 neighborhood points (x i , y j ), i, j = 0, 1, 2, 3. Interpolation calculation is performed according to the following formula:
[0093]
[0094] Wherein:
[0095]
[0096] After all the pixels are processed by GPU, the processed image is downloaded from GPU to CPU, and the distortion correction is completed.
[0097] Embodiment
[0098] In this embodiment, a microscope camera was used to photograph a glass slide with a grid width of 10 μm. The slide photograph is shown below. Figure 5 As shown, a grid image is obtained, with a size of 3200*2200. Figure 1 As shown.
[0099] The specific process is as follows:
[0100] S101: Read in a square grid image captured by a microscope camera, extract the grid outline using image algorithms, and calculate the mapping relationship between the grid center point coordinates before and after distortion.
[0101] Using the same equipment, the preprocessing algorithm only needs to be called once. The square grid image captured by the microscope camera is read in, white balance is applied, and it is converted to a grayscale image. The OTSU thresholding algorithm is used to perform thresholding segmentation on the grayscale image, and contours are extracted from the segmented binary image. Further processing of the extracted contours yields a more standard grid contour, a portion of which is shown below. Figure 2 As shown. Calculate and sort the center point coordinates of the mesh contours, and check if the number and values of the calculated mesh center point coordinates are correct. For each contour, find the center point of the mesh contour, obtain the center point coordinates of the mesh, and store them as a two-dimensional array with a total of N. row Okay, N col The coordinates here are floating-point numbers to avoid loss of precision.
[0102] Check the number of grid center points to see if any are missing. If the number is less than 2, replace the value with the average coordinates of the four nearest grid center points (up, down, left, and right). If the number of missing points is greater than or equal to 2, report an error, request a retake, and return the image. Check the number of grid center points to see if any are redundant. If the number of redundant points is less than 2, delete the erroneous center point coordinates. If the redundant points cannot be accurately located or the number of redundant points is greater than or equal to 2, report an error, request a retake, and return the image. Check the value of each grid center point and compare it with the average coordinates of the two nearest grid center points (up, down, left, and right). If the difference is large, replace the value with the average coordinates of the four nearest grid center points (up, down, left, and right).
[0103] Based on the location, the center point coordinates of a 5x5 grid in the image center are selected. According to the characteristics of camera lens distortion, this area is determined to be distortion-free, and the distance between the center points of the grid in this area is taken as the standard distance W. In N... row Okay, N col In the coordinate vector of the center point of the two-dimensional grid in the column, the subscript is (N row / 2,N col The point ( / 2) is the center point of the grid located at the very center of the image, and its coordinates are (X...). START Y START), the grid in the i-th row and j-th column in the grid image, the profile center point coordinate is (x grid , y grid ), the corresponding coordinate before distortion (x correct , y correct ) can be obtained according to the formula, specifically:
[0104] x correct = X START +(j-N col / 2)*W
[0105] y correct =Y START +(i-N row / 2)*W
[0106] For each grid, a total of Nrow*Ncol pairs of corresponding points before and after distortion can be obtained.
[0107] S102: Calculate the image pincushion distortion parameters, and block the image, and calculate the perspective transformation coefficients in each region.
[0108] Take (X START , Y START ) as the center point, establish the pincushion distortion correction formula, and substitute the coordinates before distortion (x correct , y correct ) and the corresponding coordinates after distortion (x grid , y grid ) into the formula and calculate the average to obtain the distortion correction parameters k1, k2, k3 and save them. The pincushion distortion correction formula is specifically:
[0109] x grid -X START =(x correct -X START )*(1+k1r 2 +k2r 4 +k3r 6 )
[0110] y grid -Y START =(y correct -Y START )*(1+k1r 2 +k2r 4 +k3r 6 )
[0111] r=(x correct -X START ) 2 +(y correct -Y START ) 2
[0112] To prevent the coordinates from exceeding the square region after the perspective transformation, the square region is expanded outward by W / 2, forming a local area for the perspective transformation. Figure 4 As shown; within the local region, the coordinates of the contour center point are (u grid v grid ), its corresponding coordinates before distortion (u correct v correct Substituting into the perspective transformation formula, we can obtain the perspective transformation coefficient m. 00 m 01 m 02 m 10 m 11 m 12 m 20 m 21 m 22 Save them in order. The perspective transformation formula is:
[0113]
[0114] S103: Reads in the microscopic image to be processed and uploads it to the graphics processing unit (GPU) for CUDA parallel computing acceleration, specifically including:
[0115] The image to be processed was captured in the same environment as the grid image, and its size is 3200*2200. For ease of observation, in this embodiment of the invention, [the image is...]. Figure 1 The grid image shown is subjected to distortion correction. A new blank image is created to store the processed image. The width of the new blank image is ((N) col -1)*W, height is (N) row -1)*W. Upload the image to be processed, the blank image, the pincushion distortion correction parameters, and the perspective transformation coefficients to the GPU. Create several threads in the GPU, with each thread processing one pixel. Perform the same processing within each thread.
[0116] S104: Calculate the distorted coordinates (x, y) of the current position according to the pincushion distortion correction formula. g1 y g1 ), calculate the distorted coordinates (x, y) of the current position according to the perspective transformation formula. g2 y g2 The final distorted coordinates are obtained by weighted averaging the two distorted coordinates.
[0117] The coordinates (x, y) of the pixel being processed by the current thread are obtained based on the thread ID. correct y correct The algorithm checks if the current coordinates exceed the image range; if so, no action is taken. It then obtains the pincushion distortion correction parameters k1, k2, and k3, and substitutes the local coordinates and k1, k2, and k3 into the pincushion distortion correction formula to obtain the coordinates before distortion (x...).g1 , y g1 ). Determine which square region the current coordinate belongs to, calculate the local coordinates (u correct , v correct ) of the pixel coordinate (x correct , y correct ) in the local region where the square region is located, obtain the perspective transformation coefficients in the region, substitute them into the perspective transformation formula, obtain the pre-distortion coordinates (u grid , v grid ) in the local region, and then calculate the pre-distortion coordinates (x g2 , y g2 ). Set a coefficient a (0≤a≤1), comprehensively consider two distortion correction parameters, and finally obtain the position (x grid , y grid ) corresponding to the pixel after distortion. In the embodiment of the application, a is set to 0.5, and the results of the two distortion correction methods are fully utilized.
[0118] S105: using bicubic interpolation method, obtaining the image after distortion, i.e. the pixel value of the image to be processed located at (x grid , y grid ) is placed at (x correct , y correct ) of the blank image.
[0119] For the pixel to be interpolated (x grid , y grid ), wherein x grid , y grid are floating-point numbers, and the 4x4 neighborhood points (x i , y j ) around them are taken, i, j=0, 1, 2, 3. Interpolation calculation is performed according to the following formula:
[0120]
[0121] Wherein:
[0122]
[0123] After all the pixels are processed by the GPU, the processed image is downloaded from the GPU to the CPU, and the distortion correction is completed.
[0124] In this embodiment, based on Intel i5-10500 processor, NVIDIA GeForce GTX 1080Ti GPU, the size of the image to be processed is 3200*2200, and the time consumption of the fast distortion correction based on CUDA is only 7ms. The correction can be performed at the same time as shooting, and the real-time requirement of the microscopic image distortion correction application can be met. Figure 1The image edge grid lines are deformed and curved outward at both ends with pillow distortion in the shown uncorrected image, and the image edge grid lines are parallel to the image edge with deformation disappeared in the corrected image as shown Figure 6 The image edge grid lines are parallel to the image edge with deformation disappeared in the shown corrected image.
Claims
1. A CUDA-accelerated method for fast correction of pincushion distortion in microscopy images, characterized in that, The method comprises the following steps: Step 1: read the square grid image taken by the micro camera, use the image algorithm to extract the grid contour, and calculate the mapping relationship of the center point coordinates before and after distortion; Step 2: calculate the image pillow-shaped distortion parameters, and at the same time, block the image, and calculate the perspective transformation coefficients in each area; Specifically: Step 2.1: Establish the pillow-shaped distortion correction formula, substitute the corresponding coordinates before and after distortion, and obtain the distortion correction parameters 、 and and save; Step 2.2: select the center point of the 5*5 grid center grid as the starting point of the standard grid, and divide the image into several standard square areas with the standard distance as the width; Step 2.3: Process the square regions divided from the image sequentially. Within each square region, design a 2x2 grid containing four grid center points. To prevent the coordinates from exceeding the square region after the perspective transformation, expand the square region outward by half the standard distance width. Perform perspective transformation within the expanded local region, calculate the perspective transformation coefficients, and deduce the inverse transformation coefficients. , , , , , , , and And save them in order; Step 3: read the micro image to be processed and upload it to the graphics processing unit (GPU) for parallel computing using CUDA acceleration; Step 4: Calculate the distorted coordinates of the current position according to the pincushion distortion correction formula. , ), calculate the distorted coordinates of the current position according to the perspective transformation formula. , The final distorted coordinates are obtained by weighted averaging of the two distorted coordinates; specifically including: Step 4.1: In each thread created by the GUP, obtain the coordinates of the pixel being processed by the current thread based on the thread ID. , ), determine whether the current coordinates exceed the image range; Step 4.2: Obtain pincushion distortion correction parameters, and combine the current coordinates with... , , Substituting into the pincushion distortion correction formula, we obtain the distorted coordinates ( , ); Step 4.3: determine which square area the current coordinate belongs to, and obtain the perspective transformation coefficient in the area; Step 4.4: expand the square region outward, find the local coordinate of the current coordinate in the expanded region, substitute into the perspective transformation formula, and convert to global coordinate to get the distorted coordinate , ) Step 4.5: Set the coefficient , 0≤ ≤1, calculate the weighted average of the two distorted coordinates, and finally get the distorted position of the current position , ) Step 5: use bicubic interpolation to obtain the pixel value of the distorted coordinate, and place it in the current position to complete the image distortion correction.
2. The method of fast correction of pincushion distortion of microscopy images of claim 1, wherein, Said step 1, specifically comprising the following steps: Step 1.1: read the square grid image taken by the micro camera, do white balance processing and convert it into a gray image; Step 1.2: use OTSU algorithm to threshold segment the gray image, and extract the contour of the segmented binary image; Step 1.3: calculate the average value of all contour sizes, filter the contours according to the contour area, and obtain the average size of the contours, and remove the contours with an area less than 1 / 3 of the average value of the contour area; Step 1.4: use morphological processing algorithm on the remaining contours to obtain the standard grid contour; Step 1.5: calculate the center point of each contour to obtain the center point coordinates of the grid, which are the coordinates after distortion; Step 1.6: according to the position, the center point coordinates of the 5*5 grid in the center of the image are screened out, according to the characteristics of the camera lens distortion, it is determined that the area has not been distorted, the distance between the center points of the area grid is taken as the standard distance, the center point of the most central grid in the image is taken as the starting point, and the coordinates of the other grid center points before distortion are calculated according to the starting point coordinates and grid position.
Citation Information
Patent Citations
Lens distortion correction method and photographic device
CN110533618A
A system, apparatus, and method for determining elemental composition using 4d stem
WO2020214985A1