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.6.2'
%%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
from skimage.measure import label

# Calculate the threshold value using Otsu's method
threshold = threshold_otsu(image)

# Convert the image to binary using the computed threshold
binary = image > threshold

# Label the connected components in the binary image
labels = label(binary)