GLCM_Features4.m: Vectorized version of GLCM_Features1.m [With code changes]

GLCM_Features4 - Calculates the texture features from the different GLCMs
Updated 5 Apr 2010

View License

[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

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) 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

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

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


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: Last modified: 04/05/2010]

Cite As

Avinash Uppuluri (2024). GLCM_Features4.m: Vectorized version of GLCM_Features1.m [With code changes] (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

ismember() function commented in code [as suggested by Mohammad Entezarmahdi]

Changed screenshot