Nanog timelapse example

Install and import the dependencies

[1]:
# install the basicpy in case of Google Colaboratory
try:
    import google.colab

    %pip uninstall -yq basicpy
    %pip install --upgrade -q basicpy
except ModuleNotFoundError:
    pass
[2]:
from basicpy import BaSiC
from basicpy import datasets as bdata
from matplotlib import pyplot as plt

Load the sample images

[3]:
images = bdata.timelapse_nanog()
plt.imshow(images[10])
Downloading file 'timelapse_nanog.npz' from 'doi:10.5281/zenodo.6974039/timelapse_nanog.npz' to '/home/docs/.cache/basicpy'.
[3]:
<matplotlib.image.AxesImage at 0x7f61f544ff10>
../_images/notebooks_timelapse_nanog_5_2.png

Fit the flatfield and darkfield (try 1)

[4]:
basic = BaSiC(get_darkfield=True, smoothness_flatfield=1)
basic.fit(images)

Plot the fit results (try 1)

[5]:
fig, axes = plt.subplots(1, 3, figsize=(9, 3))
im = axes[0].imshow(basic.flatfield)
fig.colorbar(im, ax=axes[0])
axes[0].set_title("Flatfield")
im = axes[1].imshow(basic.darkfield)
fig.colorbar(im, ax=axes[1])
axes[1].set_title("Darkfield")
axes[2].plot(basic.baseline)
axes[2].set_xlabel("Frame")
axes[2].set_ylabel("Baseline")
fig.tight_layout()
../_images/notebooks_timelapse_nanog_9_0.png

Fit the flatfield and darkfield (try 2)

[6]:
basic = BaSiC(
    get_darkfield=True, smoothness_flatfield=1, smoothness_darkfield=5
)  # increase smoothness_flatfield for smoother flatfield
basic.fit(images)

Plot the fit results (try 2)

[7]:
fig, axes = plt.subplots(1, 3, figsize=(9, 3))
im = axes[0].imshow(basic.flatfield)
fig.colorbar(im, ax=axes[0])
axes[0].set_title("Flatfield")
im = axes[1].imshow(basic.darkfield)
fig.colorbar(im, ax=axes[1])
axes[1].set_title("Darkfield")
axes[2].plot(basic.baseline)
axes[2].set_xlabel("Frame")
axes[2].set_ylabel("Baseline")
fig.tight_layout()
../_images/notebooks_timelapse_nanog_13_0.png

Correct the original images

[8]:
images_transformed = basic.transform(images, timelapse=True)

Plot the corrected results

[9]:
for i in range(0, 21, 5):
    fig, axes = plt.subplots(1, 2, figsize=(6, 3))
    im = axes[0].imshow(images[i])
    fig.colorbar(im, ax=axes[0])
    axes[0].set_title("Original")
    im = axes[1].imshow(images_transformed[i])
    fig.colorbar(im, ax=axes[1])
    axes[1].set_title("Corrected")
    fig.suptitle(f"frame {i}")
    fig.tight_layout()
../_images/notebooks_timelapse_nanog_17_0.png
../_images/notebooks_timelapse_nanog_17_1.png
../_images/notebooks_timelapse_nanog_17_2.png
../_images/notebooks_timelapse_nanog_17_3.png
../_images/notebooks_timelapse_nanog_17_4.png
[ ]: