[ITK-users] SimpleITK, read MHD volume and convert it into a numpy array respecting its transformation

Lowekamp, Bradley (NIH/NLM/LHC) [C] blowekamp at mail.nih.gov
Thu May 5 09:18:33 EDT 2016


Hi,

One of the key feature of ITK is that images are not just voxel, but oriented object that have a physical location. This is why the Image class has associated with the an Origin, Spacing, and Direction. You can use the Image::TransformIndexToPhysicalPoint to see this mapping. Also print the SimpleITK image and look at these attributes.

The ResampleImageFilter applies a geometric transform from the input image's physical space to the output image's physical space defined by the Output parameters of the ResampleImageFiler. In your first attempt, your input image and output image are in the same physical space so it is expected that they would be the same. The input and output image maintain the same meta-data, because of the call the SetReferenceIamge(img).

From your initial post, it sounds like you want to resample a set of images to a common reference frame. So you need to define that common reference image’s origin, spacing, direction, and size. And use that information in the ResampleImageFilter. This assumes that you don’t want to change the physical location of the image.

HTH,
Brad

On May 4, 2016, at 4:17 PM, fausto milletarì <fausto.milletari at gmail.com<mailto:fausto.milletari at gmail.com>> wrote:

Hello,

just as a brief attempt i tried:

resample=sitk.ResampleImageFilter()
resample.SetReferenceImage(img)
resample.SetOutputDirection(img.GetDirection())

Seems that, after I obtain the numpy array as:

test=resample.Execute(img)
volume=sitk.GetArrayFromImage(test)

Nothing changes in terms of data array.

If I also add resample.SetOutputSpacing(img.GetSpacing()/2.) then the numpy array changes and depicts a down-sampled version of the image.

I suspect i have to use resample.SetTransform() but I will need to create this transform using one of the transform types available in sitk. How can I create a transform that is equivalent to the one contained in the header of my MHD file? Should I create a transform starting from the volume direction and maybe offset? I could not find any example of this so far…


Best regards and thanks much for your help and your answers,

Fausto





On 04 May 2016, at 20:40, fausto milletarì <fausto.milletari at gmail.com<mailto:fausto.milletari at gmail.com>> wrote:

Hello,

I thank you for you fast and accurate answer. This was exactly what I was looking for. Actually I don’t need to visualise the data but further process it in a common reference frame. I think that your answer solves the problem. I will look into the ResampleImageFilter (that so far I was using only to adjust the resolution of different volumes acquired with different scanners to a common one).


Thanks a lot!

Fausto Milletari
On 04 May 2016, at 20:36, Lowekamp, Bradley (NIH/NLM/LHC) [C] <blowekamp at mail.nih.gov<mailto:blowekamp at mail.nih.gov>> wrote:

Hello,

If I understand you correctly you want to rotate the image and pad it for visualization before exporting to numpy.

Have you looked into the ResampleImageFilter? It accepts a transform, along with output image geometry so that you can readily manipulate the image for display. You also may want to scale the image’s intensity with a WindowLevelImageFilter for better visualization of the range of interest.

HTH,
Brad

On May 4, 2016, at 1:14 PM, fausto milletarì <fausto.milletari at gmail.com<mailto:fausto.milletari at gmail.com>> wrote:

Hello everyone,

I have a probably naive question about simpleITK. I find simpleITK extremely useful to process medical data such as MRI scans but I would like also to enjoy being able to convert my images in numpy format while respecting the transformation of the volume.

In other words I would like to get the MRI image in numpy rotated by the correct amount around each axis with zero padding for example.

when i do simply sitk.GetArrayFromImage(imgResampledCropped)I get back the raw data itself, but what I would like to do is to have a numpy array that contains the data “ready to visualise” by simple slicing of the array itself.

Do you think this is doable? Is there a standard way of doing it?



Kind regards,

Fausto

_____________________________________
Powered by www.kitware.com<http://www.kitware.com/>

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20160505/8d2204a3/attachment-0001.html>


More information about the Insight-users mailing list