1. An image processing apparatus for executing clustering processing which classifies pixels of image data into clusters, comprising: a classifying processing unit configured to classify a pixel of interest into a cluster if this cluster has a representative feature quantity whose difference with respect to a feature quantity of the pixel of interest is less than a threshold value, and if such a cluster does not exist, generate a new cluster and classify the pixel of interest into this new cluster; and a merge processing unit configured to determine whether the number of clusters has reached a prescribed upper-limit value before or after generation of the new cluster in a case where the new cluster has been generated by said classifying processing unit, and merge at least two clusters in a case where the upper-limit value has been reached.