GLCM结果中的黑线 [英] Black line in GLCM result

查看:264
本文介绍了GLCM结果中的黑线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是GLCM矩阵的结果。 GLCM图像中黑色水平线和垂直线的含义是什么?它们有问题吗?

It is the result of GLCM matrix. What is the meaning of black horizontal and vertical lines in GLCM image? Are they a problem?

N = numel(unique(img)); % img is uint8
glcm = graycomatrix(img, 'NumLevels', N);
imshow(glcm)

推荐答案

graycomatrix 从图像的缩放版本计算GLCM。由于缩放过程中的舍入误差,缩放图像中不同强度等级的数量可能小于原始图像中不同强度等级的数量。

graycomatrix calculates the GLCM from a scaled version of the image. Due to round-off errors in the scaling process the number of different intensity levels in the scaled image may be less than the number of different intensity levels in the original image .

请考虑以下示例图像:

img = uint8([  48  161  209   64  133  240  166  227;
              184   54  181   33  107  252  242  255
              217  191  125  112  204  252  135  201
              163  222   66  125  229  140   38   97
              252  214  201  191   10  102  242   74
              191   74   77    8  163   51  189  186]);

来自文档(强调我的):


[glcms,SI] = graycomatrix(___)返回缩放图像, SI ,用于计算灰色级别共生矩阵。 SI 中的值介于 1 NumLevels 之间。

[glcms,SI] = graycomatrix(___) returns the scaled image, SI, used to calculate the gray-level co-occurrence matrix. The values in SI are between 1 and NumLevels.

如果将 NumLevels 设置为不同强度等级的数量(在此示例是 39

If you set NumLevels to the number of different intensity levels (which in this example is 39)

N = numel(unique(img))
[glcm_scaled, img_scaled] = graycomatrix(img, 'NumLevels', N);

返回的GLCM有 39 * 39 元素。问题是缩放后的图像只有 28 不同的强度等级:

the returned GLCM has 39*39 elements. The issue is that the scaled image has only 28 different intensity levels:

>> img_scaled

img_scaled =

     8    25    32    10    21    37    26    35
    29     9    28     6    17    39    38    39
    34    30    20    18    32    39    21    31
    25    34    11    20    36    22     6    15
    39    33    31    30     2    16    38    12
    30    12    12     2    25     8    29    29

>> numel(unique(img_scaled))

ans =

    28

因此,GLCM将有11行和11列,其中所有条目都为零(黑线)。

As a consequence, the GLCM will have 11 rows and 11 columns in which all the entries are zero (black lines).

如果你不希望要发生这种情况,您可以通过查找表映射强度级别:

If you do not wish this to happen, you can map the intensity levels through a lookup table:

levels = unique(img);
N = numel(levels);
lut = zeros(256, 1);
for i=1:N;
    index = uint16(levels(i)) + 1;
    lut(index) = i;
end
img_lut = lut(uint16(img) + 1);
[glcm_mapped, img_mapped] = graycomatrix(img_lut, 'NumLevels', N, 'GrayLimits', []);

通过这样做, img_mapped 正好是与 img_lut 相同,GLCM中没有黑线。请注意,通过为 GrayLimits 参数指定空括号, graycomatrix 使用输入图像中的最小和最大灰度值作为限制。

By doing so, img_mapped is exactly the same as img_lut and there is no black lines in the GLCM. Notice that by specifying empty brackets for the GrayLimits parameter, graycomatrix uses the minimum and maximum grayscale values in the input image as limits.

这篇关于GLCM结果中的黑线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