Documenting code#

Bob can be used to document code. If you put the %%doc magic at the beginning of a cell…

from bia_bob import bob, doc
bob.__version__
'0.20.0'
%%doc
from skimage.filters import threshold_otsu
from skimage.measure import label
threshold = threshold_otsu(image)
binary = image > threshold
labels = label(binary)

… the cell will get updated when executing it. Note: In case there is %%doc at the beginning of a cell, the code will not be executed, it will just be replaced. For example the code above could be replaced with this:

from skimage.filters import threshold_otsu  # Import threshold_otsu function
from skimage.measure import label  # Import label function

# Calculate the Otsu threshold value for the input image
threshold = threshold_otsu(image)

# Binzarize the image at the calculated threshold value, 
# resulting in a binary image
binary = image > threshold

# Label connected regions of `True` in the binary image, 
# producing a label image where each connected component has a unique integer label
labels = label(binary)