As another example, Δs of Equation 2 may be calculated by applying a mask to all pixels in the subblock on a pixel-by-pixel basis, and the objective function of Equation 3 for the subblock may be obtained by obtaining the sum of squares of Δs. Then, the optical flow (vx, vy) for the subblock may be calculated in such a manner as to minimize the objective function. For example, referring to FIG. 8, Δs of Equation 2 may be calculated for all pixels in a 5×5 mask 810a by applying the mask 810a to the pixel at position (0, 0) of a 4×4 subblock 820 in the current block. Then, Δs of Equation 2 may be calculated for all pixels in a 5×5 mask 810b by applying the mask 810b to the pixel at position (0, 1). Through this process, the objective function of Equation 3 may be obtained by summing the squares of the calculated Δs for all the pixels in the subblock. Then, an optical flow (vx, vy) that minimizes the objective function may be calculated. In this example, the objective function is expressed as Equation 12.