Write images to imagesoutdir or outdir if specified