GLCM图像中的黑色空间 [英] Black space in GLCM image
问题描述
我正在尝试使用Haralick描述的GLCM(能量,均匀性等)对我拥有的一系列4波段(R,G,B,NIR)航拍图像进行一些质地测量.我已经在一个子集上尝试过了,但是最终得到的图像大部分是空白的.我目前的理解是,它与灰度和levels
参数有关,但我无法弄清楚.
I'm trying to calculate some textural measures using the GLCM described by Haralick (energy, homogeneity, etc.) for a series of 4 band (R, G, B, NIR) aerial photographs that I have. I have tried this on a subset but am ending up with an image that is mostly blank. My current understanding is that it has to do with the greyscaling and the levels
parameter but I can't figure it out.
我的日期非常大(几个GB),所以我试图通过使用模块RIOS来提高效率(以400倍400倍nbands numpy数组的形式读取图像,处理数据并将其写出到输出图像中).
My date is very large (several GB) so I'm trying to be efficient by using the module RIOS (reads an image in as a 400×400×nbands numpy array, processes the data and writes out to an output image).
可以在此处找到我的输入场景(200 MB).
My input scene can be found here (200 MB).
我的输出图像看起来像(由于黑色像素非常小,因此可能很难看到):
My output image looks like (this may be difficult to see as the black pixels are very small):
我的代码是:
#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"参数有关.我已经在这里指出了一个解释: GLCM结果中的黑线可以很好地解释参数,但是我无法改善结果.
Obviously there is something wrong here as my output is not as I expect. My guess that it is to do with the 'levels' parameter. I have been pointed to an explanation here: Black line in GLCM result which explains the parameter well but I am unable to improve my result.
有人可以向我解释为什么我的结果显示出来了,如何补救?
Can someone explain to me why my result is coming out as shown and how I can remedy it?
推荐答案
下面的代码计算与tif图像NIR波段的偏移量向上1像素偏移量向上"相对应的GLCM:
The code below computes the GLCM corresponding to an offset "1-pixel offset upwards" from the NIR band of your tif image:
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
的元素具有相当小的值.这是一个示例:
The effect of setting the parameter normed
to True
is that the computed GLCM is divided by its total sum, and as a result the elements of glcm
have rather small values. Here's a sample:
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
显示为图像,您需要对其重新缩放,例如:
To display glcm
as an image you need to rescale it, for example like this:
from skimage.exposure import rescale_intensity
scaled = rescale_intensity(glcm[:,:,0,0])
io.imshow(scaled)
这篇关于GLCM图像中的黑色空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!