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

9 views (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 7 Sep 2018
Edited: Image Analyst on 8 Sep 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.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!