# How to save MRMLCore.vtkMRMLSequenceNode to a number of images

**URL:** <https://discourse.slicer.org/t/how-to-save-mrmlcore-vtkmrmlsequencenode-to-a-number-of-images/20559>\
**Category:** Development\
**Tags:** python\
**Created:** [November 10, 2021, 3:33am UTC](https://discourse.slicer.org/t/how-to-save-mrmlcore-vtkmrmlsequencenode-to-a-number-of-images/20559 "2021-11-10T03:33:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Illusion](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@Illusion](https://discourse.slicer.org/u/Illusion)\
**Post date:** [November 10, 2021, 3:33am UTC](https://discourse.slicer.org/t/how-to-save-mrmlcore-vtkmrmlsequencenode-to-a-number-of-images/20559/1 "2021-11-10T03:33:13Z")

</div>

Operating system: Windows 10  
Slicer version: 4.13.0

Hello,

I am trying to write codes in Jupyter to convert a sequence of images to numpy array, in order to save the sequence to images.

Currently, I can get the MRMLCore.vtkMRMLSequenceNode using

```auto
im_seq_1 = slicer.util.getNode('Sequence_1_Im')

```

however, could not move forward.

Could anyone please let me know how should I convert `im_seq_1` or save it to images?

Thank you very much in advance!

---

<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:** [November 10, 2021, 3:59am UTC](https://discourse.slicer.org/t/how-to-save-mrmlcore-vtkmrmlsequencenode-to-a-number-of-images/20559/2 "2021-11-10T03:59:03Z")

</div>

[This example](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#access-voxels-of-a-4d-volume-as-a-single-numpy-array) in the script repository should help.

What format would you like to write the image sequence to?

---

<div class="post-metadata">

**Author:** ![Illusion](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@Illusion](https://discourse.slicer.org/u/Illusion)\
**Post date:** [November 10, 2021, 4:09am UTC](https://discourse.slicer.org/t/how-to-save-mrmlcore-vtkmrmlsequencenode-to-a-number-of-images/20559/3 "2021-11-10T04:09:14Z")

</div>

Thank you so much, Andras! That example helps a lot!  
I would like to save as an uncompressed data format or raw data. Not sure which is better for viewing and editing yet.

---

<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:** [November 10, 2021, 4:13am UTC](https://discourse.slicer.org/t/how-to-save-mrmlcore-vtkmrmlsequencenode-to-a-number-of-images/20559/4 "2021-11-10T04:13:35Z")

</div>

You can save the image sequence as an uncompressed raw file and a separate header file (you must have that to be able to interpret the data correctly) using File / Save. Choose “.seq.nhdr” file format, enable “Show options” and uncheck “Compress” option:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/1/211e9b405f23277f492bed8c0b93a1e06dd400b7.png)

---

<div class="post-metadata">

**Author:** ![Illusion](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@Illusion](https://discourse.slicer.org/u/Illusion)\
**Post date:** [November 10, 2021, 4:32am UTC](https://discourse.slicer.org/t/how-to-save-mrmlcore-vtkmrmlsequencenode-to-a-number-of-images/20559/5 "2021-11-10T04:32:06Z")

</div>

Thank you so much!

Just wondering is it possible to save to \*.npy file, which is convenient for further processing?

---

<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:** [November 10, 2021, 4:35am UTC](https://discourse.slicer.org/t/how-to-save-mrmlcore-vtkmrmlsequencenode-to-a-number-of-images/20559/6 "2021-11-10T04:35:17Z")

</div>

A numpy file does not store all metadata that must be preserved (such as image origin, spacing, axis directions, axis kinds, sequence axis type, name, unit, values), therefore I would recommend to use nrrd format. If you don’t need any metadata just the voxels as a numpy array then you can read the nrrd file using pynrrd.

What further processing would you like to do in what software?

---

<div class="post-metadata">

**Author:** ![Illusion](https://avatars.discourse-cdn.com/v4/letter/i/e19b73/32.png) [@Illusion](https://discourse.slicer.org/u/Illusion)\
**Post date:** [November 11, 2021, 2:37pm UTC](https://discourse.slicer.org/t/how-to-save-mrmlcore-vtkmrmlsequencenode-to-a-number-of-images/20559/7 "2021-11-11T14:37:31Z")

</div>

Thank you, Andras! The pynrrd can help a lot.

I would like to label two pixels for every single 2D image in the sequence, probably manually, not sure how to do it in an efficient way.

---

<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:** [November 11, 2021, 2:56pm UTC](https://discourse.slicer.org/t/how-to-save-mrmlcore-vtkmrmlsequencenode-to-a-number-of-images/20559/8 "2021-11-11T14:56:09Z")

</div>

Do you want to define two trajectories (nerves, vessels, etc.) running across the volume? If yes, then it is much faster to define that using a curve and then set the voxels from the curve points.

If you tell us about your overall goal then we can give advice on how to achieve that. It is important to make sure that the high-level workflow is good before discussing minor implementation details.
