PyRadiomics features in relate with pixel spacing, and format conversion between dicom and nrrd

528 views
Skip to first unread message

Jason Z

unread,
Jul 13, 2017, 11:09:22 AM7/13/17
to pyradiomics
Dear pyradiomics developers and users,

I just start using pyradiomics and consider switching my pipeline for feature extraction and radiomics analysis to this platform. 

Before I test it out, I have some quick questions to ask and really appreciate if I can get your clarification: does the pixel size (PixelSpacing in Dicom) of the image affect the feature it calculates?

One of the reasons I ask this is that pyradiomics requires to feed the data in SimpleITK format, and the example data in the package are prepared in NRRD (.nrrd) format (I used to work with dicom).
I noticed there is a "space directions" in the NRRD header, which is comprised of three vectors. Does it have anything to do with the PixelSpacing in Dicom header? I read the NRRD specification, but still not very clear about what it means.

Here are some examples of the header field in some demo NRRD data:
brain1_image.nrrd
space directions: (0.78124999999999989,0,0) (0,-0.78124999999999989,0) (0,0,6.4999999999999982)

prostate_phanton_subvolume.nrrd
space directions: (-0.5,0,0) (0,-0.5,0) (0,0,3)

Do the space directions are related with PixelSpacing, say space directions are equal with PixelSpacing in quantity? Then +/- defines the direction of the vector?
I noticed when I load .nrrd file into simpleITK image, img.GetSpacing() returns (0.7812499999999999, 0.7812499999999999, 6.499999999999998), or (0.5, 0.5, 3).

I used SimpleITK function to read in a dicom series as simpleITK image (img), and then save it to NRRD (.nrrd) file using sitk.WriteImage(img, filename), however, it seems all the spacing information are missing when writing to NRRD file.  
The space directions in the saved nrrd file are unit vectors: (1,0,0) (0,1,0) (0,0,1), even if I set the spacing of the SimpleITK image: img.SetSpacing([0.5, 0.5, 3]) . 

Could you give me some suggestion about how to write the meta information such as (space directions, space origin) in .nrrd with SimpleITK properly?

Thanks for checking this out!


Steve Pieper

unread,
Jul 13, 2017, 11:27:17 AM7/13/17
to Jason Z, pyradiomics
Hi Jason - 

As you probably already know, DICOM data can be tricky because so many different kinds of data can be encoded.  PyRadiomics is restricted to SimpleITK image formats so that things are less ambiguous and we leave it as a task for the user to correctly convert their data to a consistent format.

You may want to start by using the SlicerRadiomics extension so you can visually confirm the data.  In Slicer you can use tools to look at the data [2] and save the nrrd version for comparison.  Of course there are lots of other tools in python [3] and other languages that may help too.

If you want to know more generally about spacing and image directions this may help [4].

Best,
Steve



[3] https://github.com/icometrix/dicom2nifti


--
You received this message because you are subscribed to the Google Groups "pyradiomics" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyradiomics+unsubscribe@googlegroups.com.
To post to this group, send email to pyrad...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyradiomics/0b4dc925-463b-403b-a04e-092d5fd4a5a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joost van Griethuysen

unread,
Jul 14, 2017, 3:35:48 AM7/14/17
to pyradiomics
Dear Jason,

As to the meaning of space directions, this is a combination of pixel size and the transformation matrix (comparable to DICOMs PixelSpacing and Image Orientation (Patient), respectively). 
Point of interest: Image Orientation (Patient) usually gives 6 values, as DICOMs are stored per-slice. the last 3 values are the transformation vector for the 3rd dimension (DICOM stores this information as an origin for each slice).

As to your error: What kind of DICOM series are you trying to convert to NRRD? And how does your converted file look like visually? What I've seen is that if there is some inconsistency in your DICOM series, the vectors default to (1,0,0) (0,1,0) (0,0,1).
Such inconsistencies mainly include missing slices or 4D series.

As mentioned by Steve, converting DICOMs can be tricky. Be sure to check out the [3] dicom2nifti converter, which includes multiple checks before converting your DICOM series to nifti.
Of course, nifti is not nrrd, however, PyRadiomics accepts both formats as input.

Best,

Joost


Op donderdag 13 juli 2017 17:09:22 UTC+2 schreef Jason Z:

Jason Z

unread,
Jul 14, 2017, 10:08:11 AM7/14/17
to pyradiomics
Dear Joost,

Thank you so much for your explanation! 

It is interesting to know how space directions are related to both pixel size and the transformation matrix! I did some further searching and found this [1] to be useful in providing a mathematical explanation about space directions and space origin:
Space directions are essentially the three vectors comprising the transformation matrix between the index space and world space. 

In cases of scan where [i,j,k] of index space direction is in alignment with v1 = (1, 0, 0), v2 = (0, 1, 0), v3 = (0, 0, 1) in world space, the space direction will be related with PixelSpacing and SpacingBetweenSlices in DICOM as
space direction: (PixelSpacing[0], 0, 0), (0, PixelSpacing[1],0), (0, 0, SpacingBetweenSlices)  (Note: there might be +/- in front of the values depend on how the coordinate system is defined)
I have tested it out simpleITK reader when it reads in DICOM series, it sets the vectors default to (1,0,0)(0,1,0)(0,0,1) as you pointed out. In the above situation, you can specify the Image spacing using sitkImage.SetSpacing() function. 
When you save the image to NRRD afterwards, space directions will be written in the output NRRD image. Likewise, you can set space origin in SimpleITK with sitkImage.SetOrigin().

I only tested out the above situation. One may need to dig more into the SimpleITK ReadImage function, and SimpleITK image class to find out how to specify those parameters properly.

I agree with you that it can be pretty complicated to work with the transformation between DICOM and NRRD on one's own, so I think I will go with your and Steve's recommendation of checking out dicom2nifti.

Thank you again for your generous help!

Reply all
Reply to author
Forward
0 new messages