1. An image processing apparatus, comprising: a first detection unit that detects boundaries from an image; an extraction unit that extracts straight-line segments from the boundaries detected by the first detection unit; a second detection unit that detects a region in which differences between pixel values of near pixels located across the straight-line segments extracted by the extraction unit are larger than a predetermined first value, or equal to or larger than the predetermined first value; a classification unit that classifies the straight-line segments in the region detected by the second detection unit into four sides of quadrangles; a third detection unit that detects colors or densities in outer areas of the four sides classified by the classification unit; a selection unit that selects combinations that differences between the colors or the densities detected by the third detection unit and corresponding to the straight-line segments in the combinations are equal to or smaller than a predetermined second value, or smaller than the predetermined second value, from the combinations of the four sides that possibly form the quadrangles; a fourth detection unit that detects coordinates of four vertexes obtained when the straight-line segments in the combinations are extended, and a combination that an area of a quadrangle formed by the corresponding four coordinates satisfies a predetermined condition, from the combinations selected by the selection unit; and a correction unit that corrects the quadrangle formed by the combination detected by the fourth detection unit to a rectangle.