High-precision pixel motion estimation in JM8.5
OUTLINE:
1. Motion estimation related data structure and variables
2. Initialization of related important variables
3, motion estimation function (blockmotionsearch ()) process
4, sports vector prediction
5, analogation point motion estimation
6, subtransmitter point motion estimation (ie high-precision pixel point motion estimation)
7. Interpolation prediction of sub-pixel points
8, legacy problem
1. Motion estimation related data structure and variables
A, six-needle all_mv explanation
(1) The style of the declaration is as follows:
int ****** all_mv;
(2) Where appears:
The structural elements of the global variable IMG All_mv and PRED_MV (the data structure is defined in global.h)
MV_Search.c's blockMotiongSearch () function (function of a function of motion estimation, focusing later) declared in the local variable INT ******* ALL_MV;
(3) The meaning of the six-needle:
The corresponding is a six-dimensional array as follows:
All_mv [block_x] [block_y] [list] [ref] [blocktype] [direction]
Where Block_x, block_y represents 4 * 4 blocks in horizontal and vertical positions within the entire macroblock 16 * 16, and also shows that the saved motion vector is in 4 * 4, if there is a block 8 * 4 block. Its motion vector will be stored in the same two copies.
Which reference frame is represented by List?
REF is expressed as the reference frame sequence number
BlockType indicates the type of macroblock, with 16 × 16, 16 × 8. . . 4 × 4
Direction indicates horizontal or vertical direction, and its values are 0 and 1, respectively.
2. Initialization of related important variables
A, IMG-> All_mv initialization
The entire process of its initialization is as follows:
First, in the main () function of lencod.c, INIT_IMG () function is called in the same file.
Then init_img () also calls GET_MEM_MV (IMG-> ALL_MV) (in the same file) initialize all_mv. The initialization of PRED_MV is the same. The following focuses on the GET_MEM_MV () function
INT GET_MEM_MV (int ******* mv)
{
INT I, J, K, L, M;
// 4 * 4 sequence number, horizontal direction: block_x. Because the macroblocks used are not more than 16 × 16, the maximum is 4
IF ((* mv = (int ******) Calloc (4, sizeof (int *****)) == null)
NO_MEM_EXIT ("Get_MEM_MV: MV");
For (i = 0; i <4; i )
{
IF ((* mv) [i] = (int *****) Calloc (4, sizeof (int ****)) == NULL) // block_y
NO_MEM_EXIT ("Get_MEM_MV: MV");
For (j = 0; j <4; j )
{
IF ((* mv) [i] [j] = (int ***) Calloc (2, sizeof (int ***)) == null) // list. 6?
NO_MEM_EXIT ("Get_MEM_MV: MV");
For (k = 0; k <2; k )
{
IF ((* mv) [i] [j] [k] = (int ***) Calloc (IMG-> max_num_reference, sizeof (int **)) == null) // refNO_Mem_exit ("GET_MEM_MV: MV ");
For (l = 0; l
{
IF ((* mv) [i] [j] [k] [l] = (int **) Calloc (9, sizeof (int *))) == null) // blockType: 16 * 16, 16 * 8...
NO_MEM_EXIT ("Get_MEM_MV: MV");
For (m = 0; M )
IF ((* mv) [i] [j] [k] [l] [m] = (int *) Calloc (2, sizeof (int))) == null) // x or y Direction: 0 OR 1
NO_MEM_EXIT ("Get_MEM_MV: MV");
}
}
}
}
Return 4 * 4 * IMG-> max_num_references * 9 * 2 * sizeof (int);
}
3, motion estimation function (blockmotionsearch ()) process
The most core function for motion estimation for a block (various sizes) is the blockmotionsearch () in MV_Search.c, and the specific process of this function is as follows:
a, get the data of the current block
B, sports vector prediction
C, 整 象点 点 搜
D, Asian Point Search
e, save the MV and return the SAD value
Here, the following is a focus on B, C, and D.
4, sports vector prediction
Related functions are: setMotionVectorPredictor (), MV_Search.c
a, the explanation of the corresponding macro:
#define mvpred_median 0 // Medium value prediction method
#define mvpred_l 1 // Take the motion vector of the left neighboring block
#define mvpred_u 2 // Take the motion vector of the adjacent block
#define mvpred_ur 3 // Take the motion vector of the right adjacent block
b, the specific process of this function
(1) Check if each adjacent block is effective
(2) Determine the prediction mode MVPredType in conjunction with reference frame sequence number
(3) Different prediction methods according to MVPredType
C, important block
. . .
/ / Judgment the effectiveness of adjacent 4 * 4 blocks
Getluma4x4Neighbour (MB_NR, Block_x, Block_Y, -1, 0, & block_a); // Left
Getluma4x4neighbour (MB_NR, Block_x, Block_Y, 0, -1, & block_b); // Up
Getluma4x4Neighbour (MB_NR, Block_x, Block_Y, Blockshape_x, -1, & block_c); // Right-Up
Getluma4x4Neighbour (MB_NR, Block_x, Block_Y, -1, -1, & block_d); // Left-Up
. . .
/ * Prediction if only one of the neighbors buy the reference frame
* WE Are Checking
* /// only one adjacent block sequence number and the current coupon frame number, the prediction method is relatively simple.
if (rFrameL == ref_frame && rFrameU = ref_frame && rFrameUR = ref_frame!!) mvPredType = MVPRED_L; else if (! rFrameL = ref_frame && rFrameU == ref_frame && rFrameUR = ref_frame!) mvPredType = MVPRED_U;
Else if (RFRAMEL! = Ref_Frame && RFrameu! = REF_FRAME & RAMEUR == REF_FRAME) mvpredtype = mvpred_ur;
. . .
/ / Different prediction methods according to MVPredType
Switch (mvpredtype)
{
Case mvpred_median:
. . .
{
// Take the value
PRED_VEC = MV_A MV_B MV_C-Min (MV_A, MIN (MV_B, MV_C)) - Max (MV_A, MAX (MV_B, MV_C));
}
Break;
Case MVPRED_L:
PRED_VEC = MV_A;
IF (Input-> fMenable) TEMP_PRED_SAD [HV] = SAD_A;
Break;
Case mvpred_u:
PRED_VEC = MV_B;
IF (Input-> fMenable) TEMP_PRED_SAD [HV] = SAD_B;
Break;
Case mvpred_ur:
PRED_VEC = MV_C;
IF (Input-> fMenable) TEMP_PRED_SAD [HV] = SAD_C;
Break;
DEFAULT:
Break;
}
. . .
5, analogation point motion estimation
Only the case of full search is used here, and the case where the fast search method is not analyzed. Related functions are: fulpelBlockMotionSearch (), mv_search.c
The important blocks are as follows:
......
/ / ===== loop over all seat positions =====
/ / Location search for each pixel point location of the search area (full search)
For (POS = 0; POS
......
Note: This function is relatively simple, so this is not specifically analyzed. Also, it is worth mentioning that for the matching criteria in the search, RDO strategy is used in JM8.5, which has been talked in 9.19 reports, you can refer to the relevant content inside that report.
6, subtransmitter point motion estimation (ie high-precision pixel point motion estimation)
Related functions are: SubpelBlockMotionSearch (), Image.c
A, function ideology
First, through the illuminate point of the integrated integration, half-quadrant motion estimation; then by the found semi-pixel matching point, then perform a motion estimate of 1/4 pixel point
b, important block
. . .
/ / Find the corresponding reference frame
REF_PICTURE = Listx [list list_offset] [ref]; //! !
IF (Apply_Weights)
{
REF_PIC = Listx [List List_offset] [REF] -> IMGY_UPS_W;}
Else
{// Ref_PIC points to brightness data that has been sampled to 1/4 pixel point
REF_PIC = Listx [List List_offset] [REF] -> IMGY_UPS;
}
. . .
/ ****************************************
***** *****
***** HALF-PEL Refinement ******
***** *****
******************************* /
/ / ===== Convert Search Center to quarter-Pel Units =====
* mv_x << = 2;
* mv_y << = 2;
/ / ===== set function for getting pixel value =====
IF ((PIC4_PIX_X * MV_X> 1) && (PIC4_PIX_X * MV_X
(PIC4_PIX_Y * MV_Y> 1) && (PIC4_PIX_Y * MV_Y
{
PELY_14 = fastpely_14; // Point to the function of the pointer
}
Else
{
PELY_14 = UmvPELY_14; // Unlimited Sport Vector Mode
}
/ / ===== loop over search position =====
For (Best_POS = 0, POS = min_pos2; pOS
{
. . .
* D = Orig_Line [x0] - PELY_14 (Ref_PIC, RY, RX0, IMG_HEIGHT, IMG_WIDTH);
. . .
/ ********************************************
***** *****
***** Quarter-Pel Refinement *****
***** *****
******************************************* /
. . . //, and semi-xylby point motion estimate
7, subtransin point interpolation prediction
A, function calling process
Subphominic point interpolation prediction is called when the reconstructed image is inserted into a reference frame list. So the flow of the entire function call is as follows: (Note: Arrow Represents call relationship)
B, related knowledge review
(1) Predictive interpolation for half ambictor
Using 6-TAP Filter, the specific formula is as follows:
(2) Forecast interpolation for 1/4 pixel points
The method of making a mean, the specific formula is as follows:
C, UNIFIEDONEFORTHPIX () Function key block analysis
(1) This function is located in the image.c file.
. . .
/ / Open a buffer, IMG_PAD_SIZE is to meet UMV mode
GET_MEM2D (& (S-> IMGY_UPS), (2 * IMG_PAD_SIZE S-> Size_Y) * 4, (2 * IMG_PAD_SIZE S-> Size_x) * 4) ;. . .
// Since the 1/2 pixel point in the position of the horizontal integer pixel point and the direct assignment of the integrated number data
For (j = -img_pad_size; j
{
For (i = -Img_pad_size; i
{
JJ = max (0, min (S-> Size_Y - 1, J));
//6-TAP Filter
IS =
(One_fouRTh_TAP [0] [0] *
(IMGY [JJ] [MAX (0, Min (S-> Size_X - 1, I))]
IMGY [JJ] [MAX (0, Min (S-> Size_X - 1, i 1))])
One_fourath_tap [1] [0] *
(IMGY [JJ] [MAX (0, Min (S-> Size_X - 1, I - 1))]
IMGY [JJ] [MAX (0, Min (S-> Size_x - 1, I 2))])
One_fourarth_tap [2] [0] *
(IMGY [JJ] [MAX (0, Min (S-> Size_X - 1, I - 2))]
IMGY [JJ] [MAX (0, MIN (S-> Size_x - 1, I 3))]))
IMG4Y_TMP [J IMG_PAD_SIZE] [(i IMG_PAD_SIZE) * 2] = IMGY [JJ] [Max (0, Min (S-> Size_X - 1, I))] * 1024; // 1/1 PIX POS
IMG4Y_TMP [J IMG_PAD_SIZE] [(i IMG_PAD_SIZE) * 2 1] = IS * 32; // 1/2 PIX POS
}
}
// Seeking 1/2 pixel point in the position of vertical interaction points and at the position of 1/2 pixel point
. . . //slightly
/ * 1/4 PIX * /
. . . //slightly
. . .
(2) One_fouth_tap explanation:
const Int One_fouRTh_TAP [3] [2] =
{
{20, 20},
{-5, -4},
{1, 0},
}
Note: In JM8.5, one_fouth_tap [?] [1] is not used, its role cannot be explained.