1. An image processing apparatus comprising: a dividing unit that divides an object image into regions; a first extracting unit that extracts image features of the regions generated by the dividing unit; a quantizing unit that quantizes the image features extracted by the first extracting unit; a generating unit that generates an expected value of an occurrence probability of each topic variable indicating similar images from the image features quantized by the quantizing unit, using a correlation between the image features quantized by the quantizing unit and the topic variables; and an image output unit that outputs an image of a defective portion in the object image, using the expected values of the occurrence probabilities of the topic variables generated by the generating unit.