Skip to content

Commit

Permalink
More reliable tiff reading as volume (#559)
Browse files Browse the repository at this point in the history
* More reliable tiff reading as volume

* Also deal with inconsistent shapes between multiple series

* style tweak

Co-authored-by: Almar Klein <almar.klein@gmail.com>
  • Loading branch information
almarklein and almarklein committed Oct 20, 2020
1 parent e603c63 commit a64b3ad
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion imageio/plugins/tifffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,19 @@ def _get_data(self, index):
# Read data as single 3D (+ color channels) array
if index != 0:
raise IndexError('Tiff support no more than 1 "volume" per file')
im = self._tf.asarray() # request as singleton image
# There is self._tf.asarray(), but it picks the first series by
# default, so this seems more reliable. See #558.
number_of_slices = len(self._tf.pages)
ims = []
for i in range(number_of_slices):
im = self._tf.pages[i].asarray()
if ims and ims[0].shape != im.shape:
break
ims.append(im)
if ims:
im = np.stack(ims, 0)
else:
im = self._tf.asarray()
meta = self._meta
else:
# Read as 2D image
Expand Down

0 comments on commit a64b3ad

Please sign in to comment.