How to save MRMLCore.vtkMRMLSequenceNode to a number of images

Operating system: Windows 10
Slicer version: 4.13.0


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

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!

This example in the script repository should help.

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

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.

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:

Thank you so much!

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

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?

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.

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.