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.
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).
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):
My code is:
#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)
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?