Black line in GLCM result

帅比萌擦擦* 提交于 2020-01-11 12:00:13

问题


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)


回答1:


I suspect this is the problem: For the function graycomatrix, You have supplied a 'NumLevels' argument which is larger than the number of unique graylevels in your image. For instance, a 256-level (8-bit) image will have only 256 graylevels. Asking for 1000 levels in the output means 744 levels will have no data! i.e. Yes, this is a problem. You can check how many graylevels your image has using numel(unique(I)).

p.s. In the future, please attach the code you used to generate the problem.




回答2:


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 .

Consider the following sample 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]);

From the documentation (emphasis mine):

[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.

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

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

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', []);

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.



来源:https://stackoverflow.com/questions/34365953/black-line-in-glcm-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!