# Extract multiple labels from one image without reloading image and mask data? 

**URL:** <https://discourse.slicer.org/t/extract-multiple-labels-from-one-image-without-reloading-image-and-mask-data/21468>\
**Category:** Radiomics\
**Created:** [January 14, 2022, 7:51pm UTC](https://discourse.slicer.org/t/extract-multiple-labels-from-one-image-without-reloading-image-and-mask-data/21468 "2022-01-14T19:51:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Nagel](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sebastian_nagel/32/3425_2.png) [@Sebastian\_Nagel](https://discourse.slicer.org/u/Sebastian_Nagel)\
**Post date:** [January 14, 2022, 7:51pm UTC](https://discourse.slicer.org/t/extract-multiple-labels-from-one-image-without-reloading-image-and-mask-data/21468/1 "2022-01-14T19:51:20Z")

</div>

Dear Community,

we performed a CT segmentation for which we placed multiple labels into one dataset.

Now when we start extracting the features using either the command line or a Jupyter notebook, the image and mask data need to be loaded for each label, even if they are from the same image data. Is there a way to speed up the extraction in the way that the extractor loads the image and mask once and then goes through all the labels? Loading image and mask into a variable and the parsing it to the extractor speeded up things a little…

Thank you very much in advance!

---

<div class="post-metadata">

**Author:** ![JoostJM](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joostjm/32/1091_2.png) [@JoostJM](https://discourse.slicer.org/u/JoostJM)\
**Post date:** [January 18, 2022, 12:41pm UTC](https://discourse.slicer.org/t/extract-multiple-labels-from-one-image-without-reloading-image-and-mask-data/21468/2 "2022-01-18T12:41:52Z")

</div>

If you do this from a jupyter notebook you can load the image and mask as SimpleITK image objects, which you can pass instead of the path to the corresponding files. Then the image and mask are loaded only once. All other processing steps are repeated for each computation, as they are ROI dependent (e.g. the resampling only resamples the ROI and a limited region around it for computational and memory efficiency).

---

<div class="post-metadata">

**Author:** ![JoostJM](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joostjm/32/1091_2.png) [@JoostJM](https://discourse.slicer.org/u/JoostJM)\
**Post date:** [January 18, 2022, 12:44pm UTC](https://discourse.slicer.org/t/extract-multiple-labels-from-one-image-without-reloading-image-and-mask-data/21468/3 "2022-01-18T12:44:17Z")

</div>

On the commandline there is no option to prevent reloading the image, but you can enable parallel processing to speed things up a bit (`--jobs`). This parallelizes the process on the case level (e.g. each thread processes a single case, multiple threads can run in parallel). Especially handy in case of large datasets.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Nagel](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sebastian_nagel/32/3425_2.png) [@Sebastian\_Nagel](https://discourse.slicer.org/u/Sebastian_Nagel)\
**Post date:** [January 19, 2022, 8:40pm UTC](https://discourse.slicer.org/t/extract-multiple-labels-from-one-image-without-reloading-image-and-mask-data/21468/4 "2022-01-19T20:40:17Z")

</div>

Dear Joost, thank you very much for the responses!

We will try both options, but the latter one is really attractive since we do not have to change much in our setup.
