# \[Windows\] slicer.util.loadVolume loads wrong volume

**URL:** <https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641>\
**Category:** Support\
**Created:** [July 6, 2017, 10:42pm UTC](https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641 "2017-07-06T22:42:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![che85](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/che85/32/636_2.png) [@che85](https://discourse.slicer.org/u/che85)\
**Post date:** [July 6, 2017, 10:42pm UTC](https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641/1 "2017-07-06T22:42:31Z")

</div>

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)
`

> **[Dropbox - Error](https://www.dropbox.com/sh/klhh0566rggt0o5/AAB9vVwULXBNbfnag3tEB50sa?dl=0)**
>
> Dropbox is a free service that lets you bring your photos, docs, and videos anywhere and share them easily. Never email yourself a file again!

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 6, 2017, 11:03pm UTC](https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641/2 "2017-07-06T23:03:58Z")

</div>

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)
```

---

<div class="post-metadata">

**Author:** ![che85](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/che85/32/636_2.png) [@che85](https://discourse.slicer.org/u/che85)\
**Post date:** [July 7, 2017, 1:18am UTC](https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641/3 "2017-07-07T01:18:26Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 7, 2017, 4:49am UTC](https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641/4 "2017-07-07T04:49:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![che85](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/che85/32/636_2.png) [@che85](https://discourse.slicer.org/u/che85)\
**Post date:** [July 7, 2017, 1:40pm UTC](https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641/5 "2017-07-07T13:40:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [July 7, 2017, 2:24pm UTC](https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641/6 "2017-07-07T14:24:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![che85](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/che85/32/636_2.png) [@che85](https://discourse.slicer.org/u/che85)\
**Post date:** [July 7, 2017, 2:39pm UTC](https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641/7 "2017-07-07T14:39:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [July 7, 2017, 2:49pm UTC](https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641/8 "2017-07-07T14:49:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 7, 2017, 3:06pm UTC](https://discourse.slicer.org/t/windows-slicer-util-loadvolume-loads-wrong-volume/641/9 "2017-07-07T15:06:26Z")

</div>

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).
