Image Processing with Python

Jacob Deppen and David Palmquist

July, 2023

Thank you!

Thanks to Nisha and Mary for hosting and thank you for coming.

Presenters

  • Jacob Deppen, deppen8 on GitHub
  • David Palmquist, quist00 on GitHub

Acknowledgements

  • Current maintainer team: Kimberly Meechan, Ulf Schiller, Robert Turner, Toby Hodges
  • Content originally developed by Mark Meysenburg, Tessa Durham Brooks, Dominik Kutra, Constantin Pape, and Erin Becker.
  • Many community members have opened issues and pull requests to improve the lesson.

Image Processing is stable!

Moved from “beta” to “stable” in January 2023.

Four stages of lesson release timeline

Why teach this lesson?

  • Images are everywhere.
  • Image data is different to tabular / data frame data.

What’s in the lesson?

  • Introduction to images in research.
  • How images are represented by computers.
  • Manipulating images using python and scikit-image library.
  • Extracting data / statistics from images.

Key concepts

  • Pixels
  • Arrays
  • Coordinates
  • Channels
  • Kernels
  • Binary masks

What’s not in the lesson?

  • AI / Deep Learning

Lesson is a more “traditional” approach: easier to explain results, less data-intensive, applicable to more domains.

What do I need to know?

  • Bash shell skills
    • Navigating directories using pwd, ls, cd <subdirectory>, and cd .., Run a Python script from the command line.
  • Python skills
    • Variables and types, lists, logic (if, else, etc.), basic file input / output

Lesson setup

  • Data
    • Download from FigShare
  • Software
    • Anaconda (base environment includes all required packages) and Jupyter Notebooks

Introduction to image processing

Optional breakout 1

  • What research areas do you expect your learners to come from?
  • Are there particular challenges in working with image data in these areas?

Image basics

  • Representation of images in computers.
  • Images, arrays and pixels.
  • How RGB is used to make colour images.
  • File formats and compression.

If you are a computer, images are arrays

Image with pixel values overlaid

Image with pixel values overlaid

Image representation

RGB Image

RGB Image

Red channel

Red channel

Green channel

Green channel

Blue channel

Blue channel

Tools for working with images

  • skimage (scikit-image)
    • Do weird things with arrays (e.g. skimage.transform.resize).
  • numpy
    • Conventional array stuff (e.g. sub-setting, find all values > x).
  • imageio
    • Input + output; images are often not stored in numpy friendly formats.

Analyzing images

The distribution of intensity of colour in an image can tell us things.

Plant Seedling

Plant Seedling

Histogram

Histogram

Blurring

Gaussian Original

Original

Gaussian Blurred

Blurred

Thresholding

Blurred grayscale

Blurred grayscale

Threshold applied

Threshold applied

Connected components

Separating objects and getting information about them.

Labelled shapes

Labelled shapes

Getting statistics

Areas histogram

Areas histogram

False positive objects

False positive objects

Morphometrics

  • Properties of the shape of an object.
  • skimage regionprops
  • Basic e.g., area, perimeter, center
  • More complex e.g., eccentricity, bounding box

Capstone challenge

  • Morphometrics for bacterial colonies.
  • Brings together blurring, thresholding, and connected component analysis.

Morphometrics for bacterial colonies

Optional breakout 2

  • What imaging tools are people in your field using?
  • How does that fit in with an open source image processing stack?

Questions / discussion

Thanks again!