Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when creating symmetrical GLCM #261

Merged
merged 2 commits into from Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Expand Up @@ -6,6 +6,14 @@ Release Notes
Next Release
------------

Bug fixes
#########

- In GLCM, the matrix is made symmetrical by adding the transposed matrix. However, ``numpy.transpose`` returns a view
and not a copy of the array, causing erroneous results when adding it to the original array. use
``numpy.ndarray.copy`` to prevent this bug. **N.B. This affects the feature values calculated by GLCM when symmetrical
matrix is enabled (as is the default setting).**

-----------------
PyRadiomics 1.2.0
-----------------
Expand Down
4 changes: 3 additions & 1 deletion radiomics/glcm.py
Expand Up @@ -186,7 +186,9 @@ def _applyMatrixOptions(self, P_glcm, angles):
# Optionally make GLCMs symmetrical for each angle
if self.symmetricalGLCM:
self.logger.debug('Create symmetrical matrix')
P_glcm += numpy.transpose(P_glcm, (1, 0, 2))
# Transpose and copy GLCM and add it to P_glcm. Numpy.transpose returns a view if possible, use .copy() to ensure
# a copy of the array is used and not just a view (otherwise erroneous additions can occur)
P_glcm += numpy.transpose(P_glcm, (1, 0, 2)).copy()

# Optionally apply a weighting factor
if self.weightingNorm is not None:
Expand Down