Note
Go to the end to download the full example code. or to run this example in your browser via Binder
Measure fluorescence intensity at the nuclear envelope#
This example reproduces a well-established workflow in bioimage data analysis for measuring the fluorescence intensity localized to the nuclear envelope, in a time sequence of cell images (each with two channels and two spatial dimensions) which shows a process of protein re-localization from the cytoplasmic area to the nuclear envelope. This biological application was first presented by Andrea Boni and collaborators in [1]; it was used in a textbook by Kota Miura [2] as well as in other works ([3], [4]). In other words, we port this workflow from ImageJ Macro to Python with scikit-image.
import matplotlib.pyplot as plt
import numpy as np
import plotly.io
import plotly.express as px
from scipy import ndimage as ndi
from skimage import filters, measure, morphology, segmentation
from skimage.data import protein_transport
We start with a single cell/nucleus to construct the workflow.
image_sequence = protein_transport()
print(f'shape: {image_sequence.shape}')
shape: (15, 2, 180, 183)
The dataset is a 2D image stack with 15 frames (time points) and 2 channels.
vmin, vmax = 0, image_sequence.max()
fig = px.imshow(
image_sequence,
facet_col=1,
animation_frame=0,
zmin=vmin,
zmax=vmax,
binary_string=True,
labels={'animation_frame': 'time point', 'facet_col': 'channel'},
)
plotly.io.show(fig)
To begin with, let us consider the first channel of the first image (step
a)
in the figure below).
image_t_0_channel_0 = image_sequence[0, 0, :, :]
Segment the nucleus rim#
Let us apply a Gaussian low-pass filter to this image in order to smooth it
(step b)
).
Next, we segment the nuclei, finding the threshold between the background
and foreground with Otsu’s method: We get a binary image (step c)
). We
then fill the holes in the objects (step c-1)
).
smooth = filters.gaussian(image_t_0_channel_0, sigma=1.5)
thresh_value = filters.threshold_otsu(smooth)
thresh = smooth > thresh_value
fill = ndi.binary_fill_holes(thresh)
Following the original workflow, let us remove objects which touch the image
border (step c-2)
). Here, we can see that part of another nucleus was
touching the bottom right-hand corner.
dtype('bool')
We compute both the morphological dilation of this binary image
(step d)
) and its morphological erosion (step e)
).
Finally, we subtract the eroded from the dilated to get the nucleus rim
(step f)
). This is equivalent to selecting the pixels which are in
dilate
, but not in erode
:
mask = np.logical_and(dilate, ~erode)
Let us visualize these processing steps in a sequence of subplots.
fig, ax = plt.subplots(2, 4, figsize=(12, 6), sharey=True)
ax[0, 0].imshow(image_t_0_channel_0, cmap=plt.cm.gray)
ax[0, 0].set_title('a) Raw')
ax[0, 1].imshow(smooth, cmap=plt.cm.gray)
ax[0, 1].set_title('b) Blur')
ax[0, 2].imshow(thresh, cmap=plt.cm.gray)
ax[0, 2].set_title('c) Threshold')
ax[0, 3].imshow(fill, cmap=plt.cm.gray)
ax[0, 3].set_title('c-1) Fill in')
ax[1, 0].imshow(clear, cmap=plt.cm.gray)
ax[1, 0].set_title('c-2) Keep one nucleus')
ax[1, 1].imshow(dilate, cmap=plt.cm.gray)
ax[1, 1].set_title('d) Dilate')
ax[1, 2].imshow(erode, cmap=plt.cm.gray)
ax[1, 2].set_title('e) Erode')
ax[1, 3].imshow(mask, cmap=plt.cm.gray)
ax[1, 3].set_title('f) Nucleus Rim')
for a in ax.ravel():
a.set_axis_off()
fig.tight_layout()
Apply the segmented rim as a mask#
Now that we have segmented the nuclear membrane in the first channel, we use it as a mask to measure the intensity in the second channel.
image_t_0_channel_1 = image_sequence[0, 1, :, :]
selection = np.where(mask, image_t_0_channel_1, 0)
fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(12, 6), sharey=True)
ax0.imshow(image_t_0_channel_1)
ax0.set_title('Second channel (raw)')
ax0.set_axis_off()
ax1.imshow(selection)
ax1.set_title('Selection')
ax1.set_axis_off()
fig.tight_layout()