1. An image processing apparatus that selects an image captured in an imaging direction close to the imaging direction of a target included in an input image from among a plurality of sample images obtained by imaging an object of the same type as the target in a plurality of different directions, the image processing apparatus comprising: means for creating a first masking image in which pixels in an area including an area of the target in all of the sample images are determined valid pixels while pixels in the remaining area are determined invalid pixels; and means for selecting an image providing a best match with the input image from among the sample images by comparing the input image with the sample images using the pixels of the input image corresponding to the valid pixels in the first masking image.