1. An image processing apparatus configured to generate, based on a plurality of images photographed from a plurality of different viewpoints, an image viewed from a virtual viewpoint, the image processing apparatus comprising: a calculation unit configured to calculate a near image distance (NID), which corresponds to a distance from the virtual viewpoint to a first viewpoint among the viewpoints of the plurality of images, and a far image distance (FID), which corresponds to a distance from the virtual viewpoint to a second viewpoint among the viewpoints of the plurality of images, which is relatively distant from the virtual viewpoint compared with the first viewpoint; a search range setting unit configured to set a search range; a determination unit configured to determine parallax vectors corresponding to search reference block coordinates by executing block matching processing within the search range and by using a first block image, which is included in a near image corresponding to the first viewpoint and which corresponds to the search reference block coordinates and the near image distance, and a second block image, which is included in a far image corresponding to the second viewpoint and which corresponds to the search reference block coordinates and the far image distance; a generation unit configured to generate the image from viewed from the virtual viewpoint by using the parallax vectors; and a setting unit configured to set a parallax magnification (PM), wherein the search range setting unit sets the search range according to a depth length which denotes the length of a line segment parallel to an optical axis of an imaging lens, and wherein the near image distance (NID) and the far image distance (FID) are first calculated based on the parallax magnification (PM) set by the setting unit using the expressions NID=PM-1 and FID=PM+1, and then adjusted to express a ratio between the NID and the FID by a simple integer when image data has been discretized.