众所周知,GLCM(灰度共生矩阵)描述了图像的纹理特征。但通常情况下,在OpenCV中计算GLCM,matlab经常针对图片。但是现在我只想获得图像中每个点的GLCM值,但是如何获得它呢?
答案 0 :(得分:1)
如果我能正确理解你的问题,那么你可以将感兴趣区域之外的像素设置为NaN - 在计算GLCM时,MATLAB会忽略这些像素。
例如:
>> 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')
这样做你需要的吗?