Automatic Segmentation and Clustering of Spectral Terahertz Data