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

Global background correction

Prerequisites

Before starting this lesson, you should be familiar with:

Learning Objectives

After completing this lesson, learners should be able to:
  • Measure the background in an image

  • Apply image math to subtract a background intensity value from all pixels and understand that the output image should have a floating point data type

Motivation

Most biological images have non-zero intensity values in regions outside of the objects of interest. In order to properly quantify the intensities of objects such background must be taken into account. For example, most cameras on microscopes have a read noise with can be many hundred gray values (for 12-bit or 16-bit detection). As such read noise is typically constant across the whole image, subtracting a constant background value for each pixel is possible.

Concept map

graph TD I("Image") --> SB("Subtract background") SB --> BCI("Background corrected image") BCI ---|"datatype"| FP("Floating point") I --> MB("Measure background") MB --> SB

Example figure

Image before and after background correction

Activity

Show activity for:

ImageJ Macro & GUI

/**
 * Global background correction
 */


run("Close All");

open("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xy_16bit__nuclei_high_dynamic_range_with_offset.tif");

// Image › Adjust › Brightness/Contrast...
setMinAndMax(100, 115);

// Use the Rectangle tool from ImageJ's tool bar
makeRectangle(4, 8, 20, 42);

// Analyze › Set Measurements...
run("Set Measurements...", "mean redirect=None decimal=3");

// Analyze › Measure
run("Measure");

// Edit › Selection › Select None (VERY IMPORTANT, otherwise everything you do later will only operate on this region)
run("Select None");

// Image › Duplicate...
run("Duplicate...", "title=float");

// Image › Type › 32-bit
run("32-bit");

// Process › Math › Subtract...
run("Subtract...", "value=104.399");

// Image › Adjust › Brightness/Contrast...
setMinAndMax(-5, 10);

// Use the Line tool from ImageJ's tool bar
makeLine(17, 7, 69, 94);

// Analyze › Plot Profile
run("Plot Profile");

Exercises

Show exercises for:

ImageJ Macro & GUI

Open image xy_16bit__nuclei_with_background.tif

  1. Measure the background
  2. Subtract the background from the image
  3. Is the mean intensity in the background region close to 0 («1)? If not, which image data type conversion have you forgotten?
  4. Verify that the histogram has not been clipped by the background subtraction operation.

Solution

In order to obtain a correct result, the background subtraction should be performed with an image that has been converted to a float (in ImageJ 32-bit). This avoid clipping of the data for the low values.

run("Close All");
roiManager("reset");
run("Clear Results");
open("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xy_16bit__nuclei_with_background.tif");
rename("intenisty")
// 1. Measure the background
// Draw a rectangle 
makeRectangle(19, 16, 70, 52);

//Add to RoiManager using key t
roiManager("Add");
// Measure intensity
run("Measure");
// Disable current ROI (select the whole image or click on it)
run("Select All");

// 2. Subtract the background without conversion and check mean in background region
// Process › Math › Subtract...
run("Subtract...", "value=104.182");
rename("bg subtracted 16bit")
setMinAndMax("0.00", "100");
run("Enhance Contrast", "saturated=0.35");
// Measure the intensity in background region
roiManager("Select", 0);
run("Measure");
run("Histogram");

// 3. Subtract the background with prior conversion
// Open the image again
open("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xy_16bit__nuclei_with_background.tif");
// Subtract the background with prior conversion to float (32-bit)
// Image > Type > 32-bit
run("32-bit");
//  Process › Math › Subtract...
run("Subtract...", "value=104.182");
run("Enhance Contrast", "saturated=0.35");
rename("bg subtracted 32bit")
// Measure the intensity in background region
roiManager("Select", 0);
run("Measure");
setMinAndMax("0.00", "100");
run("Histogram", "bins=256 use x_min=-10 x_max=100.0 y_max=Auto");

Can you think of a way of automatically computing a global background?

Solution

For this exercise we just compute the mean intensity in the space that is not the nuclei. We can use thresholding but with different low and upper values.

/**
* Required update sites: 
*   - IJPB-Plugins (MorpholibJ)
**/

//File> Open...
open("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xy_16bit__nuclei_with_background.tif")
// Image > Duplicate...
run("Duplicate...", "binary");
// Image > Adjust > Threshold ...
setThreshold(0, 117);
setOption("BlackBackground", true);
run("Convert to Mask");

// Plugins › MorphoLibJ › Binary Images › Connected Components Labeling
run("Connected Components Labeling", "connectivity=4 type=[16 bits]");
rename("labels");
// Plugins › MorphoLibJ › Analyze › Intensity Measurements 2D/3D
run("Intensity Measurements 2D/3D", "input=intensity labels=labels mean max numberofvoxels");

Assessment

True or false?

  1. The datatype is irrelevant for background subtraction.
  2. Background subtraction using a unsigned integer image will always lead to a positive valued background.
  3. Global background subtraction is important for ratiometric computations.
  4. Global background subtraction affects differences in intensities.

Solution

  1. The datatype is irrelevant for background subtraction. FALSE
  2. Background subtraction using a unsigned integer image will always lead to a positive valued background. TRUE
  3. Global background subtraction is important for ratiometric computations. TRUE
  4. Global background subtraction affects differences in intensities. FALSE

Follow-up material

We recommend reading these modules next:

Learn more: