Divide by Gaussian#

When processing images with membrane staining it sometimes happens that the intensity of the membranes is not homogeneous and changes locally. This intensity variation may impair cell segmentation algorithms. In these cases it may make sense to homogenize the intensity by dividing the image by a Gaussian blurred version of itself.

import pyclesperanto_prototype as cle
from skimage.io import imread, imshow
from skimage.filters import gaussian

In this image you see that the intensity of the membranes decreases from top to bottom.

image = imread('../../data/membranes_2d.tif')
cle.asarray(image)
cle._ image
shape(256, 256)
dtypefloat32
size256.0 kB
min547.0
max32145.0

This intensity gradient can be removed by dividing the image by its background, a Gaussian blurred version of it self.

intensity_equivalized = cle.divide_by_gaussian_background(image, sigma_x=10, sigma_y=10)
intensity_equivalized
cle._ image
shape(256, 256)
dtypefloat32
size256.0 kB
min0.32106277
max9.812795

How it works#

To demonstrate how it works, we will do the same operation using two steps using scikit-image and numpy.

background = gaussian(image, sigma=10)
imshow(background, cmap="Greys_r")
C:\Users\haase\mambaforge\envs\bio39\lib\site-packages\skimage\io\_plugins\matplotlib_plugin.py:150: UserWarning: Low image data range; displaying image with stretched contrast.
  lo, hi, cmap = _get_display_range(image)
<matplotlib.image.AxesImage at 0x1aa03625160>
../_images/877863f43d14513d9058d0a9ec9c00dd8807c51b7186cf4535b944a5ad9dd17d.png
result = image / background
imshow(result, cmap="Greys_r")
C:\Users\haase\mambaforge\envs\bio39\lib\site-packages\skimage\io\_plugins\matplotlib_plugin.py:150: UserWarning: Float image out of standard range; displaying image with stretched contrast.
  lo, hi, cmap = _get_display_range(image)
<matplotlib.image.AxesImage at 0x1aa0350d580>
../_images/ad34f3291ef39b6d4d71af83fb281fc7f5a7aea0648c2907e7884b0587083afc.png