GLCM_Features4.m: Vectorized version of GLCM_Features1.m [With code changes]
[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]
Cite As
Avinash Uppuluri (2024). 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 .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Image Processing and Computer Vision > Image Processing Toolbox > Image Segmentation and Analysis > Texture Analysis >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.