首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GLCM特征提取

GLCM特征提取
EN

Stack Overflow用户
提问于 2021-11-01 11:35:58
回答 1查看 1.8K关注 0票数 1

所以我正在读一篇研究论文[链接],它有下面的Algo来获取图像的纹理。

所以我从上面了解到的是,我需要建立4x4的网格,然后为每个4x4子矩阵找到GLCM矩阵,然后计算这些属性。

但是我对这个方法的问题是,图像的大小是256x384,它给出了64*96个网格,计算一个GLCM矩阵64*96次,计算量非常大,特别是因为我有900幅这样的图像。

守则如下:

代码语言:javascript
复制
def texture_extract(img):
    distance = [1]
    angles = [0, np.pi/4, np.pi/2, 3*np.pi/4]
    properties = ['correlation', 'homogeneity', 'contrast', 'energy', 'dissimilarity']

    gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(gray_img, (5,5), 0)

    texture_features = []
    for i in range(0, blur.shape[0], 4):
        for j in range(0, blur.shape[1], 4):
            block = blur[i:i+4, j:j+4]

            glcm_mat = greycomatrix(block, distances=distance, angles=angles, symmetric=True, normed=True)
            block_glcm = np.hstack([greycoprops(glcm_mat, props).ravel() for props in properties])
            texture_features.append(block_glcm)

    return np.concatenate(texture_features)

我只想知道,我对算法的理解是正确的,还是我在某个地方犯了一个愚蠢的错误。

EN

回答 1

Stack Overflow用户

发布于 2022-06-23 19:49:34

我就是这样用的,一般的方式和你的一样。

GLCM性质定义

代码语言:javascript
复制
import numpy as np
from skimage.feature import greycomatrix, greycoprops
from skimage import io, color, img_as_ubyte

# GLCM properties
def contrast_feature(matrix_coocurrence):
    contrast = greycoprops(matrix_coocurrence, 'contrast')
    return contrast

def dissimilarity_feature(matrix_coocurrence):
    dissimilarity = greycoprops(matrix_coocurrence, 'dissimilarity')    
    return dissimilarity

def homogeneity_feature(matrix_coocurrence):
    homogeneity = greycoprops(matrix_coocurrence, 'homogeneity')
    return homogeneity

def energy_feature(matrix_coocurrence):
    energy = greycoprops(matrix_coocurrence, 'energy')
    return energy

def correlation_feature(matrix_coocurrence):
    correlation = greycoprops(matrix_coocurrence, 'correlation')
    return correlation

def asm_feature(matrix_coocurrence):
    asm = greycoprops(matrix_coocurrence, 'ASM')
    return asm

bins32 = np.array([0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160,
            168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 255]) #32-bit

GLCM性质的计算

代码语言:javascript
复制
from skimage.feature import greycomatrix, greycoprops
from skimage import data
from skimage import util, exposure, data
import pywt
from skimage import io
from skimage.color import rgb2gray

lenx = x_train.shape[0] # Your image array!
X_correlationTRAIN = np.zeros((lenx, 4))
...

for i in range(lenx):
    image32 = x_train[i] # Your image array!
    image32 = rgb2gray(image32)
    np.clip(image32, 0, 255, out=image32)
    image = image32.astype('uint8')
    inds = np.digitize(image, bins32)

    max_value = inds.max()+1
    matrix_coocurrence = greycomatrix(inds, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4], levels=max_value, normed=False, symmetric=False)

    X_correlationTRAIN[i] = correlation_feature(matrix_coocurrence)
    ...
    ...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69796388

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档