Disclosure of Invention
The embodiment of the invention provides a motion estimation method and device based on pixels, and aims to solve the problems that the existing method needs intensive operation and is low in processing efficiency.
In a first aspect, an embodiment of the present invention provides a pixel-based motion estimation method, including: generating an initial cost map of the input image relative to the reference image under each candidate vector; generating a candidate cost graph according to the initial cost graph; and selecting a candidate vector with the minimum cost for the pixel of the input image according to the candidate cost map as the motion vector of the pixel.
With reference to the first aspect, in a first possible implementation manner of the first aspect, the generating an initial cost map of the input image relative to the reference image under each candidate vector includes: and generating an initial cost map of the input image relative to the reference image under each candidate vector by adopting a mode of calculating the sum of the absolute pixel difference and the absolute gradient difference of the corresponding pixel.
With reference to the first aspect or the first possible implementation manner of the first aspect, in a second possible implementation manner of the first aspect, the generating a candidate cost map according to the initial cost map includes: smoothing each initial cost map to obtain a smooth cost map; and determining a candidate cost map according to the smooth cost map.
With reference to the second possible implementation manner of the first aspect, in a third possible implementation manner of the first aspect, the smoothing of each initial cost map to obtain a smoothed cost map includes: calculating a linear relation between each initial cost map and the input image; and smoothing each initial cost graph according to the linear relation to obtain a smooth cost graph.
With reference to the third possible implementation manner of the first aspect, in a fourth possible implementation manner of the first aspect, before the calculating a linear relationship between each of the initial cost maps and the input image, the method further includes: downsampling each initial cost map to generate a sampling cost map; down-sampling the input image to generate a sampled image; the calculating a linear relationship between each of the initial cost maps and the input image includes: calculating the linear relationship between each of the sampled cost maps and the sampled image.
With reference to the fourth possible implementation manner of the first aspect, in a fifth possible implementation manner of the first aspect, the obtaining a linear relationship between each of the sampling cost maps and the sampling image includes calculating a linear relationship between each of the sampling cost maps and the sampling image by using a linear regression method.
With reference to the fourth possible implementation manner of the first aspect or the fifth possible implementation manner of the first aspect, in a sixth possible implementation manner of the first aspect, the downsampling each initial cost map to generate a sampling cost map further includes: performing mean filtering on each initial cost graph; the downsampling each initial cost map to generate a sampling cost map comprises: and downsampling each initial cost map subjected to mean filtering to generate a sampling cost map.
With reference to the fourth possible implementation manner of the first aspect, the fifth possible implementation manner of the first aspect, or the sixth possible implementation manner of the first aspect, in a seventh possible implementation manner of the first aspect, before the downsampling the input image to generate a sampled image, the method further includes: performing mean filtering on the input image; the downsampling the input image to generate a sampled image comprises: and downsampling the input image after the average filtering to generate a sampling image.
With reference to the fourth possible implementation manner of the first aspect, the fifth possible implementation manner of the first aspect, the sixth possible implementation manner of the first aspect, or the seventh possible implementation manner of the first aspect, in an eighth possible implementation manner of the first aspect, the determining a candidate cost map according to the smooth cost map includes: taking the smoothed cost map as the candidate cost map; or selecting a preselected vector with the minimum cost according to the sampling cost map; and modifying each smooth cost map by using the preselected vector to obtain the candidate cost map.
On the other hand, an embodiment of the present invention further provides a pixel-based motion estimation apparatus, including: a generating unit, configured to generate an initial cost map of the input image relative to the reference image under each candidate vector; a candidate unit, configured to generate a candidate cost map according to the initial cost map generated by the generating unit; and the selecting unit is used for selecting a candidate vector with the minimum cost for the pixel of the input image according to the candidate cost map generated by the candidate unit as the motion vector of the pixel.
With reference to the second aspect, in a first possible implementation manner of the second aspect, the generating unit is configured to generate an initial cost map of the input image relative to the reference image at each candidate vector by calculating a sum of a pixel absolute difference and a gradient absolute difference of a corresponding pixel.
With reference to the second aspect or the first possible implementation manner of the second aspect, in a second possible implementation manner of the second aspect, the candidate unit includes: a smoothing subunit, configured to smooth each initial cost map to obtain a smoothed cost map; and the determining subunit is used for determining the candidate cost map according to the smooth cost map.
With reference to the second possible implementation manner of the second aspect, in a third possible implementation manner of the second aspect, the smoothing subunit includes: a relation calculating subunit, configured to calculate a linear relation between each of the initial cost maps and the input image; and the linear smoothing subunit is used for smoothing each initial cost map according to the linear relationship calculated by the relationship calculation subunit to obtain a smooth cost map.
With reference to the third possible implementation manner of the second aspect, in a fourth possible implementation manner of the second aspect, the smoothing subunit further includes: the first downsampling subunit is used for downsampling each initial cost map to generate a sampling cost map; a second downsampling subunit, configured to downsample the input image to generate a sampled image; the relation calculating subunit is configured to calculate the linear relation between each of the sampling cost maps generated by the first downsampling subunit and the sampling image generated by the second downsampling subunit.
With reference to the fourth possible implementation manner of the second aspect, in a fifth possible implementation manner of the second aspect, the relationship calculating subunit is configured to calculate, by using a linear regression method, a linear relationship between each of the sampling cost maps generated by the first downsampling subunit and the sampling image generated by the second downsampling subunit.
With reference to the fourth possible implementation manner of the second aspect or the fifth possible implementation manner of the second aspect, in a sixth possible implementation manner of the second aspect, the smoothing subunit further includes: the first filtering subunit is configured to perform mean filtering on each initial cost map; the first downsampling subunit is configured to downsample each initial cost map subjected to the average filtering by the first filtering subunit to generate a sampling cost map.
With reference to the fourth possible implementation manner of the second aspect, the fifth possible implementation manner of the second aspect, or the sixth possible implementation manner of the second aspect, in a seventh possible implementation manner of the second aspect, the smoothing subunit further includes: the second filtering subunit is used for performing mean value filtering on the input image; and the second downsampling subunit is configured to downsample the input image subjected to the average filtering by the second filtering subunit to generate a sampled image.
With reference to the fourth possible implementation manner of the second aspect, the fifth possible implementation manner of the second aspect, the sixth possible implementation manner of the second aspect, or the seventh possible implementation manner of the second aspect, in an eighth possible implementation manner of the second aspect, the selecting unit is configured to use the smooth cost map as the candidate cost map; or selecting a preselected vector with the minimum cost according to the sampling cost map; and modifying each smooth cost map by using the preselected vector to obtain the candidate cost map.
In the embodiment of the invention, an initial cost map of an input image relative to a reference image under each candidate vector is generated; generating a candidate cost graph according to the initial cost graph; and selecting a candidate vector with the minimum cost for the pixel of the input image according to the candidate cost map as the motion vector of the pixel. By applying the embodiment of the invention, the motion estimation based on the pixel is carried out, the motion vector based on the pixel is obtained, the dense operation such as interpolation or iteration is not needed, and the processing efficiency is relatively high.
Detailed Description
The technical solutions in the embodiments of the present invention will be described clearly and completely with reference to the accompanying drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a flow chart of an embodiment of the pixel-based motion estimation method of the present invention is shown. This embodiment comprises the steps of:
step 101, generating an initial cost map of the input image relative to the reference image under each candidate vector.
In order to accelerate the processing speed and keep the consistency of the final result, N vectors can be selected in advance as candidate vectors when the motion estimation based on the pixels is carried out, wherein N is more than or equal to 2; then, one candidate vector with the minimum cost is selected from the N candidate vectors for each pixel of the input image to serve as the motion vector of the pixel. In this case, the motion estimation process is a process of selecting a motion vector for each pixel from the candidate vectors. The candidate vectors may be selected in a variety of ways, for example, motion vectors of pixels of a processed image may be used as the candidate vectors, wherein the processed image may be an image in the same image sequence as the input image.
When selecting a motion vector, an initial cost map of the input image relative to the reference image under each candidate vector needs to be calculated first. The initial cost map consists of the cost of each pixel in the input image relative to the corresponding pixel in the reference image under the candidate vector. If N candidate vectors exist, N initial cost graphs can be obtained, and the N candidate vectors correspond to the N initial cost graphs one by one.
And 102, generating a candidate cost map according to the initial cost map.
After the initial cost maps are obtained, a smooth cost map corresponding to each initial cost map can be generated firstly; and then determining a candidate cost map corresponding to each initial cost map according to the smooth cost map. If N initial cost graphs exist, N smooth cost graphs can be correspondingly generated, and the N candidate cost graphs correspond to the N initial cost graphs one by one.
A direct smoothing mode can be adopted when generating the smooth cost graph. Specifically, the initial cost map may be smoothed according to a linear relationship between the initial cost map and the input image, so as to obtain a smoothed cost map. The initial cost graph is smoothed, so that the selection of the motion vector can be more accurate, and better consistency is achieved. The linear relation between the initial cost map and the input image can be calculated by adopting a linear regression method.
A first sampling and then smoothing mode can be adopted when generating the smooth cost map. Specifically, the initial cost map may be downsampled to obtain a sampling cost map, and the input image may be downsampled to obtain a sampling image; and then smoothing the sampling cost graph according to the linear relation between the sampling cost graph and the sampling image to generate a smooth cost graph. And the initial cost graph and the input image are downsampled, so that the calculation complexity can be reduced on the premise of ensuring the accuracy of motion vector selection. The linear relation between the sampling cost graph and the sampling image can also be calculated by adopting a linear regression method.
Before sampling the initial cost graph, mean value filtering can be performed on the initial cost graph; similarly, before sampling the input image, the input image may be subjected to mean filtering. The initial cost graph and the input image are subjected to mean filtering, and then sampling is performed, so that the robustness of the processing process can be increased, and the influence of image noise is reduced.
There are also various ways to determine the candidate cost map from the smoothed cost map. For example, after the smooth cost map is obtained, the smooth cost map may be directly used as a candidate cost map; or, a preselected vector may be selected for each pixel according to the initial cost map, then the smooth cost map is modified by using the preselected vector, and the modified smooth cost map is used as a candidate cost map, so as to improve the probability of selecting the preselected vector.
When the initial cost maps are N, each initial cost map can be smoothed by the method described above.
And 103, selecting a candidate vector with the minimum cost for the pixel of the input image according to the candidate cost map as the motion vector of the pixel.
From the foregoing process of obtaining the candidate cost map, according to N candidate cost maps corresponding to N candidate vectors, the cost of the pixel j under each candidate vector can be known relative to the pixel mi + j, where the pixel j is a pixel in the input image, and the pixel mi + j is a pixel in the reference image corresponding to the pixel j; so that for each pixel in the input image I a least costly candidate vector can be selected as the motion vector. When selecting a motion vector for each pixel, the selection process may be based on the Winner Take All (WTA) rule, and the detailed selection process is not described herein again.
In the embodiment of the invention, an initial cost map of an input image relative to a reference image under each candidate vector is generated; generating a candidate cost graph according to the initial cost graph; and selecting a candidate vector with the minimum cost for the pixel of the input image according to the candidate cost map as the motion vector of the pixel. By applying the embodiment, the motion estimation based on the pixel is carried out, the motion vector based on the pixel is obtained, the intensive operation is not needed, and the processing efficiency is relatively high.
Referring to fig. 2, a flow chart of another embodiment of the pixel-based motion estimation method of the present invention is shown, which illustrates the pixel-based motion estimation method of the present invention in detail.
Step 201, an initial cost map of the input image relative to the reference image under each candidate vector is generated by adopting a mode of calculating the sum of the absolute difference of the pixel of the corresponding pixel and the absolute difference of the gradient.
For convenience of description, the input image may be denoted as I, the reference image may be denoted as R, the candidate vector may be denoted as I, and the initial cost map may be denoted as C. The pixel of the input image I may be denoted as j, the pixel corresponding to the pixel j in the reference image R may be denoted as mi + j, and the initial cost map of the input image I relative to the reference image R under the candidate vector I may be denoted as Ci. The initial cost for a pixel j in the input image I under the candidate vector I may be referred to as the initial cost for the pixel j for short, relative to the pixel mi + j in the reference image R corresponding to the pixel j.
Initial cost graph CiMay be constituted by the cost of each pixel in the input image I. The initial cost for pixel j can be calculated as the pixel absolute difference of pixel j and pixel mi + j and the gradient absolute difference of pixel j and pixel mi + j. Initial cost C of pixel j under candidate vector ii,j=|Ij-Rmi+j|+|Dj-Dmi+jI, wherein Ij-Rmi+j| is the absolute difference between pixel j and pixel mi + j, | Dj-Dmi+jAnd | is the absolute difference of the gradient of the pixel j and the pixel mi + j. Since each pixel can be represented by the coordinate value of the pixel in the image, the pixel absolute difference between the pixel j and the pixel mi + j can be calculated according to the coordinate value of the pixel j and the coordinate value of the pixel mi + j, and the gradient absolute difference between the pixel j and the pixel mi + j can be calculated by using the gradient value of the pixel j and the gradient value of the pixel mi + j, and the specific calculation process is not repeated here.
When there are multiple candidate vectors, the above method may be adopted to obtain the initial cost map corresponding to each candidate vector. The sum of the absolute difference of the pixels and the absolute difference of the gradient is adopted to calculate the cost of each pixel, the calculation process is simple, and the edge characteristics of the input image can be kept in the cost map.
And 202, performing mean filtering on each initial cost map.
The mean filtering is a typical linear filtering algorithm, and refers to setting a filtering template for a target pixel on an image, where the filtering template includes neighboring pixels around the target pixel, for example, 8 surrounding pixels centered on the target pixel, to form a filtering template; the average value of all pixels in the template is used to replace the original pixel value, and the average value and the pixel value can be color value, gray value, etc. There are many specific implementation methods for the mean filtering, and the detailed description thereof is omitted here. And performing mean filtering on the initial cost graph to reduce the influence of image noise on the motion vector selection result.
And 203, down-sampling each initial cost map after mean filtering to obtain a sampling cost map.
To reduce the complexity of the calculation process, the mean filtered initial cost map may be downsampled. The down-sampling ratio can be set as desired. For example, the initial cost map may be sampled four times horizontally and three times vertically. And if N initial cost graphs exist, respectively downsampling each initial cost graph to generate a sampling cost graph corresponding to each initial cost graph.
And 204, performing mean filtering on the input image.
And the mean value filtering is carried out on the input image, so that the influence of noise on the motion vector selection result can be reduced.
And step 205, down-sampling the input image after the average filtering to obtain a sampling image.
In order to reduce the complexity of the calculation process, the average-filtered input image can be downsampled. The down-sampling may be in the same scale as the down-sampling of the initial cost map.
It should be noted that, step 202 to step 203 may be executed first, and then step 204 to step 205 may be executed; step 204 to step 205 may be executed first, and then step 202 to step 203 may be executed, which is not limited to the present invention.
Step 206, calculating the linear relation between each sampling cost map and the sampling image;
and the linear relation between the sampling cost graph and the sampling image is formed by the linear relation between each pixel in the sampling image and the cost corresponding to the pixel in the sampling cost graph. The linear relationship between the pixel and the cost corresponding to the pixel can be calculated according to the pixel brightness and the cost corresponding to the pixel. When there are N sampling cost maps, a linear regression method can be adopted to obtain the linear relationship between each sampling cost map and the sampling image one by one.
The linear relationship between the pixel in the sampling image and the cost corresponding to the pixel in the sampling cost image is determined by the linear relationship coefficient between the pixel in the sampling image and the cost corresponding to the pixel in the sampling cost image, and the linear relationship between the pixel in the sampling image and the cost can be determined as long as the linear relationship coefficient between the pixel in the sampling image and the cost is obtained. When calculating the linear relation coefficient of a certain pixel, firstly, a local image window is set on the sampling image for the pixel, and the local image window comprises the pixel. The size of the partial image can be set according to requirements. For example, 13 × 13 image blocks may be used as local image windows. The calculation process may include the steps of: calculating the average brightness of each pixel in the local image windowAnd the standard deviation of the luminance var (I 'I'), whereinCalculating the average cost value of the pixels in the local image window under the candidate vector iAnd covariance cov of pixel cost values in local image windows (C)i'I'), whereinAccording to the average brightnessStandard deviation of luminance var (I 'I'), average cost valueAnd covariance of cost cov (C)i'I'), the pixel can be calculated to calculate the linear relation coefficient. The coefficient of the linear relationship includes a slope aiAnd intercept biWhereinas shown in the foregoing formula, the standard deviation and covariance can be calculated by using the mean of the local image window. The computational complexity can be made independent of the window size using techniques such as integral mapping. There are various methods for calculating the linear relation coefficient, and they will not be described in detail here.
If there are N sampling cost maps, the linear relationship between each sampling cost map and the input image can be obtained by the method, so as to obtain N linear relationships corresponding to the N sampling cost maps one to one. The linear relation between the brightness of the down-sampling image and the sampling cost graph is calculated by adopting a linear regression method, and only one-time scanning can be performed, so that the operation complexity is reduced.
And step 207, smoothing each initial cost map according to the linear relation to obtain a smooth cost map.
After the linear relationship between the sampling cost map and the sampling image is obtained, the sampling cost map can be smoothed according to the linear relationship. And a sampling cost map Ci' the corresponding smoothed cost map can be denoted as Ci". For sampling cost graph Ci' smoothing may be performed by applying a sample cost map CiThe cost of each pixel included in' is smoothly achieved. For example, under the candidate vector I, a pixel j in the input image I corresponds to a pixel j in the sample image corresponding to the input imageThe cost of the pixel j after smoothing can be recorded as C "ikKnown as C "ik=aik*Ij+bikWherein a isikIs the slope corresponding to pixel j, bikIs the intercept corresponding to pixel j, IjIs the luminance of pixel j.
And 208, selecting a preselected vector with the minimum cost according to the sampling cost map.
After each initial cost map is downsampled to obtain a sampling cost map, a motion vector with the minimum cost can be preselected for each pixel according to the sampling cost map to serve as a preselected vector. When selecting the preselected vector for each pixel, the selection process may be based on the Winner Take All (WTA) rule, and the detailed selection process is not described herein.
And 209, modifying each smooth cost map by using the preselected vector to generate a candidate cost map.
After the preselected vector is obtained, the smooth cost map can be corrected according to the preselected vector to generate a candidate cost map, and the probability of selecting the preselected vector is improved. For example, if the pre-selected vector for pixel k in the sample image corresponding to pixel j in the input image I is t. Smooth cost graph C corresponding to preselected vector tt"where the cost corresponding to pixel k can be represented as Ctk", then C may be substitutedtk"is multiplied by a coefficient less than 1, thereby increasing the probability that the motion vector t becomes the least costly candidate vector for pixel j in the input image I. Preselecting the vector as a reference for vector selection improves the consistency of motion vectors in input images with sparse texture or high noise.
And step 210, selecting a candidate vector with the minimum cost for the pixel of the input image according to the candidate cost map as the motion vector of the pixel.
After the candidate cost map is acquired, a motion vector with the minimum cost is selected for each pixel according to the WTA rule.
It should be noted that, after step 207 is executed, step 210 may be directly executed, that is, after the smooth cost map is obtained, the smooth cost map may not be modified, and the smooth cost map is directly used as a candidate cost map; a least costly motion vector is then selected for each pixel. The smooth cost graph is directly used as a candidate cost graph, so that the processing process can be simplified, and the data calculation amount can be reduced.
It can be seen from the above embodiments that, when the embodiments are applied to the pixel-based motion estimation, the calculation is simple, the processing efficiency is relatively high, and the embodiments are suitable for being implemented by using hardware, and the motion vectors can be accurately selected, so that the selected motion vectors have relatively good consistency and relatively good robustness.
Corresponding to the pixel-based motion estimation method, the invention also provides a pixel-based motion estimation device.
Referring to fig. 3, a block diagram of an embodiment of the apparatus for estimating motion based on pixels according to the present invention is shown.
The device includes: a generating unit 301, a candidate unit 302, and a selecting unit 303.
Wherein the generating unit 301 is configured to generate an initial cost map of the input image relative to the reference image under each candidate vector.
The specific way in which the generating unit 301 generates the initial cost map of the input image with respect to the reference image under each candidate vector may be various. For example, the generating unit 301 may be configured to generate an initial cost map of the input image relative to the reference image at each candidate vector in a manner of calculating a sum of a pixel absolute difference and a gradient absolute difference of a corresponding pixel. The specific generation process is not described herein.
The candidate unit 302 is configured to generate a candidate cost map according to the initial cost map generated by the generating unit 301.
After the generating unit 301 generates the initial cost maps, the candidate unit 302 may first generate a smooth cost map corresponding to each initial cost map; and then determining a candidate cost map corresponding to each initial cost map according to the smooth cost map.
As shown in fig. 4, the candidate unit 302 may include: a smoothing subunit 401 and a determination subunit 402. The smoothing subunit 401 is configured to smooth each of the initial cost maps to obtain a smoothed cost map; the determining subunit 402 is configured to determine a candidate cost map from the smoothed cost map.
As shown in fig. 5A, the smoothing subunit 401 may include: a relation calculation subunit 501 and a linear smoothing subunit 502. The relationship calculation subunit 501 is configured to calculate a linear relationship between each initial cost map and the input image; the linear smoothing subunit 502 is configured to smooth each initial cost map according to the linear relationship calculated by the calculation subunit 501 to obtain a smooth cost map.
To reduce the amount of data calculation and increase the processing speed, as shown in fig. 5B, the smoothing subunit 401 may further include: a first downsampling subunit 503 and a second downsampling subunit 504. The first down-sampling subunit 503 is configured to down-sample each initial cost map to generate a sampling cost map; a second downsampling subunit 504, configured to downsample the input image to generate a sampled image. When the smoothing sub-unit 401 includes the first downsampling sub-unit 503 and the second downsampling sub-unit 504, the relation calculating sub-unit 501 may be configured to calculate the linear relation between each of the sampling cost maps generated by the first downsampling sub-unit 503 and the sampling image generated by the second downsampling sub-unit 504.
To reduce the influence of noise points in the image, as shown in fig. 5C, the smoothing subunit 401 may further include: a first filtering subunit 505 and a second filtering subunit 506. The first filtering subunit 505 is configured to perform mean filtering on each initial cost map; a second filtering subunit 506, configured to perform mean filtering on the input image. When the smoothing sub-unit includes the first filtering sub-unit 505, the first downsampling sub-unit 503 may be configured to downsample each of the initial cost maps after mean filtering by the first filtering sub-unit 505 to generate a sampling cost map. When the smoothing sub-unit comprises a second filtering sub-unit 506, the second downsampling sub-unit 504 may be configured to downsample the input image mean-filtered by the second filtering sub-unit 506 to generate a sampled image.
If the smoothing subunit 401 includes the first lower sampling subunit 503, the determining subunit 402 may be configured to select a preselected vector with a minimum cost according to the sampling cost map generated by the first lower sampling subunit 503; and then modifying each smooth cost map by using the preselected vector to obtain the candidate cost map.
The selecting unit 303 is configured to select, as the motion vector of the pixel, a candidate vector with the smallest cost for the pixel of the input image according to the candidate cost map generated by the candidate unit 302.
As can be seen from the foregoing embodiments, the pixel-based motion estimation apparatus provided in this embodiment is used to perform pixel-based motion estimation and obtain a pixel-based motion vector, and therefore, intensive operations are not required, and the processing efficiency is relatively high. Because the calculation process is simple, interpolation or repeated scanning is not needed, and the method is suitable for hardware implementation.
Those skilled in the art will readily appreciate that the techniques of the embodiments of the present invention may be implemented as software plus a required general purpose hardware platform. Based on such understanding, the technical solutions in the embodiments of the present invention may be essentially or partially implemented in the form of a software product, which may be stored in a storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the embodiments or some parts of the embodiments.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above-described embodiments of the present invention do not limit the scope of the present invention. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.