-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_svs_to_dzi.py
42 lines (36 loc) · 1.58 KB
/
convert_svs_to_dzi.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
41
42
import os
import deepzoom
import PIL
PIL.Image.MAX_IMAGE_PIXELS = 100000000000
# Specify your source image
# BASE_PATH = '/home/guillaume/Documents/toxicology/tox-discovery-ui/data/slides/svs'
# OUT_PATH = '/home/guillaume/Documents/toxicology/tox-discovery-ui/data/slides/dzi'
BASE_PATH = '/home/guillaume/Documents/toxicology/tox-discovery-ui/data/slides/tox2data/27686'
OUT_PATH = '/home/guillaume/Documents/toxicology/tox-discovery-ui/data/slides/tox2data/27686'
fnames = os.listdir(BASE_PATH)
fnames = [fn for fn in fnames if fn.endswith('.svs')]
for fn in fnames:
print('Start processing: {}'.format(fn))
slide_name = fn.replace('.svs', '')
os.makedirs(os.path.join(OUT_PATH, slide_name), exist_ok=True)
if not os.path.isfile(os.path.join(OUT_PATH, slide_name, fn.replace('.svs', '.dzi'))):
try:
creator = deepzoom.ImageCreator(
tile_size=128,
tile_overlap=1,
tile_format="png",
image_quality=0.8,
resize_filter="bicubic",
)
# Create Deep Zoom image pyramid from source
creator.create(
os.path.join(BASE_PATH, fn),
os.path.join(OUT_PATH, slide_name, fn.replace('.svs', '.dzi'))
)
except:
print('Use VIPS instead')
command = 'vips dzsave --tile-size 128 {} {}'.format(
os.path.join(BASE_PATH, fn),
os.path.join(OUT_PATH, slide_name, fn.replace('.svs', '.dzi'))
)
os.system(command)