1. An image processing apparatus comprising: at least one hardware processor configured to implement: a receiving unit that receives an image including a plurality of document images; a first detection unit that detects an outermost rectangular shape in the image including the plurality of document images; a second detection unit that, in a case where a background of the outermost rectangular shape is not white, detects rectangular shapes included in the outermost rectangular shape detected by the first detection unit as document images; and an output unit that outputs at least one of the document images.