这是一个分箱/缩放问题。
让我们看看里面:
edit graycomatrix
在这种情况下,我们对“NumLevels”和“GrayLimits”这两个选项感兴趣
% 'NumLevels' An integer specifying the number of gray levels to use
% when scaling the grayscale values in I. For example,
% if 'NumLevels' is 8, GRAYCOMATRIX scales the values in
% I so they are integers between 1 and 8. The number of
% gray levels determines the size of the gray-level
% co-occurrence matrix (GLCM).
%
% 'NumLevels' must be an integer. 'NumLevels' must be 2
% if I is logical.
%
% Default: 8 for numeric
% 2 for logical
%
% 'GrayLimits' A two-element vector, [LOW HIGH], that specifies how
% the values in I are scaled into gray levels. If N is
% the number of gray levels (see parameter 'NumLevels')
% to use for scaling, the range [LOW HIGH] is divided
% into N equal width bins and values in a bin get mapped
% to a single gray level. Grayscale values less than or
% equal to LOW are scaled to 1. Grayscale values greater
% than or equal to HIGH are scaled to NumLevels. If
% 'GrayLimits' is set to [], GRAYCOMATRIX uses the
% minimum and maximum grayscale values in I as limits,
% [min(I(:)) max(I(:))].
因此,换句话说,该函数将您的数据分箱到 8x8 箱中,并假设缩放范围是完整的 uint16 范围 (0-65535)。但是,您提供的示例图像最小为 305,最大为 769,使其落入第一个 bin(0-8192 左右)。当我调用A = graycomatrix(I)
它时,它给了我以下矩阵:
A =
6600 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 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
然而,当A = graycomatrix(I,'GrayLimits', [])
被调用时,缩放范围被视为 min(I) - max(I),并且函数按预期工作:
A =
4 2 1 0 0 0 0 0
1 1 2 2 0 0 0 0
2 2 4 7 1 0 0 0
0 1 7 142 72 1 0 0
0 0 0 65 1711 252 0 0
0 0 0 0 230 3055 178 0
0 0 0 0 0 178 654 8
0 0 0 0 0 0 8 9
在您的原始示例中,单个值很可能位于 8x8 矩阵的中间,因为您的原始图像是 int16 而不是 uint16,因此 graycomatrix 是对称的,以考虑到负值的可能性。
当然,您也可以缩放原始图像以适合其数据类型。例如,如果您期望异常值等,百分位缩放可能是一个好主意。