My purpose is to describe the characteristics of the texture of the image through a single value (eg, second angular momentum ASM), similar to what Haralick presents in Figure 4 of his article.

The package 'Rtexturemetrics' by The Hans-Joachim Klemmt seems to do this for me. Howover I'm not sure what radiometry parameters are required in the input image to make the GLCM.

The function description tells me that the raw data is replacement for the 0-255 range, but the layout of the plotted matrix looks strange compared to the results of python or matlab libraries .

I'm looking for help to understand if genGLCM needs some preparation in the image other than how I perceive it.

    # comparison of pre-processing
    # path.list <- list.files(path="C:/r_dren",pattern="len_acc_cf[[:digit:]]*.asc",full.names=T)

    #----Image raw "FLT4S" floating point ----

    image.raw <- raster(path.list[1])
    raw_na <- image.raw[!is.na(image.raw[])]
    image.raw[is.na(image.raw[])] <- mean(raw_na)
    image.raw[] <- as.integer(image.raw[])

class       : RasterLayer 
dimensions  : 170, 172, 29240  (nrow, ncol, ncell)
resolution  : 30, 30  (x, y)
extent      : 794418.4, 799578.4, 7400299, 7405399  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=22 +south +ellps=WGS84 +units=m +no_defs 
data source : in memory
names       : len_acc_cf0 
values      : 0, 36  (min, max)

     #  GLCM  raw.data
    east.right.raw <- genGLCM(direction=1,distance=1,image.raw) 
    south.down.raw <- genGLCM(direction=2,distance=1,image.raw)

    # ----Image standarized at 0-255 intervals,"FLT4S" floating ----

    image.stand <- calc(image.raw, fun=function(x){((x - min(x)) * 255)/(max(x)- min(x)) + 0})

    # ----  raster 8b 'INT1U'------

    image8b <- raster(nrow=170, ncol=172)
    image8b[] <- image.raw[]
    dataType(image8b) = "INT1U"

    # ----- processing GLCM's ------

    east.right.standardized <- genGLCM(direction=1,distance=1,image.stand) 
    south.down.standardized <- genGLCM(direction=2,distance=1,image.stand)

    east.right.8b_int <- genGLCM(direction=1,distance=1, image8b) 
    south.down.8b_int <- genGLCM(direction=2,distance=1, image8b)

    # ------ plot GLCM's --------

    par(mfrow =c(3,2))



enter image description here

  • Can you explain why you are performing an image standardization? Also, if you want the Angular Second Moment why not use the RTextureMetrics::calcASM function? – Jeffrey Evans Jan 29 at 23:01
  • Dear Evans, the calcASM function needs a GLCM as input (depending on distance and direction). I'm not sure if I'm correctly supplying the image for the GLCM calculation. The non-standarized image returns a GLCM plot showing a squeezed (badly distributed) graphic. What is the reason for the GLCM plot to present this different shape of other results that I have found? – viniciovcl Jan 30 at 11:33

Your Answer

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

Browse other questions tagged or ask your own question.