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:
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
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:
Add data
Choose a directory and add
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 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.
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)
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.