# Whole Image binning for GLCM

**URL:** <https://discourse.itk.org/t/whole-image-binning-for-glcm/2835>\
**Category:** Uncategorized\
**Created:** [March 16, 2020, 9:57pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835 "2020-03-16T21:57:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarthakpati](https://discourse.itk.org/user_avatar/discourse.itk.org/sarthakpati/32/383_2.png) [@sarthakpati](https://discourse.itk.org/u/sarthakpati)\
**Post date:** [March 16, 2020, 9:57pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/1 "2020-03-16T21:57:20Z")

</div>

Hi,

I am trying to extract GLCM matrix from an image and mask using [itk::Statistics::ScalarImageToCooccurrenceMatrixFilter](https://itk.org/Doxygen/html/classitk_1_1Statistics_1_1ScalarImageToCooccurrenceMatrixFilter.html). I wanted to verify how the quantization happens on the provided binning information:

1. Only the region inside the mask is quantized
2. The entire image is quantized

Regardless of which one is being done, how do I do the other?

Cheers,  
Sarthak

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [March 17, 2020, 2:45pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/2 "2020-03-17T14:45:42Z")

</div>

Hi Sarthak,

To compute GLCM on local regions, use the ITKTextureFeatures module:

[https://github.com/InsightSoftwareConsortium/ITKTextureFeatures](https://github.com/InsightSoftwareConsortium/ITKTextureFeatures)

HTH,  
Matt

---

<div class="post-metadata">

**Author:** ![sarthakpati](https://discourse.itk.org/user_avatar/discourse.itk.org/sarthakpati/32/383_2.png) [@sarthakpati](https://discourse.itk.org/u/sarthakpati)\
**Post date:** [March 17, 2020, 2:59pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/3 "2020-03-17T14:59:18Z")

</div>

Hey Matt,

Thanks, I am familiar with that filter but I need to extract the GLCM matrix.

Cheers,  
Sarthak

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [March 17, 2020, 3:11pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/4 "2020-03-17T15:11:02Z")

</div>

To just inspect or verify the GLCM matrix content, use a debugger such as GDB or edit the source code to write out intermediate results. 📖

---

<div class="post-metadata">

**Author:** ![sarthakpati](https://discourse.itk.org/user_avatar/discourse.itk.org/sarthakpati/32/383_2.png) [@sarthakpati](https://discourse.itk.org/u/sarthakpati)\
**Post date:** [March 17, 2020, 5:45pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/5 "2020-03-17T17:45:49Z")

</div>

Hey Matt,

I need the option to combine the features in different ways, hence I need access to the GLCM matrix.

To do this, I am using [itk::Statistics::ScalarImageToCooccurrenceMatrixFilter](https://itk.org/Doxygen/html/classitk_1_1Statistics_1_1ScalarImageToCooccurrenceMatrixFilter.html) to get the matrix and then using [itk::Statistics::HistogramToTextureFeaturesFilter](https://itk.org/Doxygen/html/classitk_1_1Statistics_1_1HistogramToTextureFeaturesFilter.html) to extract features.

However, I am unsure if there is a way I can do the quantization of the input image for the entire image but do the feature calculations only on the specified region of interest.

Cheers,  
Sarthak

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [March 18, 2020, 5:23pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/6 "2020-03-18T17:23:03Z")

</div>

Hi Sarthak,

To compute the matrix and features (they are both a characteristic of the entire region they are computed on), use the [itk::RegionOfInterestImageFilter](https://itk.org/Doxygen/html/classitk_1_1RegionOfInterestImageFilter.html).

HTH,  
Matt

---

<div class="post-metadata">

**Author:** ![sarthakpati](https://discourse.itk.org/user_avatar/discourse.itk.org/sarthakpati/32/383_2.png) [@sarthakpati](https://discourse.itk.org/u/sarthakpati)\
**Post date:** [March 19, 2020, 1:29pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/7 "2020-03-19T13:29:18Z")

</div>

Hey Matt,

I think I may not have conveyed the question correctly. The (annotated) region of interest (ROI) is defined in the mask. I want to extract features only from this region, but I want to quantization/binning to happen to either the entire image or just that region. Basically, get 2 sets of features:

1. where the entire image is quantized and I obtain features from the ROI which are scaled in relation to whole image, thereby capturing the heterogeneity information in the ROI **related to the entire image**.
2. where only the ROI is quantized, thereby getting heterogeneity information **WITHIN** the ROI.

My question is, what of the above 2 does the current implementation of [itk::Statistics::ScalarImageToCooccurrenceMatrixFilter](https://itk.org/Doxygen/html/classitk_1_1Statistics_1_1ScalarImageToCooccurrenceMatrixFilter.html) do and how can I do the other?

Cheers,  
Sarthak

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [March 19, 2020, 1:32pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/8 "2020-03-19T13:32:29Z")

</div>

The filter can do either, depending if the Mask input is set.

You will simply need to create two instances of it and run it twice.

---

<div class="post-metadata">

**Author:** ![sarthakpati](https://discourse.itk.org/user_avatar/discourse.itk.org/sarthakpati/32/383_2.png) [@sarthakpati](https://discourse.itk.org/u/sarthakpati)\
**Post date:** [March 19, 2020, 2:16pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/9 "2020-03-19T14:16:08Z")

</div>

Hey Brad,

I understand that the filter can do the computation based on the provided mask, which actually takes care of point 2 in my previous comment, as (from what I have understood from the documentation and running the filter) the quantization seems to happen only on the provided ROI.

But, for 1, I want to calculate the features only **INSIDE THE ROI** but with the **entire image** getting quantized.

Cheers,  
Sarthak

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [March 19, 2020, 3:12pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/10 "2020-03-19T15:12:09Z")

</div>

Please describe what you mean by “quantizing an image” here?

---

<div class="post-metadata">

**Author:** ![sarthakpati](https://discourse.itk.org/user_avatar/discourse.itk.org/sarthakpati/32/383_2.png) [@sarthakpati](https://discourse.itk.org/u/sarthakpati)\
**Post date:** [March 19, 2020, 3:59pm UTC](https://discourse.itk.org/t/whole-image-binning-for-glcm/2835/11 "2020-03-19T15:59:30Z")

</div>

When I say “quantizing the whole image”, I mean that the histogram is calculated for the entire image and not just for the part defined in the mask.
