1

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)

GLCM matrix

Tonechas
  • 13,398
  • 16
  • 46
  • 80
Omid Omidi
  • 1,670
  • 2
  • 16
  • 23

3 Answers3

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.

jessexknight
  • 756
  • 7
  • 20
  • Thanks, But i use N = numel(unique(img)); and it was not corrected!! The lines are there yet! how can i select the optimum NumLevels? – Omid Omidi Dec 19 '15 at 12:26
  • Interesting. Have you tried `plot(unique(img))` - perhaps the graylevels are not evenly distributed (the plot would be a perfect straight line if they were). If they aren't, there might still be empty bins because `NumLevels` is distributed evenly across the image range - yielding the black lines. Also, do the locations of the black lines change when you resize the GLCM figure? This might be a rendering issue. – jessexknight Jan 02 '16 at 19:15
1

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.

Tonechas
  • 13,398
  • 16
  • 46
  • 80
0

I was seeing the same behaviour under my own GLCM implementation. The issue was that I was implementing the histogram equalization given a number of gray levels.

I compute the discretization of the image before dividing first and then enter to review if any row or column is given inly zeros values.