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
muratmaga
(Murat Maga)
February 14, 2019, 7:04am
2
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
cpinter
(Csaba Pinter)
February 18, 2019, 5:53pm
4
What comes to mind are the transforms that take you from RAS to slice view XY or back, see these functions for example
/// Convert RAS position to XY in-slice position
static QPoint rasToXy(double ras[3], qMRMLSliceWidget* sliceWidget);
/// Convert RAS position to XY in-slice position, python accessor method
Q_INVOKABLE static QPoint rasToXy(QVector3D ras, qMRMLSliceWidget* sliceWidget);
/// Convert XYZ slice view position to RAS position:
/// x,y uses slice (canvas) coordinate system and actually has a 3rd z component (index into the
/// slice you're looking at), hence xyToRAS is really performing xyzToRAS. RAS is patient world
/// coordinate system. Note the 1 is because the transform uses homogeneous coordinates.
static void xyzToRas(double inputXyz[3], double outputRas[3], qMRMLSliceWidget* sliceWidget);
/// Convert XYZ slice view position to RAS position, python accessor method
Q_INVOKABLE static QVector3D xyzToRas(QVector3D inputXyz, qMRMLSliceWidget* sliceWidget);
/// Convert XY in-slice position to RAS position
static void xyToRas(QPoint xy, double outputRas[3], qMRMLSliceWidget* sliceWidget);
/// Convert XY in-slice position to RAS position
static void xyToRas(double xy[2], double outputRas[3], qMRMLSliceWidget* sliceWidget);
/// Convert XY in-slice position to RAS position, python accessor method
Q_INVOKABLE static QVector3D xyToRas(QPoint xy, qMRMLSliceWidget* sliceWidget);
/// Convert XYZ slice view position to image IJK position, \sa xyzToRas
static void xyzToIjk(double inputXyz[3], int outputIjk[3], qMRMLSliceWidget* sliceWidget, vtkOrientedImageData* image);
/// Convert XYZ slice view position to image IJK position, python accessor method, \sa xyzToRas
This file has been truncated. show original
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
lassoan
(Andras Lasso)
February 20, 2019, 2:08pm
6
1 Like
Quite useful! Thank you Andras!