Disclosure of Invention
The invention aims to solve the problem that the gray values of spliced images tend to be consistent by correcting an interested region and a non-interested region in the images to be spliced in different modes.
In order to achieve the above object, the present invention provides a gray scale correction method in image stitching, comprising:
selecting two adjacent images as images to be spliced;
defining a region of interest in the images to be stitched;
selecting a reference image from the images to be spliced;
and correcting the gray value of the region of interest of the non-reference image according to the gray value of the region of interest of the reference image.
Optionally, in the method, in the image to be stitched, an image with a large gray value variation range of the region of interest is used as a reference image.
Optionally, the method further includes:
acquiring an overlapping area of images to be spliced;
and correcting the gray value of the region of interest of the non-reference image according to the gray value of the intersection of the region of interest of the reference image and the overlapping region of the reference image.
Optionally, in the method, the correcting the gray value of the region of interest in the non-reference image includes:
calculating a correction slope according to a ratio of gray value change ranges of a first region and a second region, wherein the first region is an intersection of a region of interest of the reference image and an overlapping region of the reference image, and the second region is an intersection of the region of interest of the non-reference image and the overlapping region of the non-reference image;
and correcting the gray value of the region of interest of the non-reference image according to the correction slope.
Optionally, the method further includes:
calculating an intercept according to the correction slope and the gray average values of the first region and the second region;
and correcting the interested region of the non-reference image according to the correction slope and the intercept.
Optionally, the method further includes:
defining a non-interested area in the images to be spliced;
and correcting the gray value of the non-interested region of the non-reference image according to the gray value of the non-interested region of the reference image.
Optionally, the method further includes:
acquiring an overlapping area of images to be spliced;
and correcting the gray value of the non-interested region of the non-reference image according to the gray value of the intersection of the non-interested region of the reference image and the overlapping region of the reference image.
Optionally, in the method, the correcting the gray value of the non-interest region of the non-reference image includes:
obtaining a correction parameter according to the gray average value of a third area and a fourth area, wherein the third area is the intersection of the non-interested area of the reference image and the overlapping area of the reference image, and the fourth area is the intersection of the non-interested area of the non-reference image and the overlapping area of the non-reference image;
and carrying out nonlinear correction on the non-interested region of the non-reference image according to the correction parameters.
Optionally, the method further includes:
and smoothing the boundary of the interested region and the non-perceptual region.
The invention also provides a gray scale correction method in image splicing, which comprises the following steps:
selecting an image to be spliced;
defining a region of interest in the images to be stitched;
acquiring an overlapping area of images to be spliced;
selecting a reference image from the images to be spliced;
performing linear correction on the interesting region of the non-reference image according to the gray value of the intersection of the interesting region of the reference image and the overlapping region of the reference image;
and performing nonlinear correction on the non-interested region of the non-reference image according to the gray value of the intersection of the non-interested region of the reference image and the overlapping region of the reference image.
The correction method in image splicing can generate a corresponding correction scheme based on the image characteristics, and has self-adaptability. The method can finish gray correction under the condition of not losing the human body area contrast of the image to be spliced and even improving the contrast of the image to be spliced, and reduces the calculated amount in the whole splicing process.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in detail below. In the following description, specific details are set forth in order to provide a thorough understanding of the present invention. The invention can be implemented in a number of ways different from those described herein and similar generalizations can be made by those skilled in the art without departing from the spirit of the invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
When a large area is shot by X-ray, a plurality of continuous images need to be shot, and the plurality of images are spliced into a large image by using a splicing and fusing method, so that a doctor can integrally analyze a focus. The process of stitching is generally to determine two adjacent images in the plurality of images to be stitched to form a new image, and then to continue to find two adjacent images to be stitched until all the images are stitched.
The image region can be divided into a region of interest (ROI) and a region of non-interest (ROI), where the region of interest (ROI) generally refers to a human body region in the image, i.e., a region having reference meaning for diagnosis by a doctor, or other regions such as a phantom region in phantom imaging during device testing, or a region possibly related to diagnosis and detection. The non-region of interest (hereinafter referred to as non-ROI region) refers to a directly exposed region of the image where X-rays do not pass through the human body or other objects, and the portion of the region generally shows the same gray value in the image. According to the gray scale correction method in the image splicing process, the ROI is corrected firstly, and then the non-ROI is further corrected, so that the spliced images achieve the same overall effect on gray scale.
Correction of ROI regions
Fig. 1 is a flowchart illustrating correction of the ROI region. As shown in fig. 1, the method for correcting the region of interest in the stitched image comprises the following steps:
s10, defining an ROI (region of interest) for the image to be spliced; s11, calculating the overlapping part of the images to be spliced; s12, selecting a reference image from the images to be spliced; s13, the ROI region of the non-reference image is corrected based on the ROI region of the overlapping portion of the reference image.
Regarding the definition of the ROI region, a template of the ROI region is first calculated. Generally, the gray level of the ROI area in the negative film is higher than that of the non-ROI area, the ROI area and the non-ROI area are marked in the picture by setting a gray threshold or the like, and a template is formed, for example, the ROI area in the template is marked as 1, and the non-ROI area is marked as 0.
And then obtaining the coordinates of the overlapping area of the two images by using a coordinate algorithm. The coordinate algorithm is a method for calculating the coordinates of the overlapped area of the images to be spliced, the method utilizes scales of a ruler on the images to be spliced for calculation, specifically, the scales of the ruler on the upper boundary and the lower boundary of the images to be spliced are detected, the coordinates of the overlapped area of the images to be spliced are calculated through the scales of the ruler, and besides the scales of the ruler, the coordinates of the overlapped area can also be calculated through a method for matching feature points in the images.
In the above steps, the order of the step of defining the ROI region and the step of calculating the overlap region is not limited, and the overlap region may be calculated first and then the ROI region may be defined.
For the overlapping region of two images to be spliced, the gray values of the pixel points corresponding to the ROI region should be consistent theoretically. Therefore, the invention eliminates the overall gray level deviation of the spliced images by calculating the gray level average value of the ROI of the overlapped area of the images to be spliced, taking one of the images to be spliced as a reference image and carrying out linear correction on the ROI of the other image to be spliced.
For the selection of the reference image, a correction slope (K) is first determined for each of the two images to be stitched, assuming the reference image, and the image with the correction slope greater than 1 is used as the final reference image, and the other image is used as the image to be linearly corrected. In other embodiments, the step of determining the reference image may not be included, and any one of the two images to be stitched may be directly used as the reference image.
Correction gradient (maximum tone value of the overlapping region of the ROI region of the reference image-minimum tone value of the overlapping region of the ROI region of the reference image)/(maximum tone value of the overlapping region of the ROI region of the non-reference image-minimum tone value of the overlapping region of the ROI region of the non-reference image)
The calculation method of the correction slope can also be simplified as follows:
correction gradient is equal to the overlapping region gray scale change range of ROI region of reference image/the overlapping region gray scale change range of ROI region of non-reference image
According to the formula for calculating the correction slope, the contrast of the image satisfying the correction slope >1 is higher than that of the other image, and the overall contrast of the spliced image can be improved by correcting the image with the high contrast as a reference.
The calculation of the correction slope in the above step is not limited to the overlapping region, and may be calculated using the ROI region of the reference image and the ROI region of the non-reference image.
The deviation correction of the non-reference image aims at linearly transforming two ROI (region of interest) of the image to be spliced into the same gray scale range and the same gray scale mean value level, so that the gray scale mean value and the gray scale distribution range of the overlapped ROI of the reference image are calculated firstly, and a linear conversion formula of the non-reference image is obtained based on the gray scale mean value and the gray scale distribution range; and finally, correcting the ROI of the non-reference image by using a linear conversion formula.
Based on the above theory, the present invention adopts a linear variation method for correcting the slope and intercept, wherein
Intercept (b) is ROI region gray-scale mean value-correction slope of the overlapping region of the reference image × ROI region gray-scale mean value of the overlapping region of the non-reference image;
the gradation value after the change of the non-reference image ROI region is k × the gradation value + b before the change of the non-reference image ROI region.
FIG. 2 is a schematic illustration of the regions of the images to be stitched of the present invention. As shown in fig. 2, the three images a, b, and c to be stitched are included in the drawing, and the stitching process is to stitch the image a and the image b first, and then stitch the image a and the image b to generate the image c.
First, the ROI region 11 of image a and the ROI region 21 of image b are calculated; calculating the overlapping area 10 of the image a and the overlapping area 20 of the image b according to the scales of the upper boundary ruler and the lower boundary ruler of the images; the intersection of the ROI 11 of the image a and the overlapping region 10 of the image a is used as the first region 110, the intersection of the ROI 21 and the overlapping region 20 of the image b is used as the second region 210, the gray scale variation ranges of the first region 110 and the second region 210 are respectively calculated, and an image to which a region with a large gray scale variation range belongs is used as a reference image (assuming that the gray scale variation range of the first region 110 is larger than that of the second region 210 as a result of the comparison); calculating a correction slope from the gray scale variation range of the first region 110 and the gray scale variation range of the second region 210; calculating an intercept according to the gray average value of the first region 110, the gray average value of the second region 210 and the correction slope; and finally, correcting the gray value of the pixel point of the ROI area in the image b according to the correction slope and the intercept.
Correction of non-ROI regions
The non-ROI region does not generally contain any information related to clinical diagnosis, but the non-ROI region is a background region of the image, and when the gray levels of the background region in the image are not consistent, the non-ROI region may cause a doctor to make a judgment mistake on a human body region, and may also affect a visual effect. In other words, the human body area in one image is consistent, but the background is inconsistent, which may cause the visual difference of the doctor and possibly the misdiagnosis. Therefore, in the present invention, the non-ROI region is further subjected to the consistency correction.
Regarding the correction of the non-ROI area, the method of compressing the curve is adopted in the invention, the non-ROI area in the two images is compressed to the same gray level, and the specific compression formula is as follows:
wherein x is the gray value of the pixel point in the non-ROI area before correction, and y is the gray value of the pixel point in the non-ROI area after correction.
T in the formula is a piecewise function threshold which can be manually set or automatically calculated according to the calculation of the mean value and the variance, when x is less than or equal to T, the non-ROI area is compressed, and when x is greater than T, the gray value is kept unchanged. The threshold T is therefore the boundary point of the gray levels of the body region and the non-ROI region.
Fig. 3 is a schematic view of a compression curve of a non-ROI region of the present invention, as shown in fig. 3, wherein a threshold value T is represented at a circle mark, an abscissa represents a gray level of an image before compression, and an ordinate represents a gray level of an image after compression. The gray scale compression curve is a partial curve with an abscissa of 0-T, and it can be seen from fig. 3 that the range of 0-1000 gray scale of the image before compression approximately corresponds to the range of 0-500 gray scale of the image after compression, that is, the gray scale range of the image after compression is narrower than the gray scale range of the image before compression, and the corresponding gray scale value is also reduced.
The determination of the compression degree parameter α is calculated based on the gray average of the non-ROI region in the overlapping region of the reference image. First, the gray average (y) of the overlapping region of the non-ROI region of the reference image is calculated
1) Recalculating the non-reference imageOverlapping region mean gray (x) of non-ROI region
1) Substituting the above average into the formula
And obtains the compression degree parameter alpha of the non-reference image through inverse operation.
Fig. 4 is a flow chart illustrating correction of a non-ROI region according to the present invention. As shown in fig. 4, the correction of the non-ROI region includes the steps of: s20, acquiring a grayscale mean of an overlapping region of the non-ROI region of the reference image, wherein the acquiring of the reference image, the non-ROI region and the overlapping region in this step is the same as the method for correcting the ROI region, and is not described herein again; s21, acquiring the grayscale mean value of the overlapping region of the non-ROI of the non-reference image; s22, calculating a compression degree parameter, and calculating a compression degree parameter alpha according to the overlapping region gray scale mean value of the non-ROI region of the reference image and the overlapping region gray scale mean value of the non-ROI region of the reference image obtained in the step (A); s23, correcting the non-ROI area of the non-reference image according to the compression degree parameter alpha; and S24, fusing the reference image and the non-reference image, wherein the fusion can be a method of taking a gray average value of the corresponding point and the like.
The compression degree parameter α may also be calculated in the above step as the entire non-ROI region gray level mean value of the reference image and the entire non-ROI region gray level mean value of the non-reference image.
Further, in order to ensure the smoothness of the compression curve, in actual use, the compression curve is subjected to a smoothing operation, and the smoothing operation plays a role of smoothing the whole curve, because the function is a piecewise function, the position of the threshold value T is not smooth enough, so that the image gray scale change is severe and the image effect is influenced, and therefore, once smoothing filtering is performed by using a smoothing filtering kernel, the curve is smoother.
Although the present invention has been described with reference to the preferred embodiments, it is not intended to limit the present invention, and those skilled in the art can make variations and modifications of the present invention without departing from the spirit and scope of the present invention by using the methods and technical contents disclosed above.