Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correlation metric outside bounds of -1 to +1 #6

Open
ailich opened this issue Mar 27, 2018 · 7 comments
Open

Correlation metric outside bounds of -1 to +1 #6

ailich opened this issue Mar 27, 2018 · 7 comments

Comments

@ailich
Copy link

ailich commented Mar 27, 2018

I'm getting values outside the bounds that should be possible for correlation. Correlation should be constrained to -1 to +1 (when scale_factor=1), but about 1% of the resulting non NA values seem to fall outside this range when using the glcm function on my raster data. The resulting correlation glcm raster has max and min values of +Inf and -Inf and also contains real numbers outside the -1 to +1 bounds ranging from about 2 to 47.
(Running R version 3.4.1 on Windows 10)

@sermomon
Copy link

sermomon commented Jun 5, 2020

@ailich I have had the same problem. Do you have any news? I am trying to apply textural features as input variables of a machine learning model. I have doubts about whether to keep the values obtained (although I do not understand them) or assign 1 to values> 1 and -1 to values <-1.

@ailich
Copy link
Author

ailich commented Jun 5, 2020

@sermomon I have not found a solution to this, but there have been github commits so it's possible that it might be fixed in a newer version (e.g. have you tried with the development branch on github (devtools::install_github("azvoleff /glcm") )? I asked this question on stack overflow and got some answers but I didn't feel that any solved the issue. The inf/-inf values make sense to me as that can happen if your using max and min values with na.rm=TRUE and all the inputs are NA, but the ones outside the range of -1 to 1 that are real numbers are odd to me. I ended up using other metrics because I was not confident in the correlation values. Additionally other free software such as QGIS can be used to calculate these metrics.

Also just some general good resources for GLCM include:
https://prism.ucalgary.ca/bitstream/handle/1880/51900/texture%20tutorial%20v%203_0%20180206.pdf?sequence=11&isAllowed=y

https://www.tandfonline.com/doi/full/10.1080/01431161.2016.1278314?casa_token=M3ukyfRKO9UAAAAA%3A_ErxUHAqr0A3cHVl_EFIwUruzRhta-60xcmnhgz6IV2VJDYUvlUCSKw-JeMw-xO4iazqgW3DUyc

@sermomon
Copy link

sermomon commented Jun 5, 2020

@ailich Thanks for your quick response. I'm going to try with the developing version. I also have access to a Matlab, so I am going to also test from Matlab and report the results. Which tool do you suggest from QGis?

I agree with the comments I have read about the inf and -inf values, but I also don't understand the > 1 and <-1 values. It might be interesting to apply the glcm() function to a raster with the same value for all pixels. If the correlation values = 1, the probability is that it is an error, if, on the contrary, very high values are obtained, the correlation may be on another scale of values. Maybe my contribution is a little inexperienced, but I'm going to do these tests.

https://gis.stackexchange.com/questions/278890/glcm-r-package-correlation-metric-values-outside-bounds-of-1-to-1

@ailich
Copy link
Author

ailich commented Jun 5, 2020

QGIS's processing toolbox has access to functions from many other open source GIS's. r.texture from GRASS GIS should do what you want. It's important to note that "r.texture assumes grey levels ranging from 0 to 255 as input. The input is automatically rescaled to 0 to 255 if the input map range is outside of this range," so you may need to use r.recode and r.quantile as well to do the quantization step. QGIS can also access the Orfeo Toolbox which has a tool to calculate GLCM textures. If you need to code it in R, the RQGIS3 package or RQGIS package lets you call QGIS from R. RQGIS3 is continually developed and works with QGIS3, wile RQGIS is no longer being developed and works with QGIS2. RQGIS3 will give you access to QGIS and GRASS Functions, but cannot link to the Orfeo Toolbox, while RQGIS can also link to the Orfeo Toolbox but its development is no longer being supported. If you do end up using RQGIS/RQGIS3, because you have to do this for many surfaces, I recommend learning how the tool works in QGIS first because having the GUI makes it easier to figure out how to set things up properly.

@ailich
Copy link
Author

ailich commented Jun 17, 2020

I've created a small reproducible example to demonstrate the issue, which could maybe help understand it.

library(raster)
library(glcm)

glcm_corr<- glcm(raster(L5TSR_1986, layer=1), shift=list(c(0,1), c(1,1), c(1,0), c(1,-1)), statistics = "correlation")
glcm_corr[is.infinite(glcm_corr)]<-NA #remove Inf and -Inf

print(maxValue(glcm_corr))
[1] 11.96335 #Max value greater than 1

@ailich
Copy link
Author

ailich commented Jul 6, 2020

@sermomon did you have any luck with the MATLAB comparisons?

@ailich
Copy link
Author

ailich commented Nov 16, 2020

@sermomon, I coded up an alternative implementation here (https://github.com/ailich/GLCMTextures) if you want to test it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants