1. An image processing apparatus comprising: an image obtaining unit that obtains an image captured with an image sensor through an optical system; and a defect information generating unit that generates defect information indicating a defect within the image having been obtained, based upon a value at a target pixel and an average value of a plurality of pixel values corresponding to pixels present within a predetermined range containing the target pixel, wherein: the defect information is information on a projected image of a defect within an optical path, which manifests in the image, the defect information generating unit simultaneously generates information indicating a position of the projected image of the defect within the optical path and information indicating intensity of the projected image of the defect within the optical path and records the position information and the intensity information, and the defect information generating unit includes a relative ratio calculation unit that calculates a relative ratio of the value at the target pixel and the average value of the plurality of pixel values corresponding to the pixels present within the predetermined range containing the target pixel, and generates the defect information based upon the calculated relative ratio.