# How to open a file as a LabelMap from command line?

**URL:** <https://discourse.slicer.org/t/how-to-open-a-file-as-a-labelmap-from-command-line/876>\
**Category:** Support\
**Created:** [August 15, 2017, 4:42pm UTC](https://discourse.slicer.org/t/how-to-open-a-file-as-a-labelmap-from-command-line/876 "2017-08-15T16:42:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valerie\_Sydnor](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@Valerie\_Sydnor](https://discourse.slicer.org/u/Valerie_Sydnor)\
**Post date:** [August 15, 2017, 4:42pm UTC](https://discourse.slicer.org/t/how-to-open-a-file-as-a-labelmap-from-command-line/876/1 "2017-08-15T16:42:35Z")

</div>

Operating system: Linux  
Slicer version: 4.5.0  
Expected behavior: LabelMap file will open as a Volume with “LabelMap” checked in Volume Information, and will appear as Current LabelMapVolume in the display  
Actual behavior: LabelMap file opens as a regular volume

Hi,

Is there a way to specify that a given image/file is a LabelMap when opening the image/file with Slicer from the command line? Currently,

---

<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:** [August 15, 2017, 4:51pm UTC](https://discourse.slicer.org/t/how-to-open-a-file-as-a-labelmap-from-command-line/876/2 "2017-08-15T16:51:00Z")

</div>

It should work well. What command did you use?

---

<div class="post-metadata">

**Author:** ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)\
**Post date:** [August 15, 2017, 6:27pm UTC](https://discourse.slicer.org/t/how-to-open-a-file-as-a-labelmap-from-command-line/876/3 "2017-08-15T18:27:35Z")

</div>

Have you tried this?

> <https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/util.py#L341-L344>

---

<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:** [August 15, 2017, 6:51pm UTC](https://discourse.slicer.org/t/how-to-open-a-file-as-a-labelmap-from-command-line/876/4 "2017-08-15T18:51:25Z")

</div>

Indeed, it does not load as a label map even if I rename the file to include `-label` prefix.

@lassoan @Fernando the user is asking how to load as label map from the command line (passing the file name as an argument to the Slicer application from command line, I assume), not programmatically.

---

<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:** [August 15, 2017, 7:08pm UTC](https://discourse.slicer.org/t/how-to-open-a-file-as-a-labelmap-from-command-line/876/5 "2017-08-15T19:08:51Z")

</div>

This works for me on a recent nightly version:

```
slicer.util.loadLabelVolume(r'c:\Users\msliv\Documents\test.nrrd')

```

Could you test if it works for you, too?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [August 15, 2017, 7:14pm UTC](https://discourse.slicer.org/t/how-to-open-a-file-as-a-labelmap-from-command-line/876/6 "2017-08-15T19:14:58Z")

</div>

Or to use that from the command line:

```auto
~/Desktop/Slicer.app/Contents/MacOS/Slicer --python-code "slicer.util.loadLabelVolume('/Users/pieper/data/shere.nrrd')"

```

---

<div class="post-metadata">

**Author:** ![Valerie\_Sydnor](https://avatars.discourse-cdn.com/v4/letter/v/838e76/32.png) [@Valerie\_Sydnor](https://discourse.slicer.org/u/Valerie_Sydnor)\
**Post date:** [August 15, 2017, 8:02pm UTC](https://discourse.slicer.org/t/how-to-open-a-file-as-a-labelmap-from-command-line/876/7 "2017-08-15T20:02:26Z")

</div>

Yes I was looking to load a label map from the command line, passing the file.nrrd as an argument to Slicer as @fedorov indicated.  
@pieper’s solution is just what I was looking for! Thanks to all.
