1. An image processing apparatus configured to assign a binary label representing belonging to a target region or belonging to another region to each pixel in an image, the image processing apparatus comprising: a memory configured to store processing instructions; and a processor configured to execute the stored processing instructions, which comprise: setting a plurality of shapes as a predicted shape of the target region; selecting a pixel group comprising N pixels in the image, where N is a natural number of 4 or more, which have positions representing the set predicted shape; and setting an energy function comprising an N-th order term in which a variable is a label of each of the N pixels of the selected pixel group, so that a value of the N-th order term is at a minimum value when a combination of the labels assigned to the N pixels of the selected pixel group is a pattern matching the set predicted shape of the target region, and increases in stages from the minimum value as the number of pixels, to which a label different from the pattern is assigned, increases; performing the labeling by minimizing the set energy function by using a discrete optimization process, selecting pixel groups respectively corresponding to the set plurality of different shapes, the pixel groups each comprising N pixels that have positions representing each of the set plurality of different shapes; determining N-th order terms corresponding to each of the selected pixel groups, in each of which a variable is a label of each pixel of the each of the selected pixel groups; and setting the energy function comprising a sum of the N-th order terms, so that a value of each of the N-th order term is at a minimum value when a combination of the labels assigned to pixels of the pixel group corresponding to the N-th order term is a pattern matching the set shape corresponding to the pixel group, and increases in stages from the minimum value along with an increase in the number of pixels to which a label different from the pattern is assigned, wherein the target region comprises a muscle region, and wherein the setting instruction of setting the predicted shape sets a plurality of relaxation curves each having a different degree of change in curvature as the plurality of different shapes.