How to normalize GLCMs created for four offsets?

조회 수: 17 (최근 30일)
Mohammad Farhad Aryan
Mohammad Farhad Aryan 2020년 3월 22일
댓글: nissrine Neyy 2022년 6월 23일
I am using Matlab 2019b to extract texture features of images using gray level co-occurrence matrix (glcm). I have written the following code to extract rotation invariant features with directions 0, 45, 90, 135. The code creates four glcms and every feature has four values; one per direction.
I = imread('test.jpg')
offsets = [0 1; -1 1;-1 0;-1 -1];
glcm = graycomatrix(I, 'GrayLimits', [], 'Offset',offsets);
stats = graycoprops(glcm);
I want to normalize the glcms then extract each feature from the normalized glcms.
Any help is greatly appreciated.
  댓글 수: 2
Image Analyst
Image Analyst 2020년 3월 22일
Not sure what you want. Do you just want this
glcm = glcm / sum(glcm(:));
or
glcm = glcm / max(glcm(:));
or
glcm = rescale(glcm, 0, 1);
Mohammad Farhad Aryan
Mohammad Farhad Aryan 2020년 3월 23일
편집: Mohammad Farhad Aryan 2020년 3월 24일
Thank you Image Analyst for your quick reply.
Actually some papers used normalized and unnormalized glcms for texture analysis and showed that normalized glcm outperformed unnormalized glcm. So I want to practise both and compare the result.
I was able to normalize glcms created for each direction (0, 45, 90, 135) but when I pass the resultant glcms to the function graycoprops, it produces error saying 'Expected input number 1, GLCM, to be integer-valued'.
This is the code I used:
offsets = [0 1; -1 1;-1 0;-1 -1];
glcm1 = graycomatrix(rgb2gray(mskRgbImg), 'GrayLimits', [], 'Offset',offsets);
size_glcm_3 = size(glcm1,3);
for k = 1:size_glcm_3
glcm_sum(k) = sum(sum(glcm1(:,:,k)));
glcm(:,:,k) = glcm1(:,:,k)./glcm_sum(k); % Normalize each glcm
end
stats = graycoprops(glcm);
Help me please!

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2020년 3월 24일
Regarding your last comment above . . .It told you it's not integer and it needs integer. So, cast it to integer:
uint8Image = uint8(rescale(rgb2gray(mskRgbImg), 0, 255));
Then pass that into graycomatrix().
See my attached glcm demo.
  댓글 수: 3
Image Analyst
Image Analyst 2020년 3월 25일
So don't normalize it. Why do you think each should be normalized? If each is normalized independently then how can you compare them?
Mohammad Farhad Aryan
Mohammad Farhad Aryan 2020년 3월 25일
Based on literature review which I have done, some papers used normalized and unnormalized glcms and compared the results of classification using these glcms. Therefore, I wanted to use normalized and unnormalized glcms for texture features extraction and compare the results of classification using each of these glcms.
The following file normalized each glcm but calculated texture features using equations not via graycoprops() function.
Thanks

댓글을 달려면 로그인하십시오.


Hend Abouche
Hend Abouche 2022년 4월 8일
편집: Image Analyst 2022년 4월 8일
Hello, I am working on texture features extraction and I want to ask you why you didn't use just the function graycomatrix in a simple way, but you used the offset. Did you do it so you can specify the pixels that you want to calculate their co-occurrence?
  댓글 수: 5
Hend Abouche
Hend Abouche 2022년 4월 9일
So I did, thank you so much for ur time
nissrine Neyy
nissrine Neyy 2022년 6월 23일
Hi @Image Analyst, i have a question in the same context, what's the difference between using symmetric and not (set it to false or true), i know how it works but in term of results which is better and what does it give or add as an information ?

댓글을 달려면 로그인하십시오.

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by