Subtracting the mean from an image

Subtracting the mean is a common operation that we can see applied in various different settings. It can be used to "detrend" our data and only look at the sources which lead us to observe large deviations from some average value. This can enable us to see "where differences come from" and is useful almost universally where data analysis is needed. The first time I saw this idea was in statistics in the form of a difference between observed and expected value. I suppose that it can also be applied in accounting as well, perhaps as analysis between sales data from different periods. Only recently I realized that it can be used with images to see where the regions of highest energy can be found.

Below you can see an image of a sunset and a couple of birds. It is relatively homogenous, yet the sun and the birds add some detail to it. What we would like to observe is a muted appearance of the same image, where the interesting objects are still present, but stand out more clearly from what appears to be noise.

Image of a sunset and some birds.

Here is the same image when we subtract the means for each individual channel. This is something that requires only very few lines of code and has an almost immediate effect. This image has much lower energy, causes much less sensation and is much easier to look at over time. Notice that it still retains the flare around the sun, but in a more conservative way. Previously the flare felt as part of the noise, whereas now we see how strong it is as part of the signal. There is not much to be said about the birds, except we may now find the smallest one slightly easier to recognize.

Sunset with subtracted mean.

We can also observe the difference between the values in the original image and the mean to see what will be taken away from the first image to produce the second.

Difference between original image and mean value.

The dark and light areas are very homogenous here. If the original value was below the mean, in all three channels, we probably got a dark color as a result; if it was much above the mean, across all channels, we probably got something much lighter. The red contour might indicate very large differences in the red channel, whereas yellow may be the result of the same being valid for the red and green channels. What is interesting here is that we can see how far and in what direction the strong sunshine is affecting the image most.

I hope that this gives you some understanding what you could expect when you look at your own data from a similar lens.