dima: segmentation into templates