This lesson is still being designed and assembled (Pre-Alpha version)

Image binarization

Prerequisites

Before starting this lesson, you should be familiar with:

Learning Objectives

After completing this lesson, learners should be able to:
  • Describe the relationship between an intensity image and a derived binary image

  • Apply a threshold to distinguish foreground and background pixels

Motivation

Very often, one wants to detect objects or specific regions in images. Typically, the first step to achieve this aim is to distinguish so-called background pixels, which do not contain objects or interesting regions, from foreground pixels, which mark the areas of interest. The foreground regions can than be further processed, e.g to detect objects or perform measurements.

Concept

graph TD PV("Pixel values") --> BA(Binarization algorithm) BA --> BPV("Binarized pixel values") BPV --> BG("Background (0)") BPV --> FG("Foreground (1)")
Image before and after binarization by applying a threshold.

Activity

Open an image and binarize it by applying a threshold.

Show activity for:

ImageJ GUI

  • [ Open… ] “/image-analysis-training-resources/image_data/xy_8bit__two_cells.tif”
  • [ Threshold… ]

ImageJ Macro

open("/image-analysis-training-resources/image_data/xy_8bit__two_cells.tif");
setThreshold(30, 255);
setOption("BlackBackground", true);
run("Convert to Mask");

Jython

from ij import IJ, ImagePlus
from ij.plugin import Thresholder

inputImage=IJ.getImage()
IJ.setRawThreshold(inputImage, 60, 255, None)
binaryImage=ImagePlus('Binary image',Thresholder.createMask(inputImage))
binaryImage.show()

MATLAB


%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: '); 
%Read input image
in_image = imread(['image_data' filesep 'xy_8bit__two_cells.tif']);
figure; imagesc(in_image); %display input image
%Binarize input image with the threshold valuein_image
bin_image = uint8(in_image>= thres_val);
figure; imagesc(bin_image) % Display binary image

KNIME

Image binarization

Formative assessment

Fill in the blanks

Perform additional exercises for:

ImageJ GUI

Exercise 1

Please…

Solution This is the solution to the first exercise.

ImageJ Macro

This file should contain language-specific exercises, written in Markdown

…but probably with some HTML mixed in, so that you can add expandable Solution boxes.

Exercise 1

What is the solution to the first exercise?

Solution This is the solution to the first exercise.

Exercise 2

What is the solution to the second exercise?

Solution This is the solution to the second exercise.

Jython

This file should contain language-specific exercises, written in Markdown

…but probably with some HTML mixed in, so that you can add expandable Solution boxes.

Exercise 1

What is the solution to the first exercise?

Solution

This is the solution to the first exercise.

Exercise 2

What is the solution to the second exercise?

Solution

This is the solution to the second exercise.

MATLAB

This file should contain language-specific exercises, written in Markdown

…but probably with some HTML mixed in, so that you can add expandable Solution boxes.

Exercise 1

What is the solution to the first exercise?

Solution This is the solution to the first exercise.

Exercise 2

What is the solution to the second exercise?

Solution This is the solution to the second exercise.

Follow-up material

We recommend reading these modules next:

Learn more: