Before starting this lesson, you should be familiar with:

Learning Objectives

After completing this lesson, learners should be able to:
  • Understand the concept and purpose of commenting.

  • Comment properly what certain section of code.


When you read your code again in six months from now, you want to understand what your code does, and why. Also if you would pass your code to another person, for them to use, modify, and/or extend it. For this, you can add comments to your code, i.e. text which can be read by human, and is ignored by computer when it executes your code. In addition, you can use comment to skip certain part of the code. For example, when you wrote testing code and later no longer need those.

Concept map

graph TD ST("script text") --> CD("code") ST("script text") --> CM("comment") CD -->|read by| RC("computer") CM -->|read by| RH("human") CM -->|ignored by| RC("computer")


Single line comment, and multiple line (block) comment.


Show activity for:  


%These matlab scripts illustrate separating the foreground from the %background using a threshold value provided by the user %Prompt user for a threshold value thres_val = input('Enter a threshold value: '); % Prompt user to choose an image, e.g. xy_8bit__two_cells.tif [file, path] = uigetfile("*.tif"); %Read input image in_image = imread(fullfile(path, file)); %display input image figure; imagesc(in_image); %Binarize input image with the threshold valuein_image bin_image = uint8(in_image>= thres_val); % Display binary image figure; imagesc(bin_image);

skimage napari

import numpy as np
import matplotlib.pyplot as plt
from skimage import io

# load the image from file
image_file = "/image_data/xy_8bit__two_cells.tif"
image = io.imread(image_file)

# binarize the image, so that all values larger than the threshold are foreground
threshold_value = 60
binarized = image > threshold_value

# display the original and the binarized image
fig, ax = plt.subplots(2)

# For associated course material in jupyter, go to
# You can also spin up an interactive binder session:


Follow-up material

Recommended follow-up modules:

Learn more: