Loading nrrd data in python Jupyter notebook script


I am new working with the PyRadiomics package and I have a very basic question. How to load in the data in the Jupyter Notebook script?
I used 3D slicer to perform a segmentation on a PET image and I want to load this in the PyRadiomics package on python. However, I am not sure where to start with loading the nrrd file. I downloaded the pynrrd package (not even sure if this is necessary) but when I perform ‘import pynrrd’ it already gives the error that there is no module named ‘nrrd’.

So therefore, my question is, what is the first step in loading a dataset?

Thank you!

You need to install pynrrd and import nrrd.

If you want to load a nrrd file into a volume node then you can use loadVolume function.

Thank you for your answer! Is it correct that the load volume function is used in 3D slicer? Since I cannot find a Python package what supports this. I am actually searching for a method that can load the nrrd data files in Python so I can perform feature extraction using PyRadiomics.

You can load nrrd images into numpy array without using Slicer using the pynrrd or similar package. This is used for example in slicerio for reading segmentations from nrrd files.

Hi Mr Lasso,

Apologies for bringing up an old thread as I am also a Slicer beginner. I am also trying to load an nrrd image into numpy array in Python. However, I am struggling to make sense of the output of the numpy array. What does it mean that I get an array of all 0s and how does one interpret this? I am also not sure what to make of the headers. Do let me know if this is not the appropriate place to post this and if I should try another forum. Thank you! :slight_smile:

You only see the first and last values in a couple of rows and columns. If the image has a black border it is fine to have all zeros there. You can check the minimum and maximum value in the array to see if indeed all you have is zeros.

1 Like

Thank you so much for the very quick reply!