# GLCM extraction error on .png image

**URL:** <https://discourse.slicer.org/t/glcm-extraction-error-on-png-image/13566>\
**Category:** Radiomics\
**Tags:** pyradiomics\
**Created:** [September 19, 2020, 2:46pm UTC](https://discourse.slicer.org/t/glcm-extraction-error-on-png-image/13566 "2020-09-19T14:46:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shibashis\_Sahu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shibashis_sahu/32/8172_2.png) [@Shibashis\_Sahu](https://discourse.slicer.org/u/Shibashis_Sahu)\
**Post date:** [September 19, 2020, 2:46pm UTC](https://discourse.slicer.org/t/glcm-extraction-error-on-png-image/13566/1 "2020-09-19T14:46:01Z")

</div>

Operating system: Windows 10  
Slicer version:  
Expected behavior:  
Actual behavior:  
HI,  
I am new to pyradiomics and getting an error while extracting using GLCM, here is my code:

ig = sitk.ReadImage(’./PAC\_14\_DN0.png’, sitk.sitkUInt8)  
print(ig.GetSize())  
print(ig)  
image3d = sitk.JoinSeries(ig)  
msk = sitk.ReadImage(’./mask1.png’, sitk.sitkUInt8)  
print(msk.GetSize())  
print(msk)  
msk3d = sitk.JoinSeries(msk)

feature = radiomics.glcm.RadiomicsGLCM(image3d, msk3d, label=255)  
print(feature.getAutocorrelationFeatureValue())  
output:  
(190, 250)  
Image (0000022AFBBD4110)  
RTTI typeinfo: class itk::Image\<unsigned char,2\>  
Reference Count: 1  
Modified Time: 945  
Debug: Off  
Object Name:  
Observers:  
none  
Source: (none)  
Source output name: (none)  
Release Data: Off  
Data Released: False  
Global Release Data: Off  
PipelineMTime: 935  
UpdateMTime: 944  
RealTimeStamp: 0 seconds  
LargestPossibleRegion:  
Dimension: 2  
Index: [0, 0]  
Size: [190, 250]  
BufferedRegion:  
Dimension: 2  
Index: [0, 0]  
Size: [190, 250]  
RequestedRegion:  
Dimension: 2  
Index: [0, 0]  
Size: [190, 250]  
Spacing: [1, 1]  
Origin: [0, 0]  
Direction:  
1 0  
0 1

IndexToPointMatrix:  
1 0  
0 1

PointToIndexMatrix:  
1 0  
0 1

Inverse Direction:  
1 0  
0 1

PixelContainer:  
ImportImageContainer (0000022A801703A0)  
RTTI typeinfo: class itk::ImportImageContainer\<unsigned \_\_int64,unsigned char\>  
Reference Count: 1  
Modified Time: 941  
Debug: Off  
Object Name:  
Observers:  
none  
Pointer: 0000022A8025DD10  
Container manages memory: true  
Size: 47500  
Capacity: 47500

(190, 250)  
Image (0000022AFBBD4680)  
RTTI typeinfo: class itk::Image\<unsigned char,2\>  
Reference Count: 1  
Modified Time: 1139  
Debug: Off  
Object Name:  
Observers:  
none  
Source: (none)  
Source output name: (none)  
Release Data: Off  
Data Released: False  
Global Release Data: Off  
PipelineMTime: 1129  
UpdateMTime: 1138  
RealTimeStamp: 0 seconds  
LargestPossibleRegion:  
Dimension: 2  
Index: [0, 0]  
Size: [190, 250]  
BufferedRegion:  
Dimension: 2  
Index: [0, 0]  
Size: [190, 250]  
RequestedRegion:  
Dimension: 2  
Index: [0, 0]  
Size: [190, 250]  
Spacing: [1, 1]  
Origin: [0, 0]  
Direction:  
1 0  
0 1

IndexToPointMatrix:  
1 0  
0 1

PointToIndexMatrix:  
1 0  
0 1

Inverse Direction:  
1 0  
0 1

PixelContainer:  
ImportImageContainer (0000022A80171750)  
RTTI typeinfo: class itk::ImportImageContainer\<unsigned \_\_int64,unsigned char\>  
Reference Count: 1  
Modified Time: 1135  
Debug: Off  
Object Name:  
Observers:  
none  
Pointer: 0000022A80275050  
Container manages memory: true  
Size: 47500  
Capacity: 47500  
KeyError Traceback (most recent call last)  
 in ()  
1 # feature.enableAllFeatures()  
2 # feature.calculateFeatures()  
----\> 3 print(feature.getAutocorrelationFeatureValue())

F:\Programs\Anaconda3\lib\site-packages\radiomics\glcm.py in getAutocorrelationFeatureValue(self)  
253 Autocorrelation is a measure of the magnitude of the fineness and coarseness of texture.  
254 “”"  
–\> 255 i = self.coefficients[‘i’]  
256 j = self.coefficients[‘j’]  
257 ac = numpy.sum(self.P\_glcm \* (i \* j)[None, :, :, None], (1, 2))

KeyError: ‘i’

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![JoostJM](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/joostjm/32/1091_2.png) [@JoostJM](https://discourse.slicer.org/u/JoostJM)\
**Post date:** [September 30, 2020, 11:38am UTC](https://discourse.slicer.org/t/glcm-extraction-error-on-png-image/13566/2 "2020-09-30T11:38:29Z")

</div>

This bug occurs due to incorrect usage of the featureclass in standalone version.  
Through directly calling the feature function, important initialization steps are skipped.

Recommended usage is through the featureextractor module (as this also implements important preprocessing code and checks). See [interactive use](https://pyradiomics.readthedocs.io/en/latest/usage.html#interactive-use).

Using the feature classes directly is still possible, but only recommended for developers’ use. See [using feature classes directly](https://pyradiomics.readthedocs.io/en/latest/developers.html#using-feature-classes-directly)
