-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages2MaxProjPNG_tn.py
29 lines (25 loc) · 972 Bytes
/
images2MaxProjPNG_tn.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
import numpy as np
import os
import sys
import nrrd, png
from PIL import Image
def thumbnail(im, size=(25,25)):
im = im.resize(size, Image.ANTIALIAS)
return im
if (len(sys.argv) < 2):
print 'Error: missing arguments!'
print 'e.g. python images2MaxProjPNG_tn.py image1.nrrd imageN.nrrd ...'
else:
for x in range(1,(len(sys.argv))):
print 'creating tumbnail of image ', sys.argv[x]
readdata, options = nrrd.read(str(sys.argv[x]))
flat = np.transpose(np.max(readdata,axis=2))
tnfile = os.path.basename(sys.argv[x]).replace('.nrrd','_tn.png')
if np.shape(flat)[0] < np.shape(flat)[1]:
thumbnail(Image.fromarray(flat), size=(120,60)).save(tnfile,"PNG")
elif np.shape(flat)[0] > np.shape(flat)[1]:
thumbnail(Image.fromarray(flat), size=(60,120)).save(tnfile,"PNG")
else:
thumbnail(Image.fromarray(flat), size=(60,60)).save(tnfile,"PNG")
del flat
print 'Done.'