Use rolling-ball algorithm for estimating background intensity
The rolling-ball algorithm estimates the background intensity of a grayscale image. It comes in useful, for instance, in case of uneven exposure, when subtracting the background is desirable. It is frequently used in biomedical image processing and was first proposed by Stanley R. Sternberg in 1983 [1].
The algorithm works as a filter: Think of the image as a surface that has unit-sized blocks stacked on top of each other in place of each pixel. The number of blocks, and hence surface height, is determined by the intensity of the pixel. To get the intensity of the background at a desired (pixel) position, we imagine submerging a ball under the surface at the desired position. Once it is completely covered by the blocks, the apex of the ball determines the intensity of the background at that position. We can then ‘roll’ this ball around below the surface to get the background values for the entire image. The larger the ball, the smoother the background.
scikit-image implements a generalized version of this rolling-ball algorithm, allowing you to work with n-dimensional images and to use not only balls, but other kernels as well. This way, you may directly filter RGB images or image stacks along any (or all) spatial dimensions.









