【问题标题】:Black space in GLCM imageGLCM 图像中的黑色空间
【发布时间】:2017-04-06 22:16:11
【问题描述】:

我正在尝试使用 Haralick 描述的 GLCM(能量、均匀性等)为我拥有的一系列 4 波段(R、G、B、NIR)航空照片计算一些纹理测量值。我已经在一个子集上尝试过这个,但最终得到的图像大部分是空白的。我目前的理解是它与灰度和levels 参数有关,但我无法弄清楚。

我的日期非常大(几 GB),所以我试图通过使用模块 RIOS 来提高效率(以 400×400×nbands numpy 数组的形式读取图像,处理数据并写入输出图像)。

我的输入场景可以在here (200 MB) 找到。

我的输出图像看起来像(这可能很难看到,因为黑色像素非常小):

我的代码是:

#Set up input and output filenames
infiles = applier.FilenameAssociations()
infiles.image1 = "infile.tif"

outfiles = applier.FilenameAssociations()
outfiles.outimage = "outfile.tif"

controls = applier.ApplierControls()
controls.progress = cuiprogress.CUIProgressBar()
# I ultimately want to use a window here
# which RIOS easily allows you to set up.
# For a 3x3 the overlap is 1, 5x5 overlap is 2 etc
#controls.setOverlap(4)

def doFilter(info, infiles, outfiles, controls=controls):
    grayImg = img_as_ubyte(color.rgb2gray(infiles.image1[3]))
    g = greycomatrix(grayImg, distances=[1], angles=[0, np.pi/4, np.pi/2, 3*np.pi/4], symmetric=True, normed=True)
    filtered = greycoprops(g, 'energy')
    # create 3d image from 2d array
    outfiles.outimage = numpy.expand_dims(filtered, axis=0)


applier.apply(doFilter, infiles, outfiles, controls=controls)

显然这里有问题,因为我的输出与我预期的不一样。我猜这与'levels'参数有关。我在这里被指出了一个解释:Black line in GLCM result,它很好地解释了参数,但我无法改进我的结果。

有人可以向我解释为什么我的结果如图所示,我该如何补救?

【问题讨论】:

  • 你的图像是二进制的,所有的像素强度要么是0要么是255。执行np.unique(<your_image>) 说服自己。此类图像的 GLCM 将只有四个非零条目。
  • numpy.unique 产量 [ 21 22 23 24 25 26 27 28 29 30 3......... 186 187 188 189 190 191 192 193 194 195 196 197 198]
  • 我运行了这段代码:import numpy as npfrom skimage import iox = io.imread('https://i.stack.imgur.com/EyCI1.png')np.unique(x),得到:array([ 0, 255], dtype=uint8)
  • 啊,我的错,这是我输出的截图。我将添加我的真实数据

标签: python numpy feature-extraction scikit-image glcm


【解决方案1】:

以下代码计算 GLCM,对应于 tif 图像 NIR 波段的偏移“向上 1 个像素偏移”:

import numpy as np
from skimage import io
from skimage.feature import greycomatrix, greycoprops

x = io.imread('m_2909112_se_15_1_20150826.tif')
nir = x[:, :, 3]

glcm = greycomatrix(nir, [1], [np.pi/2], levels=256, normed=True, symmetric=True)

nir 的外观是这样的:

将参数normed 设置为True 的效果是计算的GLCM 除以其总和,因此glcm 的元素具有相当小的值。这是一个示例:

In [48]: np.set_printoptions(precision=3)

In [49]: glcm[:5, :5, 0, 0]
Out[49]: 
array([[  0.000e+00,   0.000e+00,   0.000e+00,   0.000e+00,   0.000e+00],
       [  0.000e+00,   2.725e-03,   6.940e-05,   3.725e-05,   2.426e-05],
       [  0.000e+00,   6.940e-05,   1.709e-04,   4.103e-05,   2.216e-05],
       [  0.000e+00,   3.725e-05,   4.103e-05,   4.311e-04,   4.222e-05],
       [  0.000e+00,   2.426e-05,   2.216e-05,   4.222e-05,   5.972e-05]])

要将glcm 显示为图像,您需要重新缩放它,例如:

from skimage.exposure import rescale_intensity
scaled = rescale_intensity(glcm[:,:,0,0])
io.imshow(scaled)

【讨论】:

  • 我已经实现了你的建议,但我的结果是一样的。我已经使用 print 语句对输出进行了更多研究。正如我所料,数据正在以块的形式被读取,例如: [174 169 176 179 200 203 200 183 175 192 186 180 183 181 187 178 170 177 171 ......173 166 155 148 166 162 1638 115 146 172 170 172 173 173 180 181 173 171 171] 但 graycomatrix 的结果通常为空,如 [0 0 0 0],只有少数已填充,如 [0 1 0 1]。这实际上是将空白数组传递给 graycoprops 命令。
猜你喜欢
  • 1970-01-01
  • 2017-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-25
  • 1970-01-01
  • 1970-01-01
  • 2018-06-18
相关资源
最近更新 更多