1. An image processing apparatus comprising: an image obtaining unit for continuously obtaining plural pieces of image data, which have substantially the same field angle; a reference-image generating unit for generating reference image data to be used for an image composition based on the plural pieces of image data obtained by the image obtaining unit; an image selecting unit for selecting at least two pieces of arbitrary image data from among the plural pieces of image data obtained by the image obtaining unit; a first difference calculating unit for calculating differences between the plural pieces of arbitrary image data selected by the image selecting unit for two adjacent pixels; a second difference calculating unit for calculating differences in pixel values of the plural pieces of arbitrary image data from the reference image data generated by the reference-image generating unit; a function setting unit for setting a function having variables of the differences calculated by the first difference calculating unit and the differences calculated by the second difference calculating unit; a boundary setting unit for setting boundaries respectively in the plural pieces of arbitrary image data so as to minimize the function set by the function setting unit; and an image combining unit for combining together the plural pieces of arbitrary image data selected by the image selecting unit based on the boundaries set by the boundary setting unit.