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>

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()

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()

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()





[ ]: