0

众所周知,GLCM(灰度共生矩阵)描述了图像的纹理特征。但是平时OpenCV中GLCM的计算,matlab经常针对的是一张图片。但是现在我只想获取图像内每个点的 GLCM 值,但是如何获取呢?

4

1 回答 1

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

这能满足你的需要吗?

于 2011-11-24T09:45:54.207 回答