efficiency optimization for very large images + extension to 2D image segmentations