[英]Creating gray-level co-occurrence matrix from 16-bit image
我有一个16位图像的数据集,我想从中创建GLCM矩阵以提取GLCM特征。
但是,结果矩阵显示一个值(如下图所示),我想知道为什么。
我尝试使用相同的图像,但转换为8位,结果GLCM显示多个值。
注意:我使用了以下Matlab函数:
glcm_matrix = graycomatrix(image.tif);
这是16位图像的裁剪样本:
注意:计算中使用的图像可从此处下载。 原始图像对比度很低,看起来完全暗。 上面显示的图像具有被拉伸的对比度,仅用于可视化目的。
编辑:
我用了
glcm_matrix = graycomatrix(image.tif, 'GrayLimits', []);
它给了我以下结果:
这是一个装箱/缩放问题。
让我们来看看里面:
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个bin,并假设缩放范围是整个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) A = graycomatrix(I,'GrayLimits', [])
(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,因此考虑到负值的可能性,灰度comatrix是对称的。
当然,您也可以缩放原始图像以适合其数据类型。 例如,如果您预期有异常值,百分位数缩放可能是个好主意。
我只是想以@Tapio的出色答案为基础。
当您在函数调用中使用名称/值对GrayLimits', []
时,由graycomatrix
的GLCM看起来不错。 但是,这种方法可能对您的应用程序无效。 如果以此方式为一组图像计算GLCM,则对应于两个不同图像的两个不同GLCM的相同元素可能具有不同的含义。 确实,由于对每个图像的强度进行了不同的缩放,因此GLCM的组件实际上在编码从一个图像到另一个图像的不同同时出现。
为避免这种情况,您可以首先计算整个图像数据集的最小和最大强度(例如minImgs
和maxImgs
),然后使用这些值以完全相同的方式重新调整构成数据集的所有图像的强度:
glcm_matrix = graycomatrix(image_tif, 'GrayLimits', [minImgs maxImgs]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.