the method of calculate the GLCM of a specific point in a image

て烟熏妆下的殇ゞ 提交于 2019-12-12 02:46:50

问题


As we know, GLCM (Grey Level Co-occurrence Matrix) describes the texture characteristics of images. But in usual, the calculation of GLCM in OpenCV, matlab often aim on a picture. But now I just want to get GLCM value of every single point inside the image, but how to get it?


回答1:


If I understand your problem correctly, then perhaps you can just set the pixels outside your region of interest to NaN - these pixels are ignored by MATLAB when calculating the GLCM.

For example:

>> im = eye(7)
im =
     1     0     0     0     0     0     0
     0     1     0     0     0     0     0
     0     0     1     0     0     0     0
     0     0     0     1     0     0     0
     0     0     0     0     1     0     0
     0     0     0     0     0     1     0
     0     0     0     0     0     0     1
>> graycomatrix(im)
ans =
    30     0     0     0     0     0     0     6
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     6     0     0     0     0     0     0     0
>> im([1:10,13:16,21:24,28:29,34:37,41:49]) = NaN % Remove pixels outside ROI
im =
   NaN   NaN   NaN   NaN   NaN   NaN   NaN
   NaN   NaN   NaN   NaN     0   NaN   NaN
   NaN   NaN     1   NaN     0     0   NaN
   NaN     0     0     1     0     0   NaN
   NaN     0     0     0     1     0   NaN
   NaN   NaN     0     0   NaN   NaN   NaN
   NaN   NaN   NaN   NaN   NaN   NaN   NaN
>> warning('off', 'Images:graycomatrix:scaledImageContainsNan')
>> graycomatrix(im)
ans =
     6     0     0     0     0     0     0     2
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     2     0     0     0     0     0     0     0
>> warning('on', 'Images:graycomatrix:scaledImageContainsNan')

Does that do what you need?



来源:https://stackoverflow.com/questions/8237000/the-method-of-calculate-the-glcm-of-a-specific-point-in-a-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!