Added script for template segmentation
Added image file writing