from libtiff import * imgdir = TIFF3D.open("train-labels.tif") imgarr = imgdir.read_image() for i in range(imgarr.shape[0]): savepath = "./train-labels/"+ str(i) + '.tif' img = TIFF.open(savepath, 'w') img.write_image(imgarr[i])