# How to Calculate Local Spatial Variance of an Image?

For those who work often on image processing, I'm facing an algorithm of Non-Uniformity Correction (NUC) that requires the calculation of a parameter called "Local Spatial Variance". I can't find a definition for it.

Does anyone have any idea about it ?

The article is called A Novel Infrared Focal Plane Non Uniformity Correction Method Based on Co Occurrence Filter and Adaptive Learning Rate, IEEE Access, 2019.
The "Local Spatial Variance" is on the 3rd page if you please.

Non-Uniformity Correction often refers to the notion that, all things being equal (with respect to the object observed), the actual pixel value may be affected by bias (offset) and noise (deviation around the offset). When all offsets and noise powers are (almost) constant across the pictures in space and time, then one can treat pixels equally. If not, pixels may exhibit drifts and noises whose power vary. They can be complicated to model, yet you can try to correct them locally in a window $$W$$ around location $$(i,j)$$, around some estimated average and standard deviation.

Given a pixel at location $$(i,j)$$ with value $$p[i,j]$$, and weights $$w[i,j]$$ (you can set them to one if too complicated), you can get an average:

$$\hat{p}[i,j] = \frac{\sum_{(k,l)\in W}w[k,l]p[k,l]}{\sum_{(k,l)\in W}w[k,l]}$$ or $$\hat{p}[i,j]=\mathrm{mean_{(k,l)\in W}\;}p[k,l]$$ when the weights are equal. The local spatial variance is then:

$$\hat{\sigma}^2[i,j] = \frac{\sum_{(k,l)\in W}w[k,l](p[i,j]-{p}[k,l])^2}{\sum_{(k,l)\in W}w[k,l]}$$ or

$$\hat{\sigma}^2[i,j]=\mathrm{mean_{(k,l)\in W}\;}(p[i,j]-{p}[k,l])^2$$

It is not uncommon to correct an image by an offset/variance correction as:

$${p}[i,j]\to \frac{{p}[i,j]-\hat{p}[i,j]}{\hat{\sigma}[i,j]}$$

Usually it means the variance within a window of pixels where the (i, j) pixel is in its center:

In the above you can see a 3 x 3 window (Radius of 1).
You'd calculate the variance in this window and set its value to the location of the Pij pixel.