# Holiday post: image vs. averaged background subtraction Figure 1: Image subtraction of the background from the sample image. 30 pixels have elevated intensity, representing parasitic scattering.

When correcting data for the many possible data artefacts, I usually prefer to do these corrections on the 2D images as opposed to the azimuthally averaged data (often referred to by the misnomer “integration”).
This needs to be done for some direction-dependent corrections, such as for the polarization correction, but not necessarily for others. The background correction, for example, can be done in two ways: subtracting the background image (2D) from the measurement image, or subtracting the azimuthally averaged background data (1D) from the azimuthally averaged measured image.
To illustrate the difference, perhaps a small demonstration can suffice.

### Set-up

We define two images: a background image and a sample measurement image. These are completely made-up images, and we give them the nice property that they represent scattering images in polar format: only Q varies along one axis, and only the azimuthal angle along the other.
We imagine that there is a systematic instrumental contribution in the image: perhaps a small contribution from scattering off the edge of one of the slits or pinholes (streaking). Similar scattering can originate from capillary walls or imperfections in window material.
We create two images (Figure 1), 16 by 20 pixels in size, that represent the background and sample measurement. The background image contains zero counts with Poisson noise added, and 30 pixels with an elevated intensity. The sample image is set up in a similar way, with Poisson noise added, and 30 pixels of elevated intensity, but has 20 counts of “signal” added. Figure 1: Image subtraction of the background from the sample image. 30 pixels have elevated intensity, representing parasitic scattering.

We can then attempt to retrieve the signal by subtraction of the background from the sample measurement in two ways: by subtracting the images followed by azimuthal averaging (Figure 1), or by azimuthal averaging followed by subtraction of the averaged data (Figure 2). Figure 2: Background subtraction using azimuthally averaged data from the first two images of Figure 1. The error bars show the standard error on the mean. The error bars on the subtracted data show the propagated uncertainties.

### Conclusion

The conclusion is represented in Figure 3: both approaches result in the identical retrieval of 20 mean counts of signal after subtraction of the background. However, the region of elevated intensity results in a much higher uncertainty estimate on the data subtracted after azimuthal averaging. If we do image subtraction of the background before averaging, such spurious signals can — if they are stable in both measurements — leave no large detrimental effect. Figure 3: The difference between the two approaches, showing a much higher uncertainty when azimuthally averaging before background subtraction. The error bars on the image-subtracted data show the standard error on the mean. $\frac{\sum a_n}{b}\ne \frac{a_0}{b} + ... + \frac{a_n}{b}$ if you only use simple error propagation (i.e. one is ignoring the correlation). $S_{prop} = \sqrt{ S_a^2 + S_b^2 }$