where D1 and D5 denote horizontal complexity and vertical complexity, respectively, and CU denotes a set of pixel positions in the first reference block and the second reference block corresponding to the positions of the respective pixels in the current block. [i, j] denotes a position in the first reference block and the second reference block corresponding to each pixel in the current block. And d1(i, j) and d5(i, j) may be calculated by Equation 15. d1=(Ix(0)(i, j)+Ix(1)(i, j))2 d2=(Ix(0)(i, j)+Ix(1)(i, j))(Iy(0)(i, j)+Iy(1)(i, j))