I have a grayscale image, but when I run glcm graycomatrix code there was an error

9 visualizaciones (últimos 30 días)
I run graycomatrix code in my grayscale image (pap smear image), but there was an error. When I use this code
GLCM = graycomatrix(A, 'Offset' , [0 1; -1 1; -1 0; -1 -1]);
I get this error
Error using graycomatrix
Expected input number 1, I, to be two-dimensional.
Error in graycomatrix>ParseInputs (line 260)
validateattributes(I,{'logical','numeric'},{'2d','real','nonsparse'}, ...
Error in graycomatrix (line 167)
[I, Offset, NL, GL, makeSymmetric] = ParseInputs(varargin{:});
Whereas that code could run smoothly in my grayscale fundus image. Could you help me? Thank you

Respuesta aceptada

Image Analyst
Image Analyst el 7 de Sept. de 2018
Editada: Image Analyst el 8 de Sept. de 2018
The badly-named A is most likely not a gray scale image, even if it looks monochrome. It's probably an RGB image. Let's call it grayImage instead of A and use this:
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
See attached demo of GLCM.
  2 comentarios
Zanetta Liu
Zanetta Liu el 8 de Sept. de 2018
Now my problem was solved. Like what you say it turns out not a grayscale image. Thank you

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by