# Pixel based Correlation for 2 Rasters

I was working with Pollution data from OMI i.e. NO2 & O3.

I need to find the correlation between the two rasters.

I need pixel-based correlation, but in ArcGIS Pro, I could only find point-based correlation.

How do I do pixel-based correlation for the rasters?

• is it absolutely necessary to use ArcGIS Pro? Jan 28, 2021 at 13:02
• You can do it in QGIS/GRASS GIS and it is for free. Jan 28, 2021 at 13:40
• Hii @Alešinar, No, but I only have ArcGIS license. Guess this could be done in ERDAS and Python also. I'm not that aware of writing code, If you have any code Kindly share me, I use spyder IDE. Or any other method will also do. Jan 28, 2021 at 13:45
• OK could u tell me what tools i must be using Jan 28, 2021 at 13:46

Download and install latest QGIS with GRASS GIS. The tool is r.covar under the GRASS tools. It outputs the covariance/correlation matrix.

• That is not pixel based correlation but, rather global. Jan 28, 2021 at 14:53

Please look at this post for some clarity on your problem and take note that, the way you are describing your analysis, the results would be nonsense. You cannot derive a correlation using two observations. However, you can use a moving window approach. I would also mention that, without evaluating the significance, a global correlation can be dubious. The rule of large numbers causes a distribution convergence in raster data and can easily cause spurious correlations. To support a global correlation between two rasters one should produce a p-value to indicate signifiance.

The Geomorphometry & Gradient Metrics toolbox has a correlation function that derives a moving window correlation raster. It should be compatible with ArcPro under Python 3 but, is not extensively tested and I am no longer supporting the toolbox. In theory, ESRI has take over maintenance so if you have any issues you can contact Shawn Walbridge at ESRI. You could also just grab the correlation.py file as it has everything you need to perform this analysis.

Here is the raster algebra, in ESRI parlance, to return a moving window correlation.

``````tmpXY = Times(rasterOne, rasterTwo)
xBar = FocalStatistics(rasterOne, analysisWindow, "MEAN")
yBar = FocalStatistics(rasterTwo, analysisWindow, "MEAN")
xyBar = FocalStatistics(tmpXY, analysisWindow, "MEAN")
coVar = Minus(xyBar, Times(xBar, yBar))
xStd = FocalStatistics(rasterOne, analysisWindow, "STD")
yStd = FocalStatistics(rasterTwo, analysisWindow, "STD")
xyStd = Times(xStd, yStd)
corr = Divide(coVar, xyStd)
``````