Extracting Pyradiomics from 2D images

191 views
Skip to first unread message

Leonardo Ferreira Machado

unread,
Apr 12, 2019, 1:08:12 PM4/12/19
to pyradiomics
Guys, 

I am having a hard time extracting pyradiomics from 2D images. I saved them  ".nrrd" extensions. And I am having some problems with GLRLM features some shows up as NAN and Infinity. Plus, I am getting tons of error messages related to that. The log error is posted next.

/home/leonardo/.virtualenvs/py2/local/lib/python2.7/site-packages/radiomics/glrlm.py:392: RuntimeWarning: divide by zero encountered in divide
 srlgle
= numpy.sum((self.P_glrlm / ((ivector[:, None, None] ** 2) * (jvector[None, :, None] ** 2))),
/home/leonardo/.virtualenvs/py2/local/lib/python2.7/site-packages/radiomics/glrlm.py:392: RuntimeWarning: invalid value encountered in divide
 srlgle
= numpy.sum((self.P_glrlm / ((ivector[:, None, None] ** 2) * (jvector[None, :, None] ** 2))),
/home/leonardo/.virtualenvs/py2/local/lib/python2.7/site-packages/radiomics/glrlm.py:359: RuntimeWarning: divide by zero encountered in divide
 lglre
= numpy.sum((pg / (ivector[:, None] ** 2)), 0) / Nz
/home/leonardo/.virtualenvs/py2/local/lib/python2.7/site-packages/radiomics/glrlm.py:426: RuntimeWarning: divide by zero encountered in divide
 lrlgle
= numpy.sum((self.P_glrlm * (jvector[None, :, None] ** 2) / (ivector[:, None, None] ** 2)),
/home/leonardo/.virtualenvs/py2/local/lib/python2.7/site-packages/radiomics/glrlm.py:426: RuntimeWarning: invalid value encountered in divide
 lrlgle
= numpy.sum((self.P_glrlm * (jvector[None, :, None] ** 2) / (ivector[:, None, None] ** 2)),

And the features are outputted 
 
ShortRunLowGrayLevelEmphasis : nan
 
GrayLevelVariance : 14562.970678045753
 
LowGrayLevelRunEmphasis : inf
 
GrayLevelNonUniformityNormalized : 0.007172387614434224
 
RunVariance : 0.0226440092909585
 
GrayLevelNonUniformity : 8.153393022567691
 
LongRunEmphasis : 1.0658231417085313
 
ShortRunHighGrayLevelEmphasis : 19090.72834751612
 
RunLengthNonUniformity : 1090.7300512347606
 
ShortRunEmphasis : 0.9844110690710826
 
LongRunHighGrayLevelEmphasis : 20037.37355119618
 
RunPercentage : 0.9791128337639966
 
LongRunLowGrayLevelEmphasis : nan
 
RunEntropy : 7.617423779542989
 
HighGrayLevelRunEmphasis : 19278.89648888804
 
RunLengthNonUniformityNormalized : 0.9594851476987207



Thanks in advance!

Joost van Griethuysen

unread,
Apr 15, 2019, 4:23:31 AM4/15/19
to pyradiomics
Can you share an example image, mask and parameter file? At first glance, it looks like there is a 0 somewhere in the ivector (=gray levels), but that should be prevented by the discretization step.

Regards,

Joost

Op vrijdag 12 april 2019 19:08:12 UTC+2 schreef Leonardo Ferreira Machado:

Leonardo Ferreira Machado

unread,
Apr 16, 2019, 1:28:13 PM4/16/19
to pyradiomics
Hey Joost. Sure.

There It goes the settings section. I don't use a separate settings file, rather a section in the .py file:

#!/usr/bin/env python

from __future__ import print_function

import os

import sys

import numpy as np
import SimpleITK as sitk
import six

import radiomics

input_imageName
= "0199162B-slice.nrrd"
input_maskName
= "0199162B-slice-label.nrrd"
patient_id
= "0199162B"

reader
= sitk.ImageFileReader()
reader
.SetFileName(input_imageName)
reader
.ReadImageInformation()
image
= reader.Execute()

reader
= sitk.ImageFileReader()
reader
.SetFileName(input_maskName)
reader
.ReadImageInformation()
mask
= reader.Execute()

settings
= {'binWidth': 5,
 
'interpolator': sitk.sitkBSpline,
 
'resampledPixelSpacing': None,
 
'normalize': True,
 
'normalizeScale': 256, # This allows you to use more or less the same bin width.
 
'removeOutliers': 3,
 
'force2D': False,
 
'force2Ddimension': 0,
 
# 'padDistance': 5, # Cropping image according to mask for fasting feature extraction;
 
# 'preCrop': True,
 
# 'voxelArrayShift': 300, # first order specific settings - Shifting by 300 (3 StdDevs * 100)
 
'label': 1 # default label value.
 
}

#
# Show GLCM features
#
glcmFeatures
= radiomics.glcm.RadiomicsGLCM(image, mask, **settings)
glcmFeatures
.enableAllFeatures()

print('Calculating GLCM features...')
glcmFeatures
.execute()

print('Calculated GLCM features: ')
for (key, val) in six.iteritems(glcmFeatures.featureValues):
 
print(' ', key, ':', val)
 features
.append(key)
 values
.append(val)

print('done')



That is a complete short piece of my .py file with all the routines needed
to work with a pair of images... But it doesn't work... I also added two files: the image (0199162B-slice.nrrd) and the ROI mask (0199162B-slice-label.nrrd).

That's the task I am struggling at.
Thanks.
0199162B-slice.nrrd
0199162B-slice-label.nrrd

Joost van Griethuysen

unread,
Apr 17, 2019, 2:15:44 AM4/17/19
to pyradiomics
This was indeed a bug. It was caused by the fact that the datatype of your image was int16, causing the `grayLevels` coefficient to have that same datatype.
Coupled with the fact that you had a max intensity value (after discretization) of 472, this caused an overflow, breaking the code.

This bug has been fixed in this commit, and part of the current master and will be part of the first PyRadiomics stable release following 2.1.2.

Regards,

Joost

Op dinsdag 16 april 2019 19:28:13 UTC+2 schreef Leonardo Ferreira Machado:

Leonardo Ferreira Machado

unread,
Apr 17, 2019, 9:02:24 AM4/17/19
to pyradiomics
But how should I proceed now?

I removed and installed again pyradics with 
  • python -m pip install pyradiomics
But still didn't work.

Do I have to export my images into a different datatype? Float, perhaps?

Thanks!

Joost van Griethuysen

unread,
Apr 17, 2019, 9:10:04 AM4/17/19
to pyradiomics
That is correct, I have not made a new release containing this fix yet.

You can try to build from source, either by downloading the repository from github or by 


Alternatively, you can also prevent this error by exporting your data as float data type, or use im = sitk.Cast(im, sitk.sitkFloat64) to force-cast your image prior to feeding it to PyRadiomics.

Regards,

Joost

P.S. I will try to make a release shortly

Op woensdag 17 april 2019 15:02:24 UTC+2 schreef Leonardo Ferreira Machado:
Reply all
Reply to author
Forward
0 new messages