How to perform GLCM?

3 Ansichten (letzte 30 Tage)
Nanda Sulthan Estupratama
Nanda Sulthan Estupratama am 10 Aug. 2018
Bearbeitet: Image Analyst am 16 Okt. 2018
Hi. I have a code. but there's a trouble with it. here's the code:
function[cont, ent, enr] = GLCM(CM)
P = CM/sum(sum(CM));
[N,M] = size(CM);
cont = 0;
ent = 0;
enr = 0;
for m = 1:N
mX=0
for m = 1:M
mX = mX + P(n,m);
cont = cont + ((n-1)-(m-1))^2 * P(n,m);
enr = enr + (P(n,m))^2;
if P(n,m)>0
ent = ent - P(n,m) * log10(P(n,m));
end
end
end
here's the error message:
does anyone know what should I do to execute that function? Thanks.
  1 Kommentar
Rik
Rik am 10 Aug. 2018
Apparently your input is not 2D. I must say that this function is very light on comments, making it's use/maintenance more difficult.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 16 Okt. 2018
Bearbeitet: Image Analyst am 16 Okt. 2018
Try converting from color to gray scale with rgb2gray() or extracting just one of the color channels.
Also, you're using the size function incorrectly for images. See Steve's blog: http://blogs.mathworks.com/steve/2011/03/22/too-much-information-about-the-size-function/

Community Treasure Hunt

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

Start Hunting!

Translated by