[Windows] slicer.util.loadVolume loads wrong volume

Hi developers,

I am having the following problems under Windows when programmatically loading a volume. Always the wrong volume is loaded into Slicer. The directory that I shared here has two volumes:

a. MRI Prostate image (two files)
b. ZFrame template (one file)

Please try the following on Windows:

load prostate image

This is supposed to load the prostate volume, but it doesn’t. It loads the template image which is located in the same directory.

prostateVolume = slicer.util.loadVolume(‘a000001.dcm’, returnNode=True)

##load template image

templateVolume = slicer.util.loadVolume(‘b000001.dcm’, returnNode=True)

Does anyone know what the problem is here? Those issues neither occur on MacOS nor on Ubuntu.

I noticed that when using the “add data” dialog sometimes the files are classified as “Scalar overlay” which is not loaded correctly.

Thanks
Christian

I guess you need to specify that it should be loaded as a single file and not as a multi-file DICOM series:

prostateVolume = slicer.util.loadVolume('a000001.dcm', {'singleFile': True}, returnNode=True)

It works with the setting singleFile to True but that doesn’t solve the problem since the dataset has more than one slice. a000001.dcm and a000002.dcm belong to the same dataset.

And it doesn’t explain why it works as expected on Ubuntu and MacOS without even adding anything else than I am using in the first post.

When I manually selected the file in the “add data”-dialog and set explicitly description to “Volume” then it works even when I uncheck property singleFile

I’ve debugged into this and the problem is caused by using backslash path separator character or drive letter capitalization. I’ve made file comparison mechanism more robust (normalizing filenames before comparison) in r26146, which should fix the problem.

1 Like

I am glad that you found something. I will try with the next nightly build. Thanks a lot!

@che85 why would you want to use this loader for a DICOM series instead of the ScalarVolume DICOM plugin?

We used to do that in SliceTracker and I was not looking for a workaround. We can switch to that if you prefer.

I didn’t realize this is going on. I would definitely switch to the DICOM plugin. Most likely, that util function is just using straight ITK reader, since it is the same call that is used to read non-DICOM data.

Ultimately, scalar images are always read by ITK reader. The difference is how the list of files is determined and how they deal with inconsistencies (varying spacing, non-parallel slices, etc).

ScalarVolume DICOM plugin requires a list of files (files may spread across various folders) and the plugin sorts all the files and provides the file list to the ITK reader.

When you load a DICOM volume using slicer.util.loadVolume then the ITK reader receives only a single filename and the ITK reader determines the file list (it considers filenames in the same folder, checks series UID match, and sorts based on image position patient).

1 Like