Image Processing with Python#
Course Description#
As computer systems have become faster and more powerful, and cameras and other imaging systems have become commonplace in many areas of life, the need has grown for researchers to be able to process and analyse image data. Considering the large volumes of data that can be involved and the time-consuming nature of manual processing, automating this work as a computer program can be a significant advantage.
This course introduces fundamental concepts in image handling and processing using Python and the scikit-image library. Learners will gain the skills needed to load images into Python, to select, summarise, and modify specific regions of an image, and to identify and extract objects within an image for further analysis. The course also includes an extra episode on multidimensional image data (3D stacks and timelapses) using the Napari image viewer.
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
Cell In[1], line 69
65 # Apply the function and create a new column for HTML
66 courses_df['HTML'] = courses_df.apply(generate_html, axis=1)
67
68 # Filter the DataFrame for the given course name and display the HTML text
---> 69 html_output = courses_df[courses_df['Course Name'] == course_name]['HTML'].values[0]
70 display(HTML(html_output))
File ~/.cache/pypoetry/virtualenvs/coding_for_reproducible_research_courses-l5b2FSBI-py3.11/lib/python3.11/site-packages/pandas/core/arrays/_mixins.py:293, in NDArrayBackedExtensionArray.__getitem__(self, key)
287 def __getitem__(
288 self,
289 key: PositionalIndexer2D,
290 ) -> Self | Any:
291 if lib.is_integer(key):
292 # fast-path
--> 293 result = self._ndarray[key]
294 if self.ndim == 1:
295 return self._box_func(result)
IndexError: index 0 is out of bounds for axis 0 with size 0
Course Objectives#
Load, display, and manipulate digital images with Python using scikit-image and associated libraries.
Understand how digital images are represented and stored (pixels, colour channels, and array structures) and how to process them programmatically.
Apply basic image processing techniques such as blurring, histogram creation, thresholding and connected component analysis to extract meaningful information from images.
Develop reproducible Python workflows that automate common image analysis tasks for research applications.
(if time allows) Analyse and visualise multidimensional data (3D stacks and timelapses) using the Napari image viewer.
Pre-requisite Knowledge#
This course is aimed at researchers who want to learn how to analyse their image data using Python. It assumes you have a very basic working knowledge of Python. Prior attendance at any introductory python course (e.g “Introduction to Python”) or equivalent independent exposure would be ideal. If you are competent in anouther programming, or sripting, language other than Python this will be sufficient.
Sign-up#
To check for upcoming course dates and to register, please visit the Workshop Schedule and Sign-up page.
Installation Guide#
Installation is part of the learning experience
We recommend working through each of the installation steps, even if you already have access to a configured environment. This will help you understand the complete setup process, verify that each component is working correctly, and prepare you to install and use the software on your own machine.
All CfRR courses require attendees to use their own computer/laptop to follow workshop activities and take effective notes.
Required Software#
To complete the activities in this workshop you will need to set up a Python environment with the required packages. We recommend using Miniforge.
Once Miniforge is installed, open a terminal (or Miniforge3 Prompt on Windows) and run the following commands to create and activate a dedicated environment:
mamba create -y -n image-env -c conda-forge python=3.13
mamba activate image-env
mamba install -y -c conda-forge scikit-image ipympl napari pyqt jupyterlab
Note
Windows users
Launch the Miniforge3 Prompt program to run the above commands. Running mamba commands in the standard Command Prompt may return an error.
Launching JupyterLab#
Once your environment is set up, activate it and open JupyterLab:
mamba activate image-env
jupyter lab
After JupyterLab has launched, click the Python 3 button under Notebook in the launcher window to open a new Python 3 notebook.
Course Data and Testing Your Installation#
The example images used in this course are available for download here. Extract the contents into a folder called data inside the directory you will use for this workshop — this name is used throughout the course materials to refer to this folder.
To verify your environment is set up correctly, create a new notebook in your workshop folder and run the following in a cell:
Modifying the path to the data
The test code below assumes your notebook is located in your workshop folder, with the example images in a data subfolder directly inside it. If your folder structure differs, update the file path in the iio.imread() call accordingly.
import imageio.v3 as iio
import matplotlib.pyplot as plt
import skimage as ski
import napari
%matplotlib widget
# load an image (modify path to data directory as needed)
image = iio.imread(uri='./data/colonies-01.tif')
# rotate it by 45 degrees
rotated = ski.transform.rotate(image=image, angle=45)
# display the original image and its rotated version side by side
fig, ax = plt.subplots(1, 2)
ax[0].imshow(image)
ax[1].imshow(rotated)
# open the image in Napari
viewer = napari.Viewer()
viewer.add_image(data=image, name="colonies_01", rgb=True)
Upon execution, the above figure should be displayed with an interactive widget, and a Napari Viewer should open in a seperate window displaying the original image.
Self Study Material Link#
The self-study material for this course is available on the Self-study notes: Image Processing with Python page.
Acknowledgements#
This course is based on the Data Carpentry Image Processing with Python Lesson.
If you reuse or adapt this material, please acknowledge the following sources where appropriate:
Data Carpentry Image Processing Lesson: datacarpentry/image-processing
Multidemensional Episode: bham-carpentries/image-processing
Data Carpentry Image Processing Dataset (Figshare): https://figshare.com/articles/dataset/Data_Carpentry_Image_Processing_Data_beta_/19260677
Developers#
Jeremy Pike developed the Multidimensional Data section and is responsible for migrating the original Data Carpentry Image Processing with Python lesson to the CfRR site and for ongoing maintenance and adaptation. The contributors to the original lesson include Jacob Deppen, Kimberly Meechan, David Palmquist, Ulf Schiller, Robert Turner, and Toby Hodges which in turn is built on content originally developed by Mark Meysenburg, Tessa Durham Brooks, Dominik Kutra, Constantin Pape, and Erin Becker.
Course Delivery Content#
There is currently no adíditional content that is used outside of the self-study notes to deliver this course.