Get image data from reformatted CT volume slice


(David Garcia Mato) #1


I need to get image data (meaning pixel/voxel values) from a reformatted CT volume slice.

I have developed a simple scripted module to load a CT volume and used the “Reformat” module in Slicer to reformat a CT slice to contain 3 predefined fiducials. Now, I would like to obtain the image data from that reformatted slice, meaning pixel/voxel values.

Is there a simple way to get that information?

I would really appreciate your help,

Thank you very much in advance,



(Murat Maga) #2

arrayFromVolume is what you need I think.

in the example below, a is the integer array of pixel values for the MRHead.

import SampleData

sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = sampleDataLogic.downloadMRHead()
a = arrayFromVolume(masterVolumeNode )

(David Garcia Mato) #3


I have just tried that, but “arrayFromVolume” method gives me the whole volume (3D matrix). How can I get just the pixel values of my reformatted slice?



(Csaba Pinter) #4

What comes to mind are the transforms that take you from RAS to slice view XY or back, see these functions for example

This example might also be useful from the Threshold effect that takes the image from a slice view:

I’m not sure if there is anything specific to using the Reformat module that these ideas don’t take into account, but I hope this helps!

(David Garcia Mato) #5

Thanks @cpinter!! I think that’s what I needed!


(Andras Lasso) #6

There is also a short example showing how to get resliced image as a volume node and access it as a numpy array:

(David Garcia Mato) #7

Quite useful! Thank you Andras!