I want to apply a GLCM texture filter to some aerial photographs that I have. I am using the skimage package to compute the GLCM and a package called rios to handle the i/o.

Rios - raster input output simplification - reads imagery in as a 400 x 400 x nbands numpy array and handles the creation of the output dataset paramaters. It is designed to handle very large datasets in a memory efficient way and also enables the user to set a moving window. I understand that I need to use caution when reading an image in in blocks and applying a moving window but I am not at the stage where I am implementing a window yet.

I can get my code to run but the result is an output made up of zeros with the occasional grey pixel. Ultimately I don't understand what the parameters I am using do. I consulted the documentation but it doesn't give any more than a brief description or examples of what different parameter values will achieve.

Thus far, I have:

# 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()

# Apply a moving window if required
# 3x3 the overlap is 1, 5x5 overlap is 2 etc
# I have yet to try this as i'm trying to get something basic working first

# Apply Texture
def doFilter(info, infiles, outfiles, controls=controls):
    g = greycomatrix(infiles.image1[3], [1], [0], 256, normed=True, symmetric=True)
    filtered = greycoprops(g, 'contrast')
    # create 3d image from 2d array
    outfiles.outimage = numpy.expand_dims(filtered, axis=0)

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

Could someone help explain what the parameters within the greycomatrix mean and how I would expect the GLCM to behave under different parameter values? They are referred to in the documentation as:

greycomatrix(input array, distances, angles, levels, normed=True, symmetric=True)

The parameters distances, angles and levels are the ones I understand the least.


Could you post a bit more of your code? I'm not familiar with rios or applier, although it looks interesting.

I have had this problem myself, although frustratingly I can't remember what was needed to fix it - I've tried breaking various things in my code but no luck.

As far as the glcm parameters go:

"distances" is a list of distances (in pixels) between the pixels being compared

"angles" is a list of angles (in radians) between pixels being compared

"levels" are the grey levels counted from the input image

A matrix is calculated for every distance-angle combination. As far as choosing them goes, the best combinations will depend on the image and the features of interest within this. I tend to create many images with different parameters and then do a correlation matrix to see which combination of parameters gives the most information.

For levels, I would recommend you explicitly convert your image to uint8 before starting, and then don't set this parameter. Also make sure that the datatype of your output image is a float.

This site has a good introduction to the glcm.

  • The entirety of my code is posted above. RIOS handles the opening and closing of files so the code ends up being remarkably short. In the end, the stack overflow community helped me understand why this won't work for what I want. Its an idea that I abandoned when I worked out that I have far too much data to process like this in an efficient way. – Nathan Thomas Apr 24 '17 at 22:25
  • Yes I had a go with RIOS and had the same conclusion. You can do it with numpy array indexing, but as you have said it is very slow. – user6072577 Apr 25 '17 at 8:11
  • Although in 'everyday use' RIOS is extremely powerful. By reading in blocks of data it is able to process large files in a memory efficient way. It's worth looking not if you use very large datasets – Nathan Thomas Apr 25 '17 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.