A kind of method and encoder of realizing video code anti-shake based on dynamic image
Technical field
The invention belongs to the computer video coding techniques, relate to the processing to computer picture, be specifically related to a kind of method and encoder based on dynamic image realization video code anti-shake, the present invention is applied to the video encoder in the hand-held picture pick-up device.
Background technology
Universal day by day along with equipment such as digital camera, Digital Video, the requirement of people's logarithmic code product also further improves.Hand-held picture pick-up device is owing to artificial shake causes rocking of image.This irritating phenomenon can be eliminated by anti-shake technology.
Present stage, the anti-shake system in digital equipment mainly was divided into two big classes: the anti-shake and electronic flutter-proof of optics.Optics is anti-shake to be by the shake of the built-in instrument induction camera of camera lens, reaches anti-shake effect by the position of adjusting lens in the camera lens.Electronic flutter-proof is to come image is handled by electronically, to alleviate the influence of shake to imaging.
The electronic flutter-proof method adopts the method for Digital Image Processing usually, avoids the use of anti-shake hardware.Since cheap, be generally used in the digital camera and Digital Video of low side.This shows that optics is anti-shake respectively to have pluses and minuses with two kinds of technology of electronic flutter-proof.The anti-shake technology of optics anti-shake effective can make full use of the collection pixel of CCD, but need the lens movement compensation arrangement, so cost is higher relatively.Electronic flutter-proof need not the lens movement compensation arrangement, and is cheap, realizes simply, still reduces the utilance of CCD.No matter be the anti-shake or electronic flutter-proof of optics, most methods all need the transducer-jitter compensation gyroscope of a motion to come the direction and the intensity of perceive motion, thereby adopt optical means and electronic method to compensate.
The data volume of digital video signal is very big, for the video sequence of a 640 * 480@30fps, if adopt the data mode of RGB24, then data transfer rate 26MB/s.Along with the increase of picture size and the raising of frame per second, data transfer rate also can be higher.High Data Rate is all had higher requirement to transmission equipment and memory device.In order to reduce data transfer rate, more efficiently transmission and stored video data, video compression technology is just arisen at the historic moment.By data compression technique, the redundant information in the removal of images had both guaranteed that picture quality satisfied actual demand, significantly reduced data volume again, reduced the burden of transmission and storage system.Present stage, video-frequency compression method commonly used had Mpeg1, Mpeg2, and Mpeg4 is H.26X with VC-1 etc.
Summary of the invention
The present invention proposes a kind of method and encoder based on dynamic image realization video code anti-shake, described method need not to add motion sensor, and obtains overall motion vector by method for estimating, is used to describe the shake of existence; By motion vector interpolation method, be formed for the motion vector based on macro block and piece of final coding based on macro block and piece.Like this, the video encoder that possesses anti-trembling function just can only pass through a motion estimation process, obtains the motion vector based on macro block and piece that is used for anti-shake global motion vector and is used for final coding simultaneously, has significantly reduced the complexity of calculating.
The method of the invention can be applicable to the video encoder in the digital camera, in the video encoder of the present invention, has integrated video compression and electronic flutter-proof two big functions, realizes anti-trembling function in data compression.The advantage of this video encoder is the jitter compensation transducer that need not to add, but has utilized motion estimation module in the existing video encoder to analyze the motion conditions of photographed, obtains global motion vector and is used for compensate for jitter; Simultaneously, the present invention by the combination of the two, has realized the anti-trembling function to coded image with motion estimation module in the video encoder and anti-shake module close-coupled, by shared motion vector, has reduced the computing cost of carrying out video compression and anti-shake realization separately.The present invention only can obtain being used for the global motion vector of compensate for jitter by estimation, obtain to be used for the piece of video coding and the motion vector of macro block by interpolation method again, saved greatly because independently moving estimates to compensate the amount of calculation of motion vector computation.
The present invention specifically is achieved in that
A kind of implementation method based on the shake of dynamic image elimination video coding comprises following processing:
(1) estimation
Present frame to input carries out pre-cut, the effective pixel area after the formation pre-cut;
Each macro block and piece to the pre-cut effective pixel area of present frame carry out estimation;
Export each macro block and piece motion vector by the motion estimation module of video encoder with respect to reference frame;
(2) anti-shake
The distribution frequency of the motion vector of statistics macro block and piece, with the highest motion vector of frequency as relative global motion vector;
Calculate absolute global motion vector, be used for the cutting effective pixel area;
According to absolute global motion vector, cutting effective pixel area again on the image size of total pixel region, compensation is because the global motion vector that shake forms;
(3) motion vector interpolation
The global motion vector that is used for compensate for jitter according to the motion vector and the present frame of macro block in the effective pixel area after the pre-cut and piece obtains the motion vector of the macro block of cutting effective pixel area again and piece behind the jitter compensation by interpolation;
(4) video coding
To the macro block that obtains effective pixel area after the cutting again by interpolation and the motion vector of piece, formation is based on data block with based on the motion vector of macro block, motion compensation and coding module with motion vector input video encoder carry out follow-up video data encoding.
In described (one) estimation,
The position of present frame pre-cut is a foundation with the absolute movement vector of reference frame;
The precision of described motion vector can be whole pixel, perhaps half-pix or 1/4 pixel.
During described (two) are anti-shake,
Described absolute global motion vector is 1 o'clock to be zero at frame number; Frame number greater than 1 o'clock be relative global motion vector and.
In described (three) motion vector interpolation,
Described interpolation adopts bilinear interpolation method, and perhaps other interpolation method is realized;
The precision of described motion vector rounds up according to the required precision of video encoder.
In described (four) video coding,
By the variance of the resulting data block motion vector computation of (three) motion vector interpolation data block global motion vector with respect to described data block motion vector;
If described variance less than given threshold values, is then selected the 1MV mode, otherwise select the 4MV mode;
If the precision of motion vector is that given threshold values is 2 when putting in order pixel;
If when the precision of motion vector was half-pix, given threshold values was 1.
In described (four) video coding,
If the position of effective pixel area is a macro block after the cutting,, then adopt intraframe coding method if there is one to be intraframe coding method in several data blocks of corresponding pre-cut effective pixel area;
If the position of effective pixel area comprises the macro block beyond the border in the pre-cut effective pixel area after the cutting, perhaps adopt the neighboring macro-blocks coded system, perhaps adopt intraframe coding method.
A kind of encoder based on dynamic image realization video code anti-shake comprises:
Motion estimation module, motion compensation and coding module, anti-shake module and motion vector interpolating module;
Described anti-shake module and motion vector interpolating module make an addition between described motion estimation module and described motion compensation and the coding module;
Described motion estimation module is used for the present frame of input is carried out pre-cut, and each macro block of the effective pixel area after the pre-cut is carried out estimation, exports macro block and the piece motion vector with respect to reference frame then;
Described anti-shake module is used to add up the distribution frequency of the motion vector of macro block and piece, with the highest motion vector of frequency as global motion vector relatively; The absolute global motion vector that calculates is used for cutting effective pixel area again on the image size of total pixel region, and compensation is because the global motion vector that shake forms;
Described motion vector interpolating module, be used for the global motion vector that motion vector and present frame according to effective pixel area macro block and piece after the pre-cut are used for compensate for jitter, carry out the motion vector that interpolation obtains the macro block of cutting effective pixel area again and piece behind the jitter compensation;
Described motion compensation and coding module, be used for the macro block that obtains effective pixel area after the cutting again by interpolation and the motion vector of piece, formation is based on data block with based on the motion vector of macro block, and the motion vector to input carries out follow-up video data encoding.
In the described motion estimation module,
The position of present frame pre-cut is a foundation with the absolute movement vector of reference frame;
The precision of described motion vector can be whole pixel, perhaps half-pix or 1/4 pixel.
In the described anti-shake module,
Described absolute global motion vector is 1 o'clock to be zero at frame number; Frame number greater than 1 o'clock be relative global motion vector and.
In the described motion vector interpolating module,
Described interpolation adopts bilinear interpolation method, and perhaps other interpolation method is realized;
The precision of described motion vector rounds up according to the required precision of video encoder.
Described motion compensation and coding module are to passing through the variance of the resulting data block motion vector computation of motion vector interpolation data block global motion vector with respect to described data block motion vector;
If the precision of motion vector is that given threshold values is 2 when putting in order pixel;
If when the precision of motion vector was half-pix, given threshold values was 1;
If described variance less than given threshold values, is then selected the 1MV mode, otherwise select the 4MV mode.
Described motion compensation and coding module,
If the position of effective pixel area is a macro block after the cutting,, then adopt intraframe coding method if there is one to be intraframe coding method in several data blocks of corresponding pre-cut effective pixel area;
If the position of effective pixel area comprises the macro block beyond the border in the pre-cut effective pixel area after the cutting, perhaps adopt the neighboring macro-blocks coded system, perhaps adopt intraframe coding method.
Existing anti-shake technology has adopted the motion sensor that adds more, the global motion that expression is extraneous.If anti-shake module and video encoding module are cut apart mutually, then need to carry out twice estimation, once be used to obtain global motion vector, carry out anti-shake compensation; Once be used for the macro block of video coding and the motion vector of piece, be used for video coding.
The present invention has and realizes simply need not external motion sensor than multiple optics of introducing previously and electronic flutter-proof method, realizes the estimation of motion, the compensation of dither image by digital image processing method fully.By with the mutually combining of video compression, only finish the calculating of the motion vector of the calculating of global motion vector of compensate for jitter and coding by motion estimation process.The invention provides the video encoder that a kind of simple, effective and cheap Digital Video has anti-trembling function, can be applied in Digital Video, the first-class multimedia equipment that possesses video encoding module of shooting.
Description of drawings
Fig. 1 is the total pixel of CCD, and valid pixel concerns schematic diagram after CCD valid pixel and the anti-shake compensation;
Fig. 2 is the video encoder structure chart that possesses anti-trembling function;
Fig. 3 is the video encoder process chart that possesses anti-trembling function;
Fig. 4 is a motion vector interpolation process schematic diagram.
Embodiment
The method that the present invention proposes makes video encoder possess anti-trembling function, is in order to solve because in the shooting process, because the image translation that the shake of hand causes shake does not relate to because the shake that rotation and convergent-divergent cause.
The present invention can not utilize the collection pixel value of whole CCD in order to realize electronic flutter-proof, and therefore effectively pixel count is less than the total pixel number of CCD, and this is the situation that realizes that electronic flutter-proof must occur.And the ratio of the relative total pixel number of valid pixel number is related by the anti-shake jitter amplitude of supporting.Suppose maximum jitter that the present invention supports by relative shifting range as index, the effective pixel area of given CCD is the center of the total pixel region of CCD, then the compensation range of Zui Da shake can not exceed the zone of the total pixel of CCD, therefore maximum compensation range in the horizontal direction is [YMAX, YMAX], maximum compensation range in vertical direction is [XMAX, XMAX].
If the shake total size is positioned at this scope, then can compensate the realization electronic flutter-proof; If surpass this scope, then do not carry out electronic flutter-proof.The total pixel of CCD, the relation of the valid pixel after CCD valid pixel and the anti-shake compensation as shown in Figure 1.Suppose that total pixel region size is M * N, the effective pixel area size after the anti-shake compensation is M ' * N ', and M '<M is then arranged, N '<N.
The structure of the video encoder that possesses anti-trembling function of the present invention as shown in Figure 2.
Whole anti-shake handling process of the present invention specifically describes as follows as shown in Figure 3;
(1) estimation
Estimation adopts the motion estimation module that video encoder had shown in Fig. 2 to carry out, and behind the input present frame, motion estimation module is exported each macro block and the piece motion vector with respect to reference frame.Here the precision of motion vector can be whole pixel, half-pix or 1/4 pixel etc., and the precision has here determined the anti-shake module of back and the operational precision of motion vector interpolating module.
The estimation of image is based on that piece and macro block carry out.Present polytype partitioned modes such as various video encoder support 16 * 8,8 * 16,8 * 8,8 * 4,4 * 8 and 4 * 4.Here be example only, have 16 * 16 macro block and 8 * 8 piece among the Mpeg4 with the motion vector encoder method among the Mpeg4.Estimation is that unit carries out with the macro block.The size of each piece is 8 * 8.Here suppose that image can be divided into the macro block of S * T individual 16 * 16, then has the data block of 2S * 2T individual 8 * 8.
In Mpeg4, the macroblock encoding mode has three classes: Intra, 1MV and 4MV.Intra is an intraframe coding method, and motion vector can be based on macro block, is commonly referred to the 1MV mode, promptly a macro block has only a motion vector, also can be expressed as 4MV, represent that a macro block has four data blocks to represent that each data block all has motion vector separately.But the present invention is not limited in the data block of these big or small types, also is applicable to the method for partition of above-mentioned multiple size.
Here need to prove,, reference frame has been carried out anti-shake compensation motion vector because the present invention has adopted anti-trembling function.Therefore adopt method for estimating to carry out motion vector when obtaining, current frame image need carry out pre-cut, forms the effective pixel area after the pre-cut.The position of present frame pre-cut is a foundation with the absolute movement vector of reference frame.Effective pixel area to the present frame of pre-cut is carried out estimation.Effective pixel area size after the pre-cut is M ' * N ', can be divided into S * T macro block.
Each above-mentioned macro block is carried out estimation.Here the global motion vector that is used for the 1st frame of compensate for jitter is 0, and then the K frame is MV with respect to the relative global motion vector of the compensate for jitter of K-1 frame
K, then the absolute global motion vector of the K frame compensate for jitter relative motion vectors of the 1st frame (perhaps with respect to) is expressed as AMV
K
(2) anti-shake
Anti-shake is to adopt the anti-shake module among Fig. 2 to carry out, and utilizes the motion vector of the data block in the current frame image to obtain the process of global motion vector exactly.
This process specifically can be divided into several steps:
After motion estimation module, formed the motion vector with respect to reference frame of a plurality of macro blocks and piece.
For unified calculating process, be the unit description motion vector with each data block of 8 * 8 here.The motion vector of each data block can be used MV
K(K represents frame number here, since 1 for i, j) expression.I, j are respectively the position of data block, and the upper left corner of image is (1,1) data block, the lower right corner be (2S, 2T).Wherein for the macro block of intraframe coding Intra mode, the motion vector here is set to 0.
The distribution frequency of the motion vector of statistics piece, with the highest motion vector of frequency as global motion vector MV relatively
K
Calculate the absolute movement vector of the overall situation, be used for the cutting effective pixel area.
According to the absolute movement vector, cutting effective pixel area again on total valid pixel image of original M * N obtains being used to compensate because the global motion vector that shake forms.Again after the cutting, the size of valid pixel image is M ' * N '.
(3) motion vector interpolation
The motion vector interpolation is to carry out in the motion vector interpolating module in Fig. 2, the global motion vector that is used for compensate for jitter according to the motion vector and the present frame of macro block in the effective pixel area after the pre-cut and piece, carry out interpolation and obtain the motion vector of the macro block of cutting effective pixel area again and piece behind the jitter compensation, the motion vector of image generates after the realization cutting, estimates and need not to carry out secondary motion.
Image has formed the effective pixel area after the cutting after having carried out anti-shake module, and the definition of the motion vector of the effective pixel area data block after the cutting and pre-cut view data block motion vector is inconsistent usually.The interpolation process of whole motion vector can be represented by Fig. 5.
The dash area macro block is represented the position by video data block definition after the jitter compensation cutting among the figure, and Block1~Block4 represents the position of the definition data block of pre-cut image, and the motion vector interpolating module is exactly that motion vector by Block1~Block4 obtains after the shake cutting motion vector of data block in the image by interpolation method.
Suppose:
The motion vector of Block1~Block4 is respectively MV
K(i, j), MV
K(i+1, j), MV
K(i, j+1), MV
K(i+1, j+1);
Behind the jitter compensation after the cutting data block motion vector in the image be expressed as MV '
K(i ', j ');
The global motion vector that present frame is used for compensate for jitter is MV
KSuppose that the global motion vector here all is to put in order pixel.
Be that example is described MV ' with bilinear interpolation method below
KThe acquisition of (i ', j ').Here method is not limited only to bilinear interpolation method, and other interpolation method is suitable equally.Here the size of data block is assumed to 8 * 8.
Can be for the motion vector of (i ', the j ') position in the effective pixel area after the compensate for jitter by (i, j), (i+1, j), (i, j+1), (i+1, j+1) motion vector of four of the position data blocks is realized by interpolation in the pre-cut image.
For (i, j), (i+1, j), (i, j+1), (i+1, j+1) does not calculate here the position that surmounts image boundary, can handle in the video encoding module of back.(i ', j ') position and MV
KDetermined jointly (i, j) position, (i ', j ') and (i, j) pass of the two is:
i′=MV
K.X/8+i
j′=MV
K.Y/8+j
Wherein ,/for dividing exactly operation, MV
K.X and MV
K.Y be respectively global motion vector in the horizontal direction with the component of vertical direction.Here adopt bilinear interpolation method, the image that obtains image after the anti-shake cutting (i ', j ') position with respect to the pre-cut image (i, j) deviation of the level of position and vertical direction is respectively:
dx=Mod(MV
K.X,8)
dy=Mod(MV
K.Y,8)
Mod (x, a) remainder that obtains of function representation x mould a wherein.The motion vector of (i ', the j ') position that therefore has in the effective pixel area after compensate for jitter the can be expressed as:
MV′
K(i′,j′).X=((8-dx)(8-dy)MV
K(i,j).X+dx(8-dy)MV
K(i+1,j).X+
(8-dx)dyMV
K(i,j+1).X+dxdyMV
K(i+1,j+1).X)/64
MV′(i′,j′)
K.Y=((8-dx)(8-dy)MV
K(i,j).Y+dx(8-dy)MV
K(i+1,j).Y+
(8-dx)dyMV
K(i,j+1).Y+dxdyMV
K(i+1,j+1).Y)/64
For any one data block in the effective pixel area in the image after the jitter compensation cutting, as long as (i, j), (i+1, j), (i, j+1), (i+1 j+1) does not surmount the position of pre-cut image boundary, just can access the motion vector of data block after the corresponding interpolation.
Here the precision of motion vector rounds up according to the required precision of video encoder.
Simultaneously as can be seen, when adopting half-pixel accuracy, the modulus 8 during dx and dy find the solution should be 16; Coefficient in the interpolation formula also should change 16 to 8 into, and divisor is 256 simultaneously.Other precision by that analogy.
(4) video coding
By having obtained after the motion vector interpolation after the cutting in the effective pixel area behind the motion vector with respect to reference frame of each data block, just can carry out video coding.Described video coding is to realize in motion compensation shown in Figure 2 and coding module.
Cataloged procedure comprises following process:
To carry out the coded system analysis based on the motion vector of data block, form based on data block with based on the motion vector of macro block.Each data block of image is handled according to following principle after the corresponding cutting:
If the (i, j) data block of position is a macro block, if there is one to be intraframe coding method in several data blocks of corresponding pre-cut effective pixel area, then should (i, j) data block of position be an intraframe coding method.
By the resulting data block motion vector of (three) motion vector interpolation MV '
K(i ', j '), the global motion vector MV of four data blocks of calculating
KWith respect to the variance of this value, promptly
If given threshold values T has
D
K' (i ', j ')<T, then select the 1MV mode, otherwise select the 4MV mode.Here the representative value of T can be selected.
When being is T=2 when putting in order pixel, when for half-pix T=1.T can select voluntarily according to user's designing requirement.
If the (i, j) macro block of position comprises pre-cut effective pixel area border macro block in addition, because there is not the motion vector of this macro block, can adopt two kinds of methods to handle: one is directly to adopt the neighboring macro-blocks coded system; Another is to adopt intraframe coding method.
Motion compensation and coding module with motion vector input video encoder carry out follow-up video data encoding.