0

I want to extract GLCM texture feature from an image in my CBIR system.... I applied the following code:

S=imread('A1.jpg');  
S=rgb2gray(S);  
I= imresize (S, [350 350]);     

glcm45=graycomatrix(I,'offset',[-1 1],'NumLevel', 8,'Symmetric',true); 
                                                         % 45 engle degree  
glcm135 = graycomatrix(I,'Offset',[-1 -1],'NumLevel', 8,'Symmetric',   true );  % 135 engle degree

GLCM=glcm45+glcm135;

I get 64(8*8) dimensions for GLCM feature and I used it in retrieve the similarity images and I get a very good results....

My question is: Can I consider this 64 dimensions as the length of GLCM feature vector for an image?

Tonechas
  • 13,398
  • 16
  • 46
  • 80
zenab
  • 229
  • 3
  • 9
  • 20

1 Answers1

0

Yes you can consider it as a feature. There's even a research article on this --- using GLCMs as sole features for doing face detection: "Co-occurence Matrix and its Statistical Features as a New Approach for Face Recognition". Here's the link.

That paper also shows that using GLCMs as features performs better than the Haralick features derived from the GLCMs. Also, GLCMs can be computed within milliseconds (0.5ms - 2ms; my own implementation in C++, 256x256 GLCMs with all 0, 45, 90 and 135 degree neighbourhood correspondences), and so it is a cheap and an excellent feature.

  • Shama, Thank you so much for your answer... yes I know that I can use it as sole feature but can I used just this region (8*8) from my image with size (350*350) as texture feature ? you know in this case I just use a very little pixels (8*8) for extract texture feature. – zenab Aug 08 '15 at 21:30
  • @Shama ..please , I am waiting for your helping on answer my question..thanks – zenab Aug 08 '15 at 21:31
  • 1
    Okay I thought you used 8 gray-levels and that resulted in 8x8 GLCMs for an entire image. Are you saying that you are computing GLCMs based only on 8x8 patch in an image? If that works for you, you can use it. But I guess, in an 8x8 patch most of the entries in GLCMs will be "0". So how is that even giving you good results? P.S. your MATLAB code doesn't confirm what you are saying. You are computing GLCMs over the entire image [350x350] after reducing 255 gray-levels to just 8 gray-levels. – Sanjeev Sharma Aug 09 '15 at 07:23
  • 1
    that "8" in the input means that MATLAB will quantize your image where pixels will have values in [0,7] or [1,8] instead of [0,255]. – Sanjeev Sharma Aug 09 '15 at 07:30
  • @Shama .... Yes this is my work but I used this process for each image's channel ..... For Example, the out put of GLCM of Red Channel using this function : glcm45=graycomatrix(I,'offset',[-1 1],'NumLevel', 8,'Symmetric',true) is equal to: – zenab Aug 09 '15 at 12:09
  • 0 0 0 0 0 0 0 0; 0 828 757 1 0 0 0 0; 0 757 185652 5100 721 311 63 3; 0 1 5100 7344 1611 512 175 14; 0 0 721 1611 3926 1061 352 18; 0 0 311 512 1061 3884 1222 64; 0 0 63 175 352 1222 11126 971; 0 0 3 14 18 64 971 4930; PLease, I have another question..Instead of just using (8*8), can I scale the image to (8*8), then compute GLCM as mention above? thanks – zenab Aug 09 '15 at 12:11
  • To be honest, it looks from your comments that you do not understand what GLCM is. I don't even understand your question. Would you mind rephrasing your question --- properly defining what exactly you want to do. It is all confusing. – Sanjeev Sharma Aug 09 '15 at 23:28
  • @Shama ..Yes you are right..when I discussed with you , I found that GLCM feature extraction is not so clear for me, but I get benefit from your comments so I thank you so much. So, I read graycomatrix function again and I understand that it compute GLCM over entire image. – zenab Aug 10 '15 at 05:26
  • @Shama ..just one thing is still not clear for me that is how this function produce GLCM ? when I used 8 gray-levels, that mean GLCM size will be (8*8)= 64 feature dimensions ..right? – zenab Aug 10 '15 at 05:33
  • @Shama ..My question is how can I get the values of GLCM matrix? In my case the matrix is 8-by- 8 dimension (graylevel) and I should calculating how often a pixel with gray-level (grayscale intensity) value i occurs horizontally (0r other pixel spatial relationships) adjacent to a pixel with the value j. I need an example using a real image values to understand the process of creating GLCM feature . best regards – zenab Aug 10 '15 at 05:41
  • 1
    yes the GLCM size should be 8x8 in your case. To get the 0-degree adjacency GLCM, you need to change the offset to [0 1] in matlab. Say it is glcm0. glcm0 gives you what you want. You can compute all the other GLCMs as well, say glcm0, glcm45, glcm90 and glcm135, then convert them into probability matrices and then add all four and divide by 4. This way you can get the average of all 4 glcms. Or you can just use glcm0, if you want horizontal relation, glcm90 if you need vertical relation and likewise other 45 and 135 glcms for diagonal relations. – Sanjeev Sharma Aug 10 '15 at 08:04
  • 1
    the (i,j) entry in glcm0 will give you what you asked for – Sanjeev Sharma Aug 10 '15 at 08:12
  • @Shama .. thank you so much for replying.. I did all your suggestions and more that I told you that I get a good results even previously I didn't understand how compute GLCM. – zenab Aug 10 '15 at 20:44
  • @Shama ..please, now just I want to understand how we can calculate how often a pixel with grey-level value i occurs adjacent to a pixel with the value j in any direction. e.g: we have the grey image values: – zenab Aug 10 '15 at 20:49
  • 60 58 60 60 56; 56 59 62 63 60; 58 58 56 60 62; 61 61 62 61 62; 66 63 64 66 68; 67 62 63 66 70; 60 62 65 67 66 and I have the gray-level (8*8) and you said that MATLAB will quantize my image where pixels will have values in [0,7]. I know that GLCM matrix will be 8-by-8 dimension inclusing [(0,0), (1,1), (1,2)..(0,7)].Please, can you show me how I get the output GLCM from the above (5*7) patch in my image... best regards – zenab Aug 10 '15 at 21:00
  • @Shama ...please, the value of pixel (1,1) is equal to 60 in my image (as shown in the last comment above)...how matlab quantize my image in where pixels will have values in [0,7] or [1,8] instead of [0,255]. please, still it is ambiguous for me.. I need some explanation – zenab Aug 12 '15 at 18:56
  • @Shama.. I would like to inform you that I understand know how the built-in graycomatrix function quantize the image depending on the gray-level that we specified by using : [glcm, SI] = graycomatrix(I); where SI give me the quantize image values. please, if I use another programming language ..How can I quantize the image values? Please, I need your help – zenab Aug 12 '15 at 20:45
  • 1
    @zenab, great to know that you figured it out. I am just seeing these new comments. Regarding the latest question, say your pixel value is x where x \in [0,255]. Then to quantize image to have, say, 8 levels. You can perform the modulo (integer division operation). Let Y = 256/8 = 32. For each pixel, say in c++, do p_ij = p_ij / Y; Make sure p_ij is an integer. With opencv, you can access pixel values as: cv::Scalar n1; n1 = image.at(i,j); image.at(i,j) = (int)n1.val[0]/Y; where Y = 256/8 = 32 (to have 8 gray levels) – Sanjeev Sharma Aug 15 '15 at 07:55
  • 1
    i wanted to say, in previous comment, do modulo or an integer division operation. I illustrated integer division in C++. You can do the rest. – Sanjeev Sharma Aug 15 '15 at 08:01
  • @Shama ... I want to express to you my thanks and appreciation for your help, I understood GLCM approach through your valuable comments. The last question: Is GLCM size ( in my case is equal to 64 dimension......) can be represent the texture feature? Thank you again – zenab Aug 15 '15 at 16:18
  • 1
    Yes it is already a feature, the 64-dimensional vector in your case. – Sanjeev Sharma Aug 23 '15 at 16:04