Getting vtkMRMLSliceNodeGreen, vtkMRMLSliceNodeRed, vtkMRMLSliceNodeYellow data into numpy array

Hello Everyone

I am new to slicer.
I can import NRRD file and see the 3 views (sagittal, coronal and transverse), and I can use 3DSlicer to save them as png file for each of the 3 views (by using ScreenCapture.ScreenCaptureLogic().captureSliceSweep). But I do not know how to get these values into numpy array. I think this is only giving me for one of the views,

refNodeName = 'knee'
        refPath = os.path.join(refPath, refNodeName + ".nrrd")
        slicer.util.loadNodeFromFile(refPath, 'VolumeFile')
        node=slicer.util.getFirstNodeByName(refNodeName)
        array = slicer.util.array(refNodeName)
        print(array.shape, array.ndim)

Is there a way to access the 3 views/planes and get the data into Numpy Array.
Hope I could explain it properly.

Thanks

dm

The best approach depends on what you would like to achieve. Could you give a bit more information about your use case? What would you like to do with the numpy array?

Hello,

I can save it in a text file for further processing.
I have been looking for code snippets which does this, but have not come across any.
Can you please guide me to the right direction. I feel like perhaps this is something very standard but I do not know how to do it yet.

Also I am looking into loading 3D volume from NRRD file into numpy array or merging slices to generate the 3D volume, but that can be a separate topic.

Thanks!

dm

While it does not sound like a good idea (text representation for an image is extremely inefficient), you can certainly do this if you have your data in a numpy array. In my question I meant what you actually want to do (beyond writing to file).

This is already available. Check out Slicer programming tutorials and Slicer script repository. If you have any questions then you can post them here.