Fringe projection technique has been widely used in numerous areas including manufacturing, medical science, computer science, entertainment, and documentation of cultural artifacts. However, there are problems when measuring a complex scene with a large range of reflectivity variations, where minimum human intervention is usually desirable. This paper presents a framework that can determine the optimal number of projected light intensities and corresponding intensity values for high-quality three-dimensional (3D) shape measurement with digital fringe projection technique. By using the k-means clustering algorithm, we can calculate the distribution of surface reflectivity and thus predict the optimal number of projected light intensities and corresponding intensity values. Experimental results demonstrate that the proposed framework can be successfully applied to the measurement of complex scenes whose histogram does not show apparent peaks and troughs.