skimage.feature.greycomatrix 只产生对角线值
skimage.feature.greycomatrix only producing diagonal values
我正在尝试在减少趋势的数字高程模型上生成 glcm。我当前的问题是 skimage.feature.greycomatrix(image) 的输出仅包含矩阵对角线项中的值。
glcm = greycomatrix(image,distances=[1],levels=100,angles=[0] ,symmetric=True,normed=True)
使用以下代码先对图像进行量化:
import numpy as np
from skimage.feature import greycomatrix
def quantize(raster):
print("\n Quantizing \n")
raster += (np.abs(np.min(raster)) + 1)
mean = np.nanmean(raster.raster[raster.raster > 0])
std = np.nanstd(raster.raster[raster.raster > 0])
raster[raster == None] = 0 # set all None values to 0
raster[np.isnan(raster)] = 0
raster[raster > (mean + 1.5*std)] = 0
raster[raster < (mean - 1.5*std)] = 0 # High pass filter
raster[raster > 0] = raster[raster > 0] - (np.min(raster[raster > 0]) - 1)
raster[raster>101] = 0
raster = np.rint(raster)
flat = np.ndarray.flatten(raster[raster > 0])
range = np.max(flat) - np.min(flat)
print("\n\nRaster Range: {}\n\n".format(range))
raster = raster.astype(np.uint8)
raster[raster > 101] = 0
我将如何着手让 glcm 计算对角矩阵之外的值(即只是值本身的频率),我的方法是否存在根本性错误?
如果图像中的像素强度相关,则两个相似级别同时出现的可能性很大,因此相应的GLCM的非零元素将集中在主对角线周围。相反,如果像素强度不相关,则 GLCM 的非零元素将遍布整个矩阵。以下示例使这一点显而易见:
import numpy as np
from skimage import data
import matplotlib.pyplot as plt
from skimage.feature import greycomatrix
x = data.brick()
y = data.gravel()
mx = greycomatrix(x, distances=[1], levels=256, angles=[0], normed=True)
my = greycomatrix(y, distances=[1], levels=256, angles=[0], normed=True)
fig, ax = plt.subplots(2, 2, figsize=(12, 8))
ax[0, 0].imshow(x, cmap='gray')
ax[0, 1].imshow(mx[:, :, 0, 0])
ax[1, 0].imshow(y, cmap='gray')
ax[1, 1].imshow(my[:, :, 0, 0])
尽管我没有看到您的光栅图像,但我猜测 quantize
返回的图像中的强度变化非常平滑,因此 GLCM 主要是对角线的。
我正在尝试在减少趋势的数字高程模型上生成 glcm。我当前的问题是 skimage.feature.greycomatrix(image) 的输出仅包含矩阵对角线项中的值。
glcm = greycomatrix(image,distances=[1],levels=100,angles=[0] ,symmetric=True,normed=True)
使用以下代码先对图像进行量化:
import numpy as np
from skimage.feature import greycomatrix
def quantize(raster):
print("\n Quantizing \n")
raster += (np.abs(np.min(raster)) + 1)
mean = np.nanmean(raster.raster[raster.raster > 0])
std = np.nanstd(raster.raster[raster.raster > 0])
raster[raster == None] = 0 # set all None values to 0
raster[np.isnan(raster)] = 0
raster[raster > (mean + 1.5*std)] = 0
raster[raster < (mean - 1.5*std)] = 0 # High pass filter
raster[raster > 0] = raster[raster > 0] - (np.min(raster[raster > 0]) - 1)
raster[raster>101] = 0
raster = np.rint(raster)
flat = np.ndarray.flatten(raster[raster > 0])
range = np.max(flat) - np.min(flat)
print("\n\nRaster Range: {}\n\n".format(range))
raster = raster.astype(np.uint8)
raster[raster > 101] = 0
我将如何着手让 glcm 计算对角矩阵之外的值(即只是值本身的频率),我的方法是否存在根本性错误?
如果图像中的像素强度相关,则两个相似级别同时出现的可能性很大,因此相应的GLCM的非零元素将集中在主对角线周围。相反,如果像素强度不相关,则 GLCM 的非零元素将遍布整个矩阵。以下示例使这一点显而易见:
import numpy as np
from skimage import data
import matplotlib.pyplot as plt
from skimage.feature import greycomatrix
x = data.brick()
y = data.gravel()
mx = greycomatrix(x, distances=[1], levels=256, angles=[0], normed=True)
my = greycomatrix(y, distances=[1], levels=256, angles=[0], normed=True)
fig, ax = plt.subplots(2, 2, figsize=(12, 8))
ax[0, 0].imshow(x, cmap='gray')
ax[0, 1].imshow(mx[:, :, 0, 0])
ax[1, 0].imshow(y, cmap='gray')
ax[1, 1].imshow(my[:, :, 0, 0])
尽管我没有看到您的光栅图像,但我猜测 quantize
返回的图像中的强度变化非常平滑,因此 GLCM 主要是对角线的。