version 1.4.0.0 (65.9 KB) by
Avinash Uppuluri

GLCM_Features4 - Calculates the texture features from the different GLCMs

[GLCM_Features4 execute faster than initial code in GLCM_Features1]

The GLCMs are stored in a i x j x n matrix, where n is the number of GLCMs calculated due to the different orientation and displacements usually used in the algorithm. The values i and j are equal to 'NumLevels' parameter of the GLCM computing function graycomatrix(). Note that matlab quantization values belong to the set {1,..., NumLevels} and not from {0,...,(NumLevels-1)} as provided in some references

http://www.mathworks.com/access/helpdesk/help/toolbox/images/graycomatrix.html

This vectorized version of GLCM_FEatures1.m reduces the 19 'for' loops used in the earlier code to 5 'for' loops ( but can be further vectorized) http://blogs.mathworks.com/loren/2006/07/12/what-are-you-really-measuring/ Using tic toc and cputime as in above discussion I find considerable improvement after reducing all the loops and making changes to the code as suggest in a comment by one of the members of MATLAB central. Thanks to Mohammad Entezarmahdi for letting me know the time drain caused by ismember() function used in the earlier code.

The details of the timing can be seen in "Test_GLCM_Features.html". You can also use "Test_GLCM_Features.m" to see the results.

Files provided in folder include:

GLCM_Features1.m [Non vectorized; with ismember()]

GLCM_Features2.m [Vectorized; with ismember()]

GLCM_Features3.m [Non vectorized; without ismember()]

GLCM_Features4.m [Vectorized; without ismember()]

I find that GLCM_Features4.m provides the best (fastest) timing. Any further suggestions to improve the performance of this code are welcome.

Comments are also posted at http://www.mathworks.com/matlabcentral/newsreader/view_thread/239608#613094

Haralick uses 'Symmetric' = true in computing the glcm. There is no Symmetric flag in the Matlab version I use hence I add the diagonally opposite pairs to obtain the Haralick glcm. Here it is assumed that the diagonally opposite orientations are paired one after the other in the matrix. If the above assumption is true with respect to the input glcm then setting the flag 'pairs' to 1 will compute the final glcms that would result by setting 'Symmetric' to true. If the glcm is computed using the Matlab version with 'Symmetric' flag you can set the flag 'pairs' to 0

References:

1. R. M. Haralick, K. Shanmugam, and I. Dinstein, Textural Features of Image Classification, IEEE Transactions on Systems, Man and Cybernetics, vol. SMC-3, no. 6, Nov. 1973

2. L. Soh and C. Tsatsoulis, Texture Analysis of SAR Sea Ice Imagery Using Gray Level Co-Occurrence Matrices, IEEE Transactions on Geoscience and Remote Sensing, vol. 37, no. 2, March 1999.

3. D A. Clausi, An analysis of co-occurrence texture statistics as a function of grey level quantization, Can. J. Remote Sensing, vol. 28, no. 1, pp. 45-62, 2002

4. http://murphylab.web.cmu.edu/publications/boland/boland_node26.html

Example:

Usage is similar to graycoprops() but needs extra parameter 'pairs' apart from the GLCM as input

I = imread('circuit.tif');

GLCM2 = graycomatrix(I,'Offset',[2 0;0 2]);

stats = GLCM_features4(GLCM2,0)

The output is a structure containing all the parameters for the different GLCMs

[Avinash Uppuluri: avinash_uv@yahoo.com: Last modified: 04/05/2010]

