# Get image data from reformatted CT volume slice

**URL:** <https://discourse.slicer.org/t/get-image-data-from-reformatted-ct-volume-slice/5772>\
**Category:** Development\
**Tags:** volume, reformat\
**Created:** [February 13, 2019, 11:45pm UTC](https://discourse.slicer.org/t/get-image-data-from-reformatted-ct-volume-slice/5772 "2019-02-13T23:45:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DAVID\_GARCIA\_MATO](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_garcia_mato/32/2712_2.png) [@DAVID\_GARCIA\_MATO](https://discourse.slicer.org/u/DAVID_GARCIA_MATO)\
**Post date:** [February 13, 2019, 11:45pm UTC](https://discourse.slicer.org/t/get-image-data-from-reformatted-ct-volume-slice/5772/1 "2019-02-13T23:45:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 14, 2019, 7:04am UTC](https://discourse.slicer.org/t/get-image-data-from-reformatted-ct-volume-slice/5772/2 "2019-02-14T07:04:05Z")

</div>

arrayFromVolume is what you need I think. [https://slicer.readthedocs.io/en/latest/developer\_guide/slicer.html#slicer.util.arrayFromVolume](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 )

---

<div class="post-metadata">

**Author:** ![DAVID\_GARCIA\_MATO](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_garcia_mato/32/2712_2.png) [@DAVID\_GARCIA\_MATO](https://discourse.slicer.org/u/DAVID_GARCIA_MATO)\
**Post date:** [February 18, 2019, 4:37pm UTC](https://discourse.slicer.org/t/get-image-data-from-reformatted-ct-volume-slice/5772/3 "2019-02-18T16:37:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [February 18, 2019, 5:53pm UTC](https://discourse.slicer.org/t/get-image-data-from-reformatted-ct-volume-slice/5772/4 "2019-02-18T17:53:25Z")

</div>

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

> <https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Segmentations/EditorEffects/qSlicerSegmentEditorAbstractEffect.h#L340-L366>

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

> <https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Segmentations/EditorEffects/Python/SegmentEditorThresholdEffect.py#L382-L405>

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!

---

<div class="post-metadata">

**Author:** ![DAVID\_GARCIA\_MATO](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_garcia_mato/32/2712_2.png) [@DAVID\_GARCIA\_MATO](https://discourse.slicer.org/u/DAVID_GARCIA_MATO)\
**Post date:** [February 18, 2019, 6:19pm UTC](https://discourse.slicer.org/t/get-image-data-from-reformatted-ct-volume-slice/5772/5 "2019-02-18T18:19:46Z")

</div>

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

David

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 20, 2019, 2:08pm UTC](https://discourse.slicer.org/t/get-image-data-from-reformatted-ct-volume-slice/5772/6 "2019-02-20T14:08:32Z")

</div>

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](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_reformatted_image_from_a_slice_viewer_as_numpy_array)

---

<div class="post-metadata">

**Author:** ![DAVID\_GARCIA\_MATO](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_garcia_mato/32/2712_2.png) [@DAVID\_GARCIA\_MATO](https://discourse.slicer.org/u/DAVID_GARCIA_MATO)\
**Post date:** [February 21, 2019, 1:40am UTC](https://discourse.slicer.org/t/get-image-data-from-reformatted-ct-volume-slice/5772/7 "2019-02-21T01:40:46Z")

</div>

Quite useful! Thank you Andras!
