Raw 2D (GLCM, GLRLM, etc) matrix

78 views
Skip to first unread message

Igor Vieira

unread,
Dec 7, 2017, 10:51:28 AM12/7/17
to pyradiomics
Hi all,

Suppose I have an 3D image...

Is it possible to have access to the 2D ​(GLCM, GLRLM, etc) raw matrix from which the features are estimated? Which function(s) do(es) that in pyradiomics? 

Thanks in advance,
Igor

Joost van Griethuysen

unread,
Dec 8, 2017, 4:34:10 AM12/8/17
to pyradiomics
Hello Igor,

Yes in a way. You'd have to implement the feature class yourself though. This means you have to implement preprocessing such as loading, resampling, and cropping the image before you pass it on the the feature class. Be sure to check out the helloFeatureClass examples (script and/or jupyter notebook) on how to do this. They are included in the repository.

Once you've instantiated the GLCM featureclass (`featureClass = glcm.RadiomicsGLCM(image, mask, **settings)`), which then has an attribute (`featureClass.P_glcm`) which is a 3D numpy array (i, j and angle, usually Ng x Ng x 13). However note that empty gray levels (i.e. graylevels not present in the ROI) are not included in the matrix! So you'll also need the graylevels that correspond to the indices in the matrix (first 2 dimensions of P_glcm). You can find those  as follows: `graylevels = featureClass.coefficients['grayLevels']`, this is a 1D numpy array containing the unique gray levels found in the ROI (after discretization).

A similiar operation is applied for the angles (last dimension): all angles, for which no pairs could be found, are deleted. Which angles are deleted are stored in the log (level DEBUG)

Finally, the P_glcm is already normalized, i.e. value of each element is the probability, not the count: the sum of each GLCM (for each angle) = 1.


If you want the non-normalized, full glcm, you'd need to implement the function yourself. This is possible but there are some important assumptions. First, you need the discretized gray values (VERY IMPORTANT, all gray values in the ROI must be integer numbers and the lowest must be 1) as a 3D (not more, not less) numpy array. A second numpy array (datatype 'boolean') of the exact same shape as your image array is required, where a value of True means that voxel is included in the ROI. Then, a 2D numpy array for all angles is required. You can get such an array by calling imageoperations.generateAngles(ROI_size, **settings). Finally, you need the maximum gray level in the ROI (Ng).

Then, call radiomics.cMatrices.calculate_glcm(imageMatrix, maskMatrix, angleMatrix, Ng), which returns a 3D numpy array specifying the non-normalized GLCM. Pay attention that you do not pass a slice of the numpy arrays but a continuous stored array, you can ensure this by calling e.g. imageMatrix = imageMatrix.copy().

Debugging this function is difficult, as C does not have error handling. If you do something wrong, your program just crashes without telling you why, so handle with care.


Regards,

Joost

Op donderdag 7 december 2017 16:51:28 UTC+1 schreef Igor Vieira:

Igor Vieira

unread,
Dec 11, 2017, 5:18:16 AM12/11/17
to Joost van Griethuysen, pyradiomics
Many thanks Joost: very clear! +10

A+,
Igor Vieira

--
You received this message because you are subscribed to a topic in the Google Groups "pyradiomics" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyradiomics/s1tbbvPFgyk/unsubscribe.
To unsubscribe from this group and all its topics, 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/07077d3f-3315-4a82-80fb-79365646e56f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Igor Vieira
 
" You see things; and you say 'Why?'
But I dream things that never were; and I say 'Why not?' " (Bernard Shaw)
 
Reply all
Reply to author
Forward
0 new messages