-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume_to_hdf.py
30 lines (27 loc) · 1.06 KB
/
volume_to_hdf.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
import cv2
from tifffile import imread
from tqdm import tqdm
import glob
import h5py
import numpy as np
# %%
layers = glob.glob("/mnt/aged-star/20230210143520/*.tif")
# %%
for layer in tqdm(layers[10000:]):
layer_img = cv2.convertScaleAbs(imread(layer), alpha=(255.0/65535.0))
break
# %%
with h5py.File('/mnt/aged-star/volume.hdf5', "r+") as f:
dset = f.create_dataset("20230210143520", shape=(layer_img.shape[0],layer_img.shape[1], len(layers)), dtype=np.uint8, chunks=True, shuffle=True, compression="lzf")
# dset = f["scan_volume"]
for layer_range in tqdm(range(0, len(layers), 256)):
array_container = []
for i in tqdm(range(layer_range, layer_range+256)):
try:
array_container.append(cv2.convertScaleAbs(imread(layers[i]), alpha=(255.0/65535.0)))
except:
print("layer broke on ", layers[i])
break
array_container = np.stack(array_container, axis = -1)
print(layer_range, layer_range+256)
dset[:, :, layer_range:layer_range+256] = array_container