The effectiveness of K-means clustering algorithm for image segmentation has been proven in many studies, but is limited in the following problems: 1) the determination of a proper number of clusters. If the number of clusters is determined incorrectly, a good-quality segmented image cannot be guaranteed; 2) the poor typicality of clustering prototypes; and 3) the determination of an optimal number of pixels. The number of pixels plays an important role in any image processing, but so far there is no general and efficient method to determine the optimal number of pixels. In this paper, a grid-based K-means algorithm is proposed for image segmentation. The advantages of the proposed algorithm over the existing K-means algorithm have been validated by some benchmark datasets. In addition, we further analyze the basic characteristics of the algorithm and propose a general index based on maximizing grey differences between investigated objective grays and background grays. Without any additional condition, the proposed index is robust in identifying an optimal number of pixels. Our experiments have validated the effectiveness of the proposed index by the image results that are consistent with the visual perception of the datasets.