An image processing apparatus comprising: a boundary line candidate image creating means that creates a boundary line candidate image using an input image obtained by capturing an optical tomographic image of an ocular fundus composed of a plurality of retinal layers, the boundary line candidate image representing edges of the retinal layers detected from the input image as boundary line candidates; a luminance value-differentiated image creating means that differentiates a luminance value of the input image in the depth direction of the ocular fundus to create a luminance value-differentiated image, the luminance value-differentiated image representing luminance gradient of the retinal layers, wherein the luminance value-differentiated image complements the edge information of the boundary line candidate image; a luminance value information image creating means that creates a luminance value information image in which the input image is shifted in the depth direction of the ocular fundus by a desired number of pixels; an evaluation score image creating means that creates an evaluation score image that represents an evaluation score for boundary line extraction, on the basis of a boundary line position probability image representing a boundary line position and created from the boundary line candidate image, an existence probability image, the luminance value-differentiated image, and the luminance value information image; and a boundary line extracting means that searches for a route having a highest total evaluation score from the created evaluation score image and extracts the route having the highest total evaluation score as the boundary line, wherein the luminance value-differentiated image is weighted with a first weighting coefficient in accordance with the boundary line to be extracted; the luminance value information image is weighted with a second weighting coefficient in accordance with the boundary line to be extracted; and the existence probability image is constructed by obtaining an existence probability that is a probability of existence of a boundary line of the retinal layers in a normal tomographic image of an ocular fundus of a normal eye, wherein each pixel of the existence probability image stores the probability of a boundary line of the retinal layers existing at said pixel in the normal tomographic image. a boundary line candidate image creating means that creates a boundary line candidate image using an input image obtained by capturing an optical tomographic image of an ocular fundus composed of a plurality of retinal layers, the boundary line candidate image representing edges of the retinal layers detected from the input image as boundary line candidates; a luminance value-differentiated image creating means that differentiates a luminance value of the input image in the depth direction of the ocular fundus to create a luminance value-differentiated image, the luminance value-differentiated image representing luminance gradient of the retinal layers, wherein the luminance value-differentiated image complements the edge information of the boundary line candidate image; a luminance value information image creating means that creates a luminance value information image in which the input image is shifted in the depth direction of the ocular fundus by a desired number of pixels; an evaluation score image creating means that creates an evaluation score image that represents an evaluation score for boundary line extraction, on the basis of a boundary line position probability image representing a boundary line position and created from the boundary line candidate image, an existence probability image, the luminance value-differentiated image, and the luminance value information image; and a boundary line extracting means that searches for a route having a highest total evaluation score from the created evaluation score image and extracts the route having the highest total evaluation score as the boundary line, wherein the luminance value-differentiated image is weighted with a first weighting coefficient in accordance with the boundary line to be extracted; the luminance value information image is weighted with a second weighting coefficient in accordance with the boundary line to be extracted; and the existence probability image is constructed by obtaining an existence probability that is a probability of existence of a boundary line of the retinal layers in a normal tomographic image of an ocular fundus of a normal eye, wherein each pixel of the existence probability image stores the probability of a boundary line of the retinal layers existing at said pixel in the normal tomographic image.