Skip to content

Commit

Permalink
libtiff
Browse files Browse the repository at this point in the history
  • Loading branch information
zhixuhao committed Apr 17, 2017
1 parent cae3407 commit c5398d4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions split_merge_tif.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'''
split 30 single images from an array of images : train-volume.tif label-volume.tif test-volume.tif
'''
from libtiff import TIFF3D,TIFF
dirtype = ("train","label","test")

def split_img():

'''
split a tif volume into single tif
'''

for t in dirtype:
imgdir = TIFF3D.open(t + "-volume.tif")
imgarr = imgdir.read_image()
for i in range(imgarr.shape[0]):
imgname = t + "/" + str(i) + ".tif"
img = TIFF.open(imgname,'w')
img.write_image(imgarr[i])

def merge_img():

'''
merge single tif into a tif volume
'''

path = '/home/zhixuhao/Downloads/imgs_mask_test_server2/'
imgdir = TIFF3D.open("test_mask_volume_server2.tif",'w')
imgarr = []
for i in range(30):
img = TIFF.open(path + str(i) + ".tif")
imgarr.append(img.read_image())
imgdir.write_image(imgarr)

if __name__ == "__main__":

merge_img()



0 comments on commit c5398d4

Please sign in to comment.