问题
As we know, GLCM (Grey Level Co-occurrence Matrix) describes the texture characteristics of images. But in usual, the calculation of GLCM in OpenCV, matlab often aim on a picture. But now I just want to get GLCM value of every single point inside the image, but how to get it?
回答1:
If I understand your problem correctly, then perhaps you can just set the pixels outside your region of interest to NaN - these pixels are ignored by MATLAB when calculating the GLCM.
For example:
>> im = eye(7)
im =
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 1 0
0 0 0 0 0 0 1
>> graycomatrix(im)
ans =
30 0 0 0 0 0 0 6
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0
>> im([1:10,13:16,21:24,28:29,34:37,41:49]) = NaN % Remove pixels outside ROI
im =
NaN NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN 0 NaN NaN
NaN NaN 1 NaN 0 0 NaN
NaN 0 0 1 0 0 NaN
NaN 0 0 0 1 0 NaN
NaN NaN 0 0 NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN
>> warning('off', 'Images:graycomatrix:scaledImageContainsNan')
>> graycomatrix(im)
ans =
6 0 0 0 0 0 0 2
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0
>> warning('on', 'Images:graycomatrix:scaledImageContainsNan')
Does that do what you need?
来源:https://stackoverflow.com/questions/8237000/the-method-of-calculate-the-glcm-of-a-specific-point-in-a-image