Skip to content

Instantly share code, notes, and snippets.

@tdsmith
Created September 17, 2013 00:01
Show Gist options
  • Save tdsmith/6588350 to your computer and use it in GitHub Desktop.
Save tdsmith/6588350 to your computer and use it in GitHub Desktop.
import tifffile as tf
import numpy as np
from os.path import splitext
def z_project(fn):
tiff = tf.TiffFile(fn)
n = len(tiff.pages)
immap = np.arange(n).reshape((-1, 2), order='F')
d = {}
d['cars'] = immap[:-1,0]
d['srs'] = immap[:,1]
for name, inds in d.iteritems():
a = np.array([tiff[ind].asarray() for ind in inds])
a.sort(axis=0) # intensity projection
outname = '%s-%s.tif' % (splitext(fn)[0], name)
tf.imsave(outname, a[-1,:,:])
@NicolasCARPi
Copy link

One can simply use: np.amax(img, axis=0) (with img being the ndarray with slices first)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment