BIA Bob demo#

BIA Bob is a Jupyter-magic based assistant for interacting with data via code

from bia_bob import bob

You can use the %bob single-line or the %%bob multi-line magic to ask for programming image analysis tasks and bob will do it for you.

%bob Load the blobs.tif image file and show it.
This notebook may contain text, code and images generated by artificial intelligence. Used model: claude-3-opus-20240229, vision model: claude-3-opus-20240229, endpoint: None, bia-bob version: 0.18.0. It is good scientific practice to check the code and results it produces carefully. Read more about code generation using bia-bob.

I will load the blobs.tif image and display it using stackview.insight.

from skimage.io import imread
import stackview

image = imread('blobs.tif')
stackview.insight(image)
shape(254, 256)
dtypeuint8
size63.5 kB
min8
max248
%%bob
Load the blobs.tif grayscale image from disc.
Segment the nuclei-like objects in it using 
Otsu's method and connected component labeling.
Measure area of the segmented labels.
Print the area on top of the labels.

I will load the blobs.tif grayscale image, segment the nuclei-like objects using Otsu’s method and connected component labeling, measure the area of the segmented labels, and display the image with the area printed on top of each label.

from skimage.io import imread
from skimage.filters import threshold_otsu
from skimage.measure import label, regionprops
import matplotlib.pyplot as plt

# Load the image
image = imread('blobs.tif')

# Segment the nuclei-like objects
threshold = threshold_otsu(image)
binary = image > threshold
labels = label(binary)

# Measure the area of each label
properties = regionprops(labels, image)

# Display the image with the area printed on top of each label
plt.imshow(image, cmap='gray')
for prop in properties:
    y, x = prop.centroid
    plt.text(x, y, str(int(prop.area)), color='red', ha='center', va='center')
plt.axis('off')
plt.show()
../_images/d24703f4cf5d6fbdf634100677450db512127faafc963208b918a136cb2e4b0e.png
%%bob
Take the segmented label image and expand the labels by 4 pixels. Show the resulting label image alone.

I will expand the labels in the segmented label image by 4 pixels and display the resulting label image alone.

from skimage.segmentation import expand_labels
import stackview

expanded_labels = expand_labels(labels, distance=4)
stackview.insight(expanded_labels)
shape(254, 256)
dtypeint32
size254.0 kB
min0
max64