dem灰度共生矩阵纹理特征参数提取python代码
时间: 2023-09-04 14:15:27 浏览: 183
以下是使用Python提取DEM灰度共生矩阵纹理特征参数的示例代码:
```python
import numpy as np
import gdal
from skimage.feature import greycomatrix, greycoprops
# 读取DEM数据
dem_file = "dem.tif"
ds = gdal.Open(dem_file)
dem = ds.ReadAsArray()
# 计算灰度共生矩阵
gcm = greycomatrix(dem, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4], levels=256, normed=True, symmetric=True)
# 提取纹理特征参数
contrast = greycoprops(gcm, 'contrast').flatten()
dissimilarity = greycoprops(gcm, 'dissimilarity').flatten()
homogeneity = greycoprops(gcm, 'homogeneity').flatten()
energy = greycoprops(gcm, 'energy').flatten()
correlation = greycoprops(gcm, 'correlation').flatten()
# 将纹理特征参数保存到CSV文件中
features = np.hstack((contrast, dissimilarity, homogeneity, energy, correlation))
np.savetxt("texture_features.csv", features, delimiter=",")
```
其中,`dem.tif`是DEM数据文件,`greycomatrix`函数用于计算灰度共生矩阵,`greycoprops`函数用于提取纹理特征参数。最后,将提取的纹理特征参数保存到CSV文件中。
阅读全文