Unable to load tiff sequence created by python3 tifffile module

Operating system: Windows 10
Slicer version: 4.8.1
Expected behavior: Load tiff sequence created by python3 tifffile module and render the volume
Actual behavior: The loading bar shows up but the Active Volume is empty.

I try to create tiff sequence with python 3.4.5 on a CentOS 7 server. The py code is demonstrated as follow:

============================TIFF generation============================

import numpy as np
import tifffile as tiff

data = np.zeros((x_axis, y_axis, z_axis)) #just a sample
for z in range(z_axis):
  tiff.imsave(str(z)+'.tiff', data[:, :, z])
  image = tiff.imread(str(z)+'.tiff')
  print(np.array_equal(image, data[:, :, z])) #always print True

============================TIFF generation============================

The last line of the code always print True, which means that I can successfully write and load the tiff image and they are the same.

However, when I try to load it with Slicer, it fails. The steps I take was:

  1. Add data
  2. Choose a directory and add
  3. Show options and uncheck singlefile

The loading bar shows up and finishes. However, the Active Volume in the Volume module is empty. I cannot select volume loaded from Volume Rendering module, either. I’m wondering where I do it wrong.

Thanks for answering!

Try Choose files to add rather than adding directory. Also, does the file load in other software?

If that doesn’t work, you could upload a (small) example file for someone to look at.

(by the way, for code you can quote with triple-backtick: “```”`)

See detailed instructions here: https://www.slicer.org/wiki/Documentation/4.6/FAQ#How_to_load_data_from_a_sequence_of_jpg.2C_tif.2C_or_png_files.3F

1 Like

Thanks for your comment. I also try to open the tiff files with GIMP 2 but it doesn’t work either.
I tried to upload some examples but it says tiff files are not authorized. Only jpg, png, gif is allowed.

I’m wondering if the data type of the numpy array should be uint16 or anything else. The original intensities are designed to be 16 bit unsigned integer. However, although I tried to modify the array to np.uint16, the output tiff files are still unreadable.

Thanks for your comment. I tried your suggestion but it also failed.
There is no options for me in “Active Volume” in Volume module.

If the file doesn’t load in GIMP then it certainly won’t load in Slicer, unfortunately. (your code sample doesn’t run as-is so I can’t try it myself)

Try dropbox, onedrive, etc and post a link.

1 Like

Thanks for your help! I think I just figure it out and solve it.
The data type of 3D numpy array should be “float32” so that the output image can be correctly loaded and rendered.