Avinash Uppuluri (2021). GLCM_Features4.m: Vectorized version of GLCM_Features1.m [With code changes] (https://www.mathworks.com/matlabcentral/fileexchange/22354-glcm_features4-m-vectorized-version-of-glcm_features1-m-with-code-changes), MATLAB Central File Exchange. Retrieved .

Created with
R14SP1

Compatible with any release

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!Create scripts with code, output, and formatted text in a single executable document.

miaomiao longyour code takes care of 3 dimensional glcms (multiple glcms in a single 3D array).but in the example

GLCM2 = graycomatrix(I,'Offset',[2 0;0 2]);

the function grycomatrix olny takes in two dimensional data. i have three dimensional data, 79*95*65, not knowing how to get glcm3. can you kindly help me pointing how i can do it? thank you very much. i am a medical doctore, not very good at programming.

anyone can provide a script to read in 3d dataset instead of graycomatrix?

miaomiao longyour code takes care of 3 dimensional glcms (multiple glcms in a single 3D array).but in the example

GLCM2 = graycomatrix(I,'Offset',[2 0;0 2]);

the function grycomatrix olny takes in two dimensional data. i have three dimensional data, 79*95*65, not knowing how to get glcm3. can you kindly help me pointing how i can do it? thank you very much. i am a medical doctore, not very good at programming.

Adela ArpithaVanditaDear Avinash,

You calculate indnc, idmnc (w.r.t. Claussi 2002 paper) and you mention that INV is same as homom. Claussi 2002 mentions only two equations, Inverse Difference and Inverse Difference Moment. Also homop that you calculate w.r.t Soh 1999 is same as IDM (Haralick 1973). Can you please provide equation and their due references for these four features. It is confusing what is being calculated in each of these four and what is the difference. Please answer this asap.

Regards

Humayun IrshadHow can I compute GLCM on selected regions inside whole image?

sai kiran thatiAvinash i have been trying to reach you! I am sai kiran thati. I am currently using your code in my research to extract features from GLCM. i posted a question. Can you please read it and answer for me? I think you are the only guy who can help me out in this.

http://www.mathworks.com/matlabcentral/answers/135000-how-to-decide-the-pixel-distance-gray-levels-and-orientation-angle-before-calculating-glcm-from-gr

PrabhakarGLCM2 = graycomatrix(I,'Offset',[2 0;0 2]); can explain about [2 0;0 2]

PrabhakarDear Avinash Uppuluri

1.SGLD matrix and this GLCM matrix both are same?

2.Here which direction (0,45,90,135) you preferred because i did,'t find exact offset value

hamed abdulazizDear Sir;

I used your GLCM_Features4 code for bitmap image but my MATLAB displayed this error message :

??? Undefined function or method 'GLCM_features4' for input

arguments of type 'double'.

Error in ==> call_glcm4 at 4

stats = GLCM_features4(GLCM2,0);

could you help me please?

I'll wait your answer impatiently

Best regards,

Hamed

Avinash UppuluriHi Ivana,

To clarify please run this script:

A = repmat(0:255, 256, 1);

[GLCM2, B] = graycomatrix(A,'Offset',[1 0],'G',[0,255]);

figure;plot(A(:), B(:), '*');

figure;imagesc(A);colorbar

figure;imagesc(B);colorbar

What this does is generates a 256 x 256 image that contains gray levels from 0 to 255 in all rows. Then I plot the input versus output plot. Hopefully this will clarify any doubts on the GLCM outputs levels. You probably have already gone through the definitions of 'GrayLimits' and 'NumLevels' which are the parameters that control the output levels.

'GrayLimits'

Two-element vector, [low high], that specifies how the grayscale values in I are linearly scaled into gray levels. Grayscale values less than or equal to low are scaled to 1. Grayscale values greater than or equal tohigh are scaled to NumLevels. If graylimits is set to [], graycomatrix uses the minimum and maximum grayscale values in the image as limits,[min(I(:)) max(I(:))].

Minimum and maximum specified by class, e.g.

double [0 1]

int16[-32768 32767]

'NumLevels'

Integer specifying the number of gray-levels to use when scaling the grayscale values in I. For example, if NumLevels is 8, graycomatrix scales the values in I so they are integers between 1 and 8. The number of gray-levels determines the size of the gray-level co-occurrence matrix (glcm).

8 (numeric)

2 (binary)

Hope this helps.

Avinash

ivana7cHello,

thanks for the useful implementation. I have one question which is regarding how Matlab computes the GLCM matrix itself, maybe you will know the answer. I want to calculate the GLCM for an image, and I call:

I = imread('circuit.tif');

GLCM2 = graycomatrix(I,'Offset',[1 0],'G',[0,255]);

The default value for NumValues is 8, so I get 8x8 matrix as a result. My question is, do you maybe know how Matlab maps the intensity values from the original image to these 8 intensity ranges? It seems it doesn't do it uniformly, but it does something like this:

original range -> mapping:

0..18 -> 1

19..54 -> 2

55..91 -> 3

.

.

.

237..255 -> 8

So, the first range includes only 19 intensity values, the second 36, the third 37 and so on. Do you maybe know the logic behind this computation?

Thank you for any help!

Regards,

Ivana

M@lik Ali