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

15 ビュー (過去 30 日間)
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
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 9 月 7 日
Can you attach the image? If not solved yet
Zanetta Liu
Zanetta Liu 2018 年 9 月 9 日
It was solved. Thank you for your comment

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2018 年 9 月 7 日
編集済み: Image Analyst 2018 年 9 月 8 日
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 件のコメント
Zanetta Liu
Zanetta Liu 2018 年 9 月 8 日
Now my problem was solved. Like what you say it turns out not a grayscale image. Thank you
Image Analyst
Image Analyst 2018 年 9 月 8 日
You're welcome. Thanks for Accepting the answer.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by