Using skimage for non-rectangular image areas

纵然是瞬间 提交于 2019-12-11 05:47:26

问题


Let's say I'm concerned with part of an image that I'm wanting to calculate a GLCM for that's not rectangular. How should I go about this? I've made a masking procedure that zeroes out the portion of the image that I don't care about, I just don't know how to take this "masked" image without considering the zeroed out portions of the image...

Thanks for your help!


回答1:


If you are able to assign the zero intensity value to background pixels, you can obtain the GLCM of the region of interest by simply discarding the first line and the first column of the full image's GLCM. This actually equivals to getting rid of those co-occurrences that involve background pixels.

Demo

The following snippet demonstrates how to extract a couple of Haralick features from the GLCMs of a circular object on a black background:

In [25]: import numpy as np

In [26]: from skimage import io

In [27]: from skimage.feature import greycomatrix, greycoprops

In [28]: img = io.imread('https://i.stack.imgur.com/6ESoP.png')

In [29]: glcm = greycomatrix(img, 
    ...:                     distances=[1, 2], 
    ...:                     angles=[0, np.pi/4, np.pi/2, 3*np.pi/4],
    ...:                     symmetric=True,
    ...:                     normed=False)
    ...: 

In [30]: glcm_br = glcm[1:, 1:, :, :]

In [31]: glcm_br_norm = np.true_divide(glcm_br, glcm_br.sum(axis=(0, 1)))

In [32]: np.set_printoptions(threshold=1000, precision=4)

In [33]: props = ['energy', 'homogeneity']

In [34]: feats_br = np.hstack([greycoprops(glcm_br_norm, p).ravel() for p in props])

In [35]: feats_br
Out[35]: 
array([ 0.0193,  0.0156,  0.0173,  0.0166,  0.0151,  0.0156,  0.0136,
        0.0166,  0.1255,  0.0788,  0.0978,  0.0929,  0.0782,  0.0788,
        0.0545,  0.0929])

Please notice that the GLCM has to be normalized after getting rid of the first line and the first column of the GLCM of the full image.

Note: the suffix _br stands for background removed.



来源:https://stackoverflow.com/questions/44444935/using-skimage-for-non-rectangular-image-areas

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