1. An image encoding device comprising: an encoding means detecting an optimal mode to be provided to an encoding process from a plurality of first prediction modes and a plurality of second prediction modes every predetermined block by comparison of cost values of a cost function indicating an encoding efficiency and encoding image data in the optimal mode; and a motion predicting and compensating means for calculating the cost values of a plurality of motion vectors, which are candidates of an optimal motion vector, with a first pixel precision every first prediction mode and calculating the optimal motion vector with a second pixel precision and the cost value of the optimal motion vector with the second pixel precision using a profile of the cost values with the first pixel precision, wherein the first prediction modes are inter prediction mode, the second prediction modes are intra prediction modes, the first pixel precision is a half-pixel precision, and the second pixel precision is a quarter-pixel precision, and wherein the motion predicting and compensating means selects at least three points located in a line with the first pixel precision on the basis of an SAD value which is the sum of absolute predicted differences or an SATD value which is the sum of absolute values which are obtained by carrying out a Hadamard transform on the predicted differences in detecting a motion with the first pixel precision, specifies as a motion vector with a second pixel precision in the line the motion vector indicating a middle point between a point having the minimum SAD or SATD value and a point having the second-minimum SAD or SATD value when an end point has the minimum SAD or SATD value, a center point has the second-minimum SAD or SATD value, a difference between the minimum SAD or SATD value and the second-minimum SAD or SATD value is small, and a difference between the second-minimum SAD or SATD value and the third-minimum SAD or SATD value is great, and calculates the cost value of the motion vector using an SAD or SATD value of the motion vector based on the relationship of the minimum, second-minimum, and third-minimum SAD or SATD values.