Clustering and Segmentation with Application in Document Image Processing