A Computational Framework for Segmentation and Grouping