Load stacks of files into viewer

Dear all,

I think that’s a rather simple question but I just cannot get my head around how to solve this. I managed to use SimpleITK for displaying both DICOM files and folders and single Nifti (or other files) using slicer as viewer. But what about sending multiple nii-files (e.g. different sequences) to Slicer?

These are the lines of code I started adapting:
https://simpleitk.readthedocs.io/en/master/link_DicomSeriesReader_docs.html

but obviously

dicom_names = reader.GetGDCMSeriesFileNames( sys.argv[1] )

is the wrong way. Can anyone give me a quick suggestion.

Cheers,

David

Having a time sequence as a series of files is not overly common. The usual way is to have a single image of higher dimension. You should be able to read them using series reader, but you need to construct the list of file names (std::vector<std::string>) yourself.

Thanks for the input and the quick response!

It’s less a time series saved as files but rather providing an overview of the available sequences so that I have the opportunity to spot major issues. I have about 4-10 sequences of nii-files in a folder, and I would like to work with them instead of downloading the DICOM files again. Actually, I tried stacking them in an additional dimension but I can tell you it’s not the most elegant thing I have ever coded.

Just so that I get you right, you mean something like:

file_names =  [filename for filenamein os.listdir(nifti_dir)]
series_reader = sitk.ImageSeriesReader()
series_reader.SetFileNames(file_names)

Yet, that doesn’t work with sitk.Show. I am clearly missing something here. Thanks for your help.

That’s what I meant. So your viewer does not support 4D files - what did you expect to achieve?

Hello @dpedrosac,

I would not recommend using the Show function to view the images as it creates a copy of each image and then opens that file in your file viewer of choice (default is Fiji, which you already know).

With Slicer you can open them with the MultiVolumeImporter and view with the MultiVolumeExplorer (see discussion here). I’m not a slicer expert so not sure if you can do this programmatically/commandline.

Using ITK-SNAP:

import os
import glob

file_names = glob.glob('./*.mha')
os.system('/Applications/ITK-SNAP.app/Contents/bin/itksnap -g {0} -o '.format(file_names[0]) + ' '.join(file_names[1:]))

Hi @zivy

that’s exactly what I was looking for.

Cheers