According to the image processing device of the present invention, the binarization image having increasing assuredness can be generated by extracting the metal piece from the original image with the graph cut processing. The image processing device of the present invention is the system that executes an image trimming from near the center of the intermediate region after the metal piece is divided relative to the image of the roughly extracted binarization image near the center of the intermediate region in that it is difficult to decide whether it belongs to the metal piece or not. Following such steps, the intermediate region can be assuredly trimmed while executing the image trimming in the region as small as possible.