# Load stacks of files into viewer

**URL:** https://discourse.itk.org/t/load-stacks-of-files-into-viewer/2962
**Category:** Beginner Questions
**Created:** [April 17, 2020, 11:17am UTC](https://discourse.itk.org/t/load-stacks-of-files-into-viewer/2962 "2020-04-17T11:17:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![dpedrosac](https://discourse.itk.org/user_avatar/discourse.itk.org/dpedrosac/32/1389_2.png) [@dpedrosac](https://discourse.itk.org/u/dpedrosac)
#### Post date: [April 17, 2020, 11:17am UTC](https://discourse.itk.org/t/load-stacks-of-files-into-viewer/2962/1 "2020-04-17T11:17:15Z")

</div>

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](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

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [April 17, 2020, 11:54am UTC](https://discourse.itk.org/t/load-stacks-of-files-into-viewer/2962/2 "2020-04-17T11:54:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![dpedrosac](https://discourse.itk.org/user_avatar/discourse.itk.org/dpedrosac/32/1389_2.png) [@dpedrosac](https://discourse.itk.org/u/dpedrosac)
#### Post date: [April 17, 2020, 12:22pm UTC](https://discourse.itk.org/t/load-stacks-of-files-into-viewer/2962/3 "2020-04-17T12:22:12Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [April 17, 2020, 12:43pm UTC](https://discourse.itk.org/t/load-stacks-of-files-into-viewer/2962/4 "2020-04-17T12:43:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [April 17, 2020, 1:35pm UTC](https://discourse.itk.org/t/load-stacks-of-files-into-viewer/2962/5 "2020-04-17T13:35:01Z")

</div>

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](https://discourse.slicer.org/t/how-to-load-4d-images-in-slicer-fmri-or-asl-datasets/1157/5)). I’m not a slicer expert so not sure if you can do this programmatically/commandline.

Using ITK-SNAP:

```auto
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:]))

```

---

<div class="post-metadata">

### Author: ![dpedrosac](https://discourse.itk.org/user_avatar/discourse.itk.org/dpedrosac/32/1389_2.png) [@dpedrosac](https://discourse.itk.org/u/dpedrosac)
#### Post date: [April 18, 2020, 8:15am UTC](https://discourse.itk.org/t/load-stacks-of-files-into-viewer/2962/6 "2020-04-18T08:15:05Z")

</div>

Hi @zivy

that’s exactly what I was looking for.

Cheers
