Check this script example for running island tool and exporitng the segmentation and writing to the disk: