# Loading a .bmp sequence from directory as a LabelMap

**URL:** <https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802>\
**Category:** Support\
**Tags:** segmentation, volume, 3d-model, file-import\
**Created:** [August 17, 2022, 10:27am UTC](https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802 "2022-08-17T10:27:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Windy](https://avatars.discourse-cdn.com/v4/letter/w/91b2a8/32.png) [@Windy](https://discourse.slicer.org/u/Windy)\
**Post date:** [August 17, 2022, 10:27am UTC](https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802/1 "2022-08-17T10:27:24Z")

</div>

Operating system: Windows 10 Education  
Slicer version: 5.0.2

Expected behavior:  
I have a set of segmented slices in a directory. It has 2 classes (0 and 255). The image format is .bmp. I want to load them as a segmentation.

Actual behavior:  
I was following the [official docs](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmentations.html#import-an-existing-segmentation-from-volume-file). However, when I load as a volume and select `LabelMap` it gives the following error.

```auto
UpdateFromSeries: Unsupported number of components: 1 != 3

vtkMRMLVolumeArchetypeStorageNode::ReadDataInternal: Cannot read file as a volume of type LabelMapVolume [fullName = D:/roi_1_resampled/labelled/masks/dilate_roi_1_resampled_0476.bmp]: FileFormatError. Number of files listed in the node = 0. File reader says it was able to read 816 files. File reader used the archetype file name of D:/roi_1_resampled/labelled/masks/dilate_roi_1_resampled_0476.bmp [reader 0th file name = D:/roi_1_resampled/labelled/masks/dilate_roi_1_resampled_0476.bmp].

vtkMRMLStorageNode::ReadData: Failed to read node dilate_roi_1_resampled_0476_2 (vtkMRMLLabelMapVolumeNode1) from filename='D:/roi_1_resampled/labelled/masks/dilate_roi_1_resampled_0476.bmp'

```

---

<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 17, 2022, 4:39pm UTC](https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802/2 "2022-08-17T16:39:46Z")

</div>

You can try using the ImageStacks module from SlicerMorph instead - it has more options and should work for you.

> **[SlicerMorph/Docs/ImageStacks at master · SlicerMorph/SlicerMorph](https://github.com/SlicerMorph/SlicerMorph/tree/master/Docs/ImageStacks)**
>
> master/Docs/ImageStacks

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [August 17, 2022, 11:30pm UTC](https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802/3 "2022-08-17T23:30:58Z")

</div>

> [@Windy](#):
>
> I was following the [official docs](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmentations.html#import-an-existing-segmentation-from-volume-file). However, when I load as a volume and select `LabelMap` it gives the following error.

Labelmap conversion from image sequences is a two step process: IMport then convert. I don’t think you can directly import an image stack as a labelmap. (Instructions you shared are for volumes that are already in NRRD or other Slicer compatible volumetric formats like NRRD or NIFTI).

The simplest solution is to use the ImageStacks from SlicerMorph extension as @pieper indicated. Once you import the volume, right click on it in the Data module, and choose “edit properties”, which wil take you to the volumes module. Expand the Volume Information tab, and click the button that says **Convert**.

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/4/34ba449b61169a7daee985a3ec21d6d9936f68f9.png).

Slicer does not use labelmaps for segmentations anymore. If you want to continue your segmentation in slicer (or create models out of these segmentations). You have one more step where you convert the labelmap to segmentation object. You can easily do that by right clicking the new labelmap object in the data module and choosing **“Convert labelmap to Segmentation Node”.**

Remember to save these so that you don’t have to keep repeating these stesp.

---

<div class="post-metadata">

**Author:** ![Windy](https://avatars.discourse-cdn.com/v4/letter/w/91b2a8/32.png) [@Windy](https://discourse.slicer.org/u/Windy)\
**Post date:** [August 18, 2022, 4:42am UTC](https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802/4 "2022-08-18T04:42:47Z")

</div>

Actually, the second part in that link says it works with any image format.

I followed the steps you mentioned. but I don’t get the convert button.

---

<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 18, 2022, 2:23pm UTC](https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802/5 "2022-08-18T14:23:29Z")

</div>

> [@Windy](#):
>
> I followed the steps you mentioned. but I don’t get the convert button.

What do you see instead in the window corresponding to what @muratmaga posted?

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [August 18, 2022, 4:58pm UTC](https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802/6 "2022-08-18T16:58:07Z")

</div>

> [@Windy](#):
>
> says it works with any image format

Thanks for point it out. That probably needs to be corrected, Slicer treats JPG/PNG/BMP as vector (RGB) images, whereas a labelmap is a scalar image. I expect that was the reason for the error you posted:

```auto
UpdateFromSeries: Unsupported number of components: 1 != 3

```

As for your current question, please provide a screenshot of the VOlumes module with the Volume Information tab expanded.

---

<div class="post-metadata">

**Author:** ![Windy](https://avatars.discourse-cdn.com/v4/letter/w/91b2a8/32.png) [@Windy](https://discourse.slicer.org/u/Windy)\
**Post date:** [August 24, 2022, 5:42am UTC](https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802/7 "2022-08-24T05:42:59Z")

</div>

![Capture23](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/2/02b40075453584c854a4b757f41984d7139499e7.png)

---

<div class="post-metadata">

**Author:** ![Windy](https://avatars.discourse-cdn.com/v4/letter/w/91b2a8/32.png) [@Windy](https://discourse.slicer.org/u/Windy)\
**Post date:** [August 24, 2022, 5:54am UTC](https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802/8 "2022-08-24T05:54:42Z")

</div>

Thank you for trying to help. I just went ahead and created a Nifti stack from the BMPs and imported as segmentations

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [August 24, 2022, 2:53pm UTC](https://discourse.slicer.org/t/loading-a-bmp-sequence-from-directory-as-a-labelmap/24802/9 "2022-08-24T14:53:34Z")

</div>

From your screenshot above the issue is the same, if you look at the NUmber of Scalars you see it is 3 (implying a RGB volume), not 1. I suspect the voxel spacing is incorrect. Again, you can take care all of those using ImageStacks module.
