Embodiment
The present invention is based on the error concealing method that camera lens cuts apart and can be generalized into following basic step:
1, decoding n frame.
2, detect the n frame and whether make a mistake, change 3 if make a mistake, otherwise change 5.
Whether 3, detect the n frame is the border of a camera lens.
If 4 n frames are not the borders of a camera lens, carry out time domain error and hide.If shot boundary carries out the spatial domain error concealing.
If 5 n frames are last frames, withdraw from, otherwise n=n+1 changes 1.
Specifically introduce wrong discovery mechanism and the spatial domain error concealing and the time domain error hidden method that are adopted below respectively, provide the quick camera lens dividing method of compression domain again, camera lens dividing method and spatial domain error concealing, time domain error are hidden combined at last.When specific implementation method is discussed, be the example introduction with the video flowing of Moving Picture Experts Group-2, but the inventive method is not limited in Moving Picture Experts Group-2, is equally applicable to MPEG-1/4 standard or other video encoding standard.
1, mistake discovery mechanism
In order to carry out hiding error, the most important thing is correctly to locate the wrong position that occurs.If can not accurately locate wrong position, just error concealing can not be carried out.Mistake of the present invention finds mainly to have used two kinds of methods:
(1) checks the pixel value of macroblock boundaries and the difference of macroblock boundaries pixel value around it
When playing, producing " mosaic " phenomenon when occurring wrong in the video flowing, by intuitively can feel to occur the macro block of mistake and on every side macro block tangible difference is arranged.Here utilized just error macro block and on every side the difference of macro block in colourity, brightness find the position of erroneous macroblock.According to the coded system of MPEG-2, adopted the VLC coding for macro block, when certain macro block makes a mistake, tend to have influence on follow-up macro block in this sheet (slice), up to the arrival of next sheet.Be can not surmount delegation because of a sheet again, so the mistake that this macro block brings at most only can influence the one's own profession macro block.
By last surface analysis, can know: in the macro block around the erroneous macroblock, about macro block tend to be affected, and its up and down macro block generally can not be affected the therefore coboundary of a computing macro block and difference and the lower boundary of macro block and the difference of macro block coboundary, below of top macro block lower boundary here.By to the calculating of many frames with relatively find in three components of color YUV (wherein, the brightness of Y representation in components, U represents blue and green aberration, the aberration that the V representation in components is red with green), the difference of U component value is the most significant, therefore selects the difference of U component as macro block and the differentiation of macro block difference size on every side in the method.Choosing small number of pixels value participation calculating is in order to reduce the complexity of algorithm.
The pixel value that select to calculate the pixel value of current macro coboundary and top macro block lower boundary in the method the pixel value of the difference on the U component and this macro block lower boundary and below the difference of pixel on the U component of macro block coboundary simultaneously as judgment condition, when this two differences during, can judge that mistake has taken place this macro block simultaneously greater than threshold value (threshold range is 25~35 in this method).
(2) when detected code value is not in code table, illustrates mistake has taken place in the code stream
Because used VLC code table is not completely in the mpeg standard, therefore when code stream makes a mistake, the mutilation long code word (VLC) that occurs the motion vector of a macro block or discrete cosine transform (DCT) coefficient probably can be concluded when this situation occurs mistake has taken place in code stream not in the VLC code table.But often can not accurately locate wrong position in this way, because when a code word does not occur in the VLC code table, may not be that mistake has appearred in this code word, but mistake has just appearred in the code word of front in this sheet, just code word causes just finding over time mistake owing to having the bit mistake to become the another one code word and having changed the error propagation that the length of code word causes.But,, just can conclude the transmission mistake has taken place in this sheet that therefore in the hiding error that this method realizes, when this thing happens, we will be hidden to whole implementation mistake in case this situation occurs.
2, error concealing on the spatial domain
The error hidding method that error concealing has adopted block-based cutting apart on the spatial domain-mated on the spatial domain, following algorithm 1 is the method for a macro block being carried out error concealing:
Algorithm 1, concrete steps are as follows:
(1) position of the macro block of alignment error;
(2) judge " error macro block directly over adjacent macroblocks and under adjacent macroblocks " whether can use; If unavailable, find the nearest macro block that can be used for error concealing;
(3) similarity in the zone in zone and the available macroblock is calculated in the error macro block;
(4) finish and cut apart-matching process;
(5) calculate in the 4th step cut apart-whether two used zones of matching process are similar areas; If not, change (3), if change (6);
(6) finish error concealing;
(7) error concealing has been carried out in each zone of judging current error macro block; If not, change (3); If withdraw from.
Below that interpretation algorithms 1 is related ins and outs.
The zone similarity is estimated:
In the method, size is the adjacent block B of bx * by
TAnd B
BBetween the average of absolute error estimate by following formula:
When MAD value during, or when in specifying the region of search, having found a minimum MAD, carry out hiding error with two match block at this moment less than a predetermined threshold value.
Cut apart-matching process
Cut apart-4 steps of matching process are as shown in Figure 1.Wherein MBc indicates by the macro block of hiding error, MB
T, MB
TL, MB
TR, MB
B, MB
BL, MB
BRTop, upper left side, upper right side, below, lower left, the bottom-right macro block that obtains of macro block decreased in expression respectively.
In preceding 2 steps, defined bigger adjacent block and mated, and in the end all used the piece of minimum dimension 4 * 4 to mate in 2 steps, but defined different regions of search.Adopt this method to guarantee minimum processing time and concealment effect as well as possible.Process begin guaranteed that with relatively large the coupling bigger conforming zone can have been avoided more calculating and delay by direct reconstruct.On the other hand, there is the zone of more details to need littler piece to mate.Introduce 4 steps below in detail:
(1) the piece size of initial matching-maximum
Initial matching attempts to mate largest block b adjacent on the vertical direction
1And t
1, it is of a size of 16 * 8 pixels.As shown in Figure 1a.If these two zones are considered to similar, the hiding error of whole macro block can be realized by copying.Otherwise algorithm continued to carry out (2) step.
(2) cut apart first-in the vertical direction only
Original block in (1) step is divided into two littler pieces, is respectively b
1, b
2And t
1, t
2, its size is 8 * 8.Only in the vertical direction is that each is to mating.As b
1With t
1And b
2With t
2(seeing Fig. 1 (b)).Therefore there is the hiding quilt of less texture region directly to carry out.
(3) set of secondary splitting-definition initial search area-less direction
In (2) step, piece further is divided into the size 4 * 4 of the minimum that is allowed, and uses b
iAnd t
iRepresent.In this step, shown in Fig. 1 (c), defined the initial search area on the horizontal direction, the smallest blocks (b that will be mated
iAnd t
i) in the region of search of definition, slide.Whether all their combinations are the decision-makings of optimum Match with the similarity algorithm for estimating that the front was introduced all.This step is carried out by iteration, realizes up to the hiding error that similarity coupling or whole macro block are no longer satisfied in next optimical block combination.The notion of sliding has guaranteed that the border of any direction or lines can be by reconstruct.
(4) do not cut apart-increase region of search-more multi-direction set
The region of search of definition is further increased in (3) step shown in Fig. 1 (d).Allow the direction of reconstruct to expand to adjacent upper left side, upper right side or lower left, bottom-right macro block, therefore enlarged the direction of reconstruct.In this step, the size of the piece that is used for mating remains unchanged, shown in Fig. 1 (d).Coupling is at b
k, t
kBetween carry out.This step also is that iteration is carried out, and has all carried out hiding error up to whole macro block.
Error concealing
In the error hidding method of this method, adopted the method for copy.As shown in Figure 1, the picture material of the adjacent best matching blocks in above and below is copied into the first half and the latter half of lost regions respectively by matching direction.(for example, in Fig. 1 a, if b
1And t
1In the first step, be considered to mate, then b
1Content be copied into the zone of equal sizes in erroneous macroblock the first half, the i.e. more shallow zone of color among the figure; t
1Be copied into the zone of equal sizes in the latter half of erroneous macroblock, i.e. the darker zone of color among the figure).Cutting apart-preceding two steps of matching process in, hiding error is directly carried out and is not needed iterative process, and needs iterative process in latter two steps, and hiding error is carried out in the zone of also not carrying out hiding error in back.Therefore in algorithm for each pixel in the macro block is provided with a sign, be used to refer to this pixel and whether carried out hiding error.If pixel has been carried out hiding error, when occurring on his the direction, do not need again he to be carried out hiding error in next optimum Match.
3, the error concealing on the time domain
Compare with the hiding error on the spatial domain, less or not have the zone of motion in motion, the hiding error on the time domain can be obtained intimate perfect effect.Around the macro block that makes a mistake the motion vector of macro block inconsistent or since around it macro block be intraframe coding and can't obtain their movable information the time, simple block matching method can't obtain gratifying result, and the forward direction-back on the time domain in this method can reduce these shortcomings to piece matching error concealment method.This method is that erroneous macroblock has been selected neighborhood, based on the piece coupling in principle, can carry out possible best concealment to erroneous macroblock in this neighborhood.
The redundancy of forward direction-back on the time domain on the hidden time domain of utilizing video sequence of piece matching error.Here suppose that at least some adjacent pieces have level and smooth, consistent motion vector.Introduce this algorithm below in detail.
MB
CBe the current macro block that makes a mistake, MB
TBe the macro block of erroneous macroblock top, MB
BMacro block for the erroneous macroblock below.Be the center with the macro block with the erroneous macroblock same position in reference frame, the zone of pre-defined N * M size is the region of search, select simultaneously erroneous macroblock around macro block as candidate.Here we can only select the macro block of erroneous macroblock top, shown in Fig. 2 A; Also can only select the macro block of erroneous macroblock below, shown in Fig. 2 (B); Also the macro block that can select the erroneous macroblock above and below simultaneously is as candidate, shown in Fig. 2 c.Under in the end a kind of situation, the vertical distance of macro block is restricted to 16 pixels up and down, simultaneously MB
TAnd MB
BMotion in the region of search is consistent.Search in selected zone causes the piece of minimum MAD to be used as the estimation of erroneous macroblock content to piece coupling on the time domain to all candidates.Hiding error copies the content of piece around the best matching blocks that finds suitable on the position of the macro block that makes a mistake to, if adopt the mode of Fig. 2 (A) to select candidate such as us, the macro block that will mate the macro block below so copies the position of erroneous macroblock to.
4, quick camera lens dividing method in the compression domain
In traditional error concealment strategy, in general time domain error hides that to have a computing cost little, and the characteristics that concealment effect is good are methods of being inclined to use in error concealing.But when the content change between consecutive frame in the video is obvious especially (this significant change is generally switched by camera lens and caused), the effect that time domain error is hidden is just very poor.Consider this point, the new error concealing method that we propose is cut apart real-time camera lens with traditional error concealing method and is combined.
A camera lens is the video clips of the interior shooting of time between video camera opens and closes.Video frequency program semantically can be regarded as the combination of some camera lenses, and it is exactly to find these semantic borders that camera lens is cut apart.It is a lot of to be used for the algorithm that camera lens cuts apart, and consider in our application that the precision that camera lens is cut apart is not very important, and the speed that camera lens is cut apart is very crucial, has adopted the real-time camera lens dividing method based on motion vector among the present invention, and basic thought is as follows:
In MPEG-2 stream, the frame of three types of I, P, B is arranged, in the I frame, do not have motion vector, in the P frame, forward motion vector is arranged, in the B frame, may exist forward direction, back to and bi-directional motion vector.But,, during the work of MPEG-1/2 encoder, always select rational coding mode according to a certain foundation no matter how complicated situation is.Therefore, encoder is still followed certain reasonably strategy in the time of the processing variation camera lens.For example when running into the saltus step camera lens, inter prediction will inevitably lose efficacy, and relatively tend to select intra-frame encoding mode this moment, and both sides after before shot boundary, then forward direction, back are to selecting to be bound to meet certain rational pattern with bi-predictive mode.
If R
PThe macro block and the ratio of macro block in frame that forward motion vector is arranged that do not have motion vector in the expression P frame:
MV
FThe number that the macro block of forward motion vector is arranged in the expression frame, MV
NonExpression does not have the sum of the macro block of motion vector.Under normal circumstances, the most of macro block in the P frame can be encoded with the reduction coded-bit with reference to the reference frame of its front, so R
PVery little (general 1<R
P); When the camera lens switching takes place at P frame place the time, because the reference frame content of current P frame and front differs greatly, reference frame coding with reference to the front is used more bit on the contrary, and the macro block in most of P frame can adopt intraframe coding method (not having motion vector), so R
PVery big.Pass through R
PValue can judge whether the camera lens switching to have taken place at P frame place.
In like manner, establish R
BMacro block and the ratio of macro block in frame that forward motion vector is arranged that backward motion vector is arranged in the expression B frame
Under normal circumstances, the most of macro block in the B frame can be encoded to reduce coded-bit, R with reference to the reference frame of its front and the reference frame of back
BIt is near the value of a fluctuation 1; When the camera lens switching takes place at B frame place, because the reference frame content of current B frame and front differs greatly.Use more bit on the contrary with reference to the reference frame of front coding, the macro block in most of B frame can adopt the reference frame frame of back to give a forecast, and does not give a forecast with reference to the reference frame of front, so R
BVery big.Pass through R
BValue can judge whether the camera lens switching to have taken place at B frame place.
Adopt sliding window, can judge at the P frame with at the possible camera lens that the B frame occurs and switch.In the method, be R
PAnd R
BTo set up sliding window separately respectively.
If W is a sliding window that length is l, w
i(i ∈ [0, l)) is that an element in the window (is R
XValue), the expectation of window is
FrameNo represents the current frame number that enters into the X frame of sliding window, and ShotCount represents current camera lens counter, can find the switching of possibility X frame place's generation with following algorithm.
Sliding window algorithm, concrete steps are as follows:
(1)FrameNo=0,ShotCount=0;
(2) to each element in the window, make w
i=InitialEle, (i ∈ [0, l)), i=0 calculates E (W);
(3) if R
X(FrameNo)>and TH_X * E (W), change (4), otherwise change (5);
(4) Shot[ShotCount]=FrameNo, ShotCount=ShotCount+1, FrameNo=FrameNo+1 changes (3), otherwise, change (5);
(5) W (imodl)=R
X(FrameNo), recomputate E (W), i=i+1, FrameNo=FrameNo+1 if FrameNo>Max_X_Frame withdraws from, otherwise changes (3);
In the present invention, for P frame (being that X is P), InitialEle=1000, sliding window width l ∈ [8,10], threshold value TH_P=4.For B frame (X is B), InitialEle=1000, sliding window width l ∈ [18,22], threshold value TH_B=6.
Switch for the camera lens that may take place, detect with following method at I frame place:
Each piece (8 * 8 pixel) to macro block carries out dct transform, obtains 64 DCT coefficients, and wherein first coefficient is a DC coefficient, i.e. the DC coefficient.If c (0,0) is the DC coefficient of each piece, then
Be that the DC coefficient is a whole average.Just constituted the DC image of original image by all DC coefficients in the frame, the resolution of DC image is 1/64 of original image, has but kept the most information of original image.
In order further to reduce amount of calculation, we only utilize the DC image of I frame luminance component to detect to dissolve.The DC image of I frame can directly extract from compression domain, establishes I
iAnd I
I+1Be two adjacent I frames, the difference of DC image is defined as between them:
When camera lens dissolves switching, Diff_I_DC (I
i, I
I+1) obvious peak value can appear.Equally, to Diff_I_DC (I
i, I
I+1) also can adopt the sliding window method, in above-mentioned sliding window algorithm, X is I,
Sliding window width l=4, TH_I=3.