python open cv 图像纹理计算_使用scikit-image和Python实现GLCM纹理特征

该脚本展示了如何使用Python、scikit-image库和gdal等工具计算图像的GLCM(灰度共生矩阵)纹理特征。通过并行处理和滑动窗口方法,对输入栅格数据进行重采样、计算对比度、不相似度、均匀度、能量、相关性和熵等纹理特征,并将结果导出为GeoTIFF栅格文件。
摘要由CSDN通过智能技术生成

我有同样的问题,不同的数据.这是我编写的一个脚本,它使用并行处理和滑动窗口方法:

import gdal, osr

import numpy as np

from scipy.interpolate import RectBivariateSpline

from numpy.lib.stride_tricks import as_strided as ast

import dask.array as da

from joblib import Parallel, delayed, cpu_count

import os

from skimage.feature import greycomatrix, greycoprops

def im_resize(im,Nx,Ny):

'''

resize array by bivariate spline interpolation

'''

ny, nx = np.shape(im)

xx = np.linspace(0,nx,Nx)

yy = np.linspace(0,ny,Ny)

try:

im = da.from_array(im, chunks=1000) #dask implementation

except:

pass

newKernel = RectBivariateSpline(np.r_[:ny],np.r_[:nx],im)

return newKernel(yy,xx)

def p_me(Z, win):

'''

loop to calculate greycoprops

'''

try:

glcm = greycomatrix(Z, [5], [0], 256, symmetric=True, normed=True)

cont = greycoprops(glcm, 'contrast')

diss = greycoprops(glcm, 'dissimilarity')

homo = greycoprops(glcm, 'homogeneity')

eng = greycoprops(glcm, 'energy')

corr = greycoprops(glcm, 'correlation')

ASM = greycoprops(glcm, 'ASM')

return (cont, diss, homo, eng, corr, ASM)

except:

return (0,0,0,0,0,0)

def read_raster(in_raster):

in_raster=in_raster

ds = gdal.Open(in_raster)

data = ds.GetRasterBand(1).ReadAsArray()

data[data<=0] = np.nan

gt = ds.GetGeoTransform()

xres = gt[1]

yres =

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值