Disclosure of Invention
The invention aims to solve the problems, and provides an image stitching method and system which can realize rapid and high-quality image stitching.
In order to achieve the above object, the present invention is specifically as follows:
an image stitching method disclosed in one or more embodiments includes:
extracting characteristic points of the images to be spliced, describing and matching the characteristic points to obtain rough matched characteristic points;
counting the number of feature points conforming to the matching relation in the pixel areas adjacent to the rough matching point set, and removing the wrong matching points by calculating the feature neighborhood score;
calculating a homography transformation matrix of the images to be spliced according to the feature points which are accurately matched, and registering the images; and (5) realizing smooth image stitching through a weighted smoothing algorithm.
Further, image feature extraction and description are performed using an ORB algorithm.
Further, rough matching of the feature points is carried out by using a violent matching algorithm, and error rough matching is filtered by using a cross matching method.
Further, dividing the image into a plurality of non-overlapping grids, counting the feature score of each grid, and simultaneously counting the feature neighborhood scores of the adjacent grids with a set number; rotating the grids and the adjacent grids to obtain the maximum grid characteristic score; when the maximum grid feature score is greater than the grid feature score threshold, judging that the grid features are correctly matched; otherwise, the matching is wrong.
Further, feature neighborhood scores of eight grids adjacent to the current grid are counted to obtain nine-grid feature scores.
Further, the mean value of the number of coarse matching features of the grid in the current nine-grid is counted, and a grid feature score threshold is determined according to the mean value.
Further, constructing a global homography matrix between image sequences through matching point pairs; calculating a homography matrix of local dependence by adding weight coefficients; the weight coefficient is determined according to the Gaussian distances from the current feature point to all feature points on the image.
Further, according to the obtained homography matrix of local dependence, corresponding images are transformed to determine overlapping areas among the images, and the images to be fused are mapped into a new blank image to form a mosaic.
An image stitching system disclosed in one or more embodiments includes a server including a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the image stitching method described above when executing the program.
A computer readable storage medium disclosed in one or more embodiments has stored thereon a computer program which, when executed by a processor, performs the above-described image stitching method.
The invention has the beneficial effects that:
(1) The invention provides a coarse matching feature point screening method for grid neighborhood feature statistics, which realizes accurate matching of feature points by counting the number of feature points conforming to a matching relation in a pixel area adjacent to a coarse matching point set and eliminating feature points which are mismatched.
(2) The invention provides an image registration method based on a weighted projection transformation model, which calculates a locally dependent homography transformation matrix by adding a Gaussian weight coefficient, and solves the problem of ghost effect and parallax error caused by global homography matrix registration.
(3) The invention greatly improves the characteristic fine matching speed and the registration precision, the synthesized image has no obvious geometric dislocation and blurring problems, and the edge transition of the overlapped area is good.
The specific embodiment is as follows:
the invention is described in detail below with reference to the attached drawing figures:
it should be noted that the following detailed description is illustrative and is intended to provide further explanation of the invention. Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
It is noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of exemplary embodiments according to the present invention. As used herein, the singular is also intended to include the plural unless the context clearly indicates otherwise, and furthermore, it is to be understood that the terms "comprises" and/or "comprising" when used in this specification are taken to specify the presence of stated features, steps, operations, devices, components, and/or combinations thereof.
Example 1
In one or more embodiments, an image stitching method is disclosed, as shown in fig. 1, a feature extraction ORB algorithm is applied to image stitching, and correct matching and incorrect matching are distinguished by counting feature numbers conforming to a matching relationship in pixel areas adjacent to rough matching feature points, so that the precision matching speed of the feature points is improved; and then, adopting a weighted projection transformation method, introducing a pixel distance relation to optimize the weight coefficient of the transformation model, and improving the registration accuracy of the overlapped region. The method comprises the following specific implementation processes:
1. feature extraction
The method is realized by the following steps:
(1) Feature point extraction
ORB (Oriented FAST and Rotated BRIEF) is an algorithm for fast feature point extraction and description. The ORB algorithm is divided into two parts, feature point extraction and feature point description. Feature extraction was developed from the FAST (Features from Accelerated Segment Test) algorithm, and feature point descriptions were improved according to the BRIEF (Binary Robust IndependentElementary Features) feature description algorithm.
A point P is selected from the image, and the FAST algorithm judges whether the point is a characteristic point or not by drawing a circle with a radius r by taking the P as a circle center. If the gray value of n continuous pixel points on the circumference is larger or smaller than the gray value of P points, P is regarded as the characteristic point. In order to solve the problem of a plurality of feature points at the adjacent positions, the invention sorts the detected FAST feature points according to Harris corner response values, and selects the point with the response value of 80% at the front (if 100 FAST feature points are detected in total, 80 points with the Harris corner response values sorted at the front are extracted) as the extracted feature points.
In order to realize the multi-scale invariance of the feature points, the method adopts a mode of establishing pyramid images. By setting a scale factor scaleFactor (the value of the invention is 1.2) and the number of pyramid layers nlevels (the value of the invention is 8). The original image is then scaled down by a scaling factor to nlevels images. The scaled image is: i' =i/scaleefaactork (k=1, 2, …, nlevels). The nlevels images with different proportions extract the sum of the characteristic points as the characteristic points of the image.
Since FAST features do not have directionality, the ORB algorithm uses a moment (motion) method to determine the direction of FAST feature points. And calculating the centroid of the characteristic point in the radius range of r by using the moment, wherein the coordinate of the characteristic point and the centroid form a vector as the direction of the characteristic point. The moment is defined as follows:
wherein I (x, y) is the pixel value of the image pixel point (x, y). The centroid of this moment is:
a direction vector is formed between the image feature point and the centroid, so that the direction of the feature point can be represented by the angle of the direction vector, and the calculation formula is as follows:
(2) Description of feature points
The ORB algorithm is characterized by adding twiddle factors based on BRIEF characterization. The BRIEF algorithm computes a binary string feature descriptor. In the neighborhood of one feature point, n pairs of pixel points pi and qi (i=1, 2, … and n) are selected. The magnitude of the gray value of each dot pair is then compared. If I (pi) > I (qi), then a value of 1 is generated for the corresponding position in the binary string, otherwise 0. All pairs of points are compared, and a binary string of length n is generated. In order to increase the noise resistance of the feature descriptor, the invention firstly carries out Gaussian smoothing on the image, uses the mxm neighborhood gray average value of a certain point in the neighborhood to replace the value of the certain point pair, and further compares the sizes of the point pairs, thereby enabling the feature value to have noise resistance.
Because the BRIEF descriptor lacks rotational invariance, the ability to resist rotation of the image plane is poor, requiring the addition of rotational invariance, enhancing the ability to resist noise. For a feature point, the BRIEF descriptor is formed by comparing n pairs of points, and n pairs of points (2 n points) are combined together to form a matrix B, where the matrix B is as follows:
then constructing a rotation matrix by utilizing the directions of the characteristic points, wherein the rotation matrix is in the following form:
and correcting the matrix B through rotating the matrix to ensure that the matrix B has rotation invariance, wherein the correction formula is as follows:
S θ =R θ S
and extracting rotation invariant descriptors according to the direction of the feature points, and overcoming the sensitivity of BRIEF operators to the direction.
2. Feature coarse matching
The invention utilizes Brute Force (BF) algorithm to perform rough matching of characteristic points to obtain N groups of rough matching characteristic point pairs which are marked as { F ] a ,F b }, wherein F a ={f a1 ,f a2 ,...,f aN Sum F b ={f b1 ,f b2 ,...,f bN }. The violent matching algorithm is to compare descriptors of feature points one by one in a vector space, and select a pair with smaller distance (Hamming distance is adopted in the invention) as a matching point. After violent matching, the invention uses a cross matching method to coarsely filter false matches. The idea of cross-filtering is to match once, and then to use the matched points in reverse, and if the matched point is still the first matched point, it is considered to be a correct match. For example, the first time feature point A uses a violent matching method, and the matched feature point is a feature point B; in turn, feature point B is used for matching, which is considered a correct match if it is still feature point a, or an incorrect match.
3. Feature fine matching
(1) Feature neighborhood score definition
For image matching, there are a certain number of matching feature points in adjacent areas on both images that are correctly matched, while adjacent areas on both images that are incorrectly matched are different, so the number of feature point matches in their adjacent areas is typically zero, as shown in fig. 2. Therefore, the number of the feature points with the matching relation can be counted in the neighborhood of the rough matching feature point set, and the error matching is eliminated. Therefore, the invention distinguishes between correct matching and incorrect matching by counting the number of feature points conforming to the matching relationship in the pixel region adjacent to the coarse matching point set.
Will { I }
a ,I
b The neighborhood of the set of matching feature points in } is denoted as { N }
a ,N
b N, where N
a ={N
a1 ,N
a2 ,...,N
aN },N
b ={N
b1 ,N
b2 ,...,N
bN }. For the i-th set of matching point pairs { f
ai ,f
bi Statistics of f
ai Neighborhood N
ai Feature point set { f)
a1 ,f
a2 ,...,f
aMi Sum of feature points total number M
i And counting feature point sets corresponding to the rough matching of the feature points
And the corresponding feature point sets are located at f
bi Neighborhood N
bi Number S of (3)
i . According to M
i And S is
i Setting a score threshold S for the proportional relation of (2)
T To determine the i-th matching point pair { f
ai ,f
bi Whether or not it is a correct match. Finally traversing all the matched feature point sets to remove the false matching to obtain a fine matched feature point set { F }
a ',F
b '}. For convenience of description, S will be
i Called feature neighborhood score, the calculation formula is as follows:
s in ik Representation and N ai Whether the kth feature point rough matching feature point is positioned in N bi If in the state of N bi If the number is within, the number is determined to be 1, otherwise, the number is determined to be 0.
(2) Grid feature statistics
To speed up statistics, the present invention divides an image into grid with g=p×q non-overlapping, i.e. { I } a ,I b Dividing into a set of grid blocks { a, B }, where a= { a } 1 ,a 2 ,...,a i ,...,a G },B={b 1 ,b 2 ,...,b j ,...,b G And a is i Representation I a Ith grid of (b) j Representation I b As shown in fig. 3. In order to increase robustness, the feature neighborhood score of each grid is counted, and the grid feature neighborhood scores of 8 grids adjacent to the feature neighborhood score are counted, wherein the feature neighborhood score is called a nine-grid feature neighborhood score S:
wherein S is i,j Is the j-th mesh feature score of nine Gong Gezhong where the i-th mesh is located.
To avoid the influence of inter-image rotation on statistics, for I
b Nine Gong Gejin lines above are rotated clockwise as shown in fig. 4 (a) - (c). Wherein grid G
5 The rotation does not change its position, but the adjacent grid moves clockwise, e.g. upper left grid G
1 Grid G after 1 st rotation
4 Grid G after rotation 4 th time
9 When the rotation is carried out for the 9 th time in turn, the grid characteristic distribution situation is consistent with the situation of fig. 4 (a), and the largest grid characteristic neighborhood score under the situation of 8 times of rotation is counted
In the method, in the process of the invention,
the characteristic score of the jth grid is obtained after rotating the nine grids of the ith grid k times. Then, the mean value of the number of coarse matching features of the current grid in the nine grids is counted:
wherein M is
i,j The number of rough matching feature points in the ninth Gong Gezhong jth grid where the ith grid is located is represented. When grid feature score
Greater than grid feature score threshold S
T At the time { f
ai ,f
bi And the correct match is assumed, and otherwise, the incorrect match is assumed.
Where α is the weight of the feature point number average.
4. Image registration stitching
The image registration is a technology for determining the overlapping area and the overlapping position between images to be spliced, and an image registration method based on characteristic points is adopted, namely, a transformation matrix between image sequences is constructed through matching point pairs, so that the panoramic image is spliced. According to the inter-image transformation matrix H, corresponding images can be transformed to determine overlapping areas between the images, and the images to be fused are mapped into a new blank image to form a mosaic.
If p
a =[x
a ,y
a ]
T And p
b =[x
b ,y
b ]
T Representing an image { I }
a ,I
b A pair of matching points in the sequence. N' groups of fine matching point pairs obtained by the steps
The global homography matrix H can be solved:
in the method, in the process of the invention,
and->
P is respectively
a And p
b Homogeneous coordinates H.epsilon.
3×3 。
When I
a And I
b When the camera is not rotated around the optical center to shoot, or the image background cannot approximate a plane scene, the global homography matrix H is used as a transformation model, and a ghost effect or parallax error is caused after registration. To solve this problem, the present invention calculates a homography matrix H of local dependence by adding weight coefficients
* Then to I
b Each point p of (3)
b* The transformation is performed such that the first and second parameters,
wherein H is
* Calculated from the following formula:
in the weight matrix
A∈
2N×9 Is a matrix of direct linear transformation equations, vector H is a deformation of matrix H, h= [ H ]
00 h
01 h
02 h
10 h
11 h
12 h
20 h
21 h
22 ]Weight coefficient->
Is based on the current point p
b* To I
b All feature points +.>
Is determined by the Gaussian distance of (1), set to be p
b* The closer the neighborhood, the greater the pixel weight, and relatively farThe pixel weight of (2) takes a corresponding smaller value:
where σ is the scale parameter. To prevent the weight coefficients from becoming too sparse, a default compensation value y e 0,1 is introduced.
During fusion, the overlapping area is provided with a suture, so that the suture needs to be processed, and a weighted smoothing algorithm is adopted, wherein the main idea of the algorithm is as follows: the gray value Pixel of a Pixel point in the image overlapping area is obtained by weighted average of the gray values pixel_l and pixel_r of corresponding points in two images, namely pixel=k×pixel_l+ (1-k) ×pixel_r, wherein k is an adjustable factor, and in the overlapping area, along the direction of image stitching, k is gradually changed from 1 to 0, so that smooth stitching of the overlapping area is realized.
Example two
The embodiment discloses an image stitching system, which comprises a server, wherein the server comprises a memory, a processor and a computer program stored on the memory and capable of running on the processor, and the image stitching method of the embodiment I is realized when the processor executes the program.
Example III
The present embodiment discloses a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, performs the image stitching method of the first embodiment.
While the foregoing description of the embodiments of the present invention has been presented in conjunction with the drawings, it should be understood that it is not intended to limit the scope of the invention, but rather, it is intended to cover all modifications or variations within the scope of the invention as defined by the claims of the present invention.