A moving image encoding apparatus for encoding an input moving image and generating encoded data, the moving image encoding apparatus comprising: detection means for detecting, as a target block, a block in which change in pixel values is small, and brightness smoothly changes, from blocks to which intra prediction or bidirectional prediction was applied among blocks acquired by dividing the input moving image; extraction means for extracting a brightness change direction of the target block; pixel value control means for controlling pixel values of a decoded block of a locally decoded image indicated by the detection means and based on the brightness change direction of the target block extracted by the extraction means, the decoded block corresponding to the target block; and encoding means for encoding data including information indicating the target block and the brightness change direction of the target block; wherein the extraction means is configured to determine a flat surface approximated to pixel values of the target block, and to extract the brightness change direction of the target block from the inclination of the flat surface; the pixel value control means is configured to generate a random number for each of the pixels of the decoded block, and to set a coefficient that increases as brightness increases along the brightness change direction for each of the pixels of the decoded block, to obtain an adding value for a pixel of the decoded block by multiplying the random number for the pixel with the respective coefficient for the pixel, and to add the adding value for the pixel to a pixel value of the pixel of the decoded block; and the random number for each of the pixels of the decoded block is larger than or equal to 0 and smaller than or equal to 1. detection means for detecting, as a target block, a block in which change in pixel values is small, and brightness smoothly changes, from blocks to which intra prediction or bidirectional prediction was applied among blocks acquired by dividing the input moving image; extraction means for extracting a brightness change direction of the target block; pixel value control means for controlling pixel values of a decoded block of a locally decoded image indicated by the detection means and based on the brightness change direction of the target block extracted by the extraction means, the decoded block corresponding to the target block; and encoding means for encoding data including information indicating the target block and the brightness change direction of the target block; wherein the extraction means is configured to determine a flat surface approximated to pixel values of the target block, and to extract the brightness change direction of the target block from the inclination of the flat surface; the pixel value control means is configured to generate a random number for each of the pixels of the decoded block, and to set a coefficient that increases as brightness increases along the brightness change direction for each of the pixels of the decoded block, to obtain an adding value for a pixel of the decoded block by multiplying the random number for the pixel with the respective coefficient for the pixel, and to add the adding value for the pixel to a pixel value of the pixel of the decoded block; and the random number for each of the pixels of the decoded block is larger than or equal to 0 and smaller than or equal to 1.