Get image data from reformatted CT volume slice

Hello,

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,

Best,

David

arrayFromVolume is what you need I think. https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.arrayFromVolume

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 )

Hi,

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?

Thanks!

David

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!

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

David

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

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_reformatted_image_from_a_slice_viewer_as_numpy_array

1 Like

Quite useful! Thank you Andras!