forked from silencemao/detect-cell-edge-use-unet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
split_merge_image.py
43 lines (30 loc) · 952 Bytes
/
split_merge_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#@silence 20170517
'''
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/greg/data/code/python3/UNet/unet/data/'
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()