After completing this lesson, learners should be able to:
Understand how to use image filters for creating a local background image
Use the generated local background image to compute a foreground image
Motivation
Very often, biological images contain locally varying background intensities. This hampers both segmentation and intensity quantification. However, often it is possible to generate a background image that can be subtracted in order to yield a foreground image with zero background. It is very important to know about this, because removing spatially varying background is a prevalent task in bioimage analysis.
Concept map
graph TD
ii(Input image)
ii --> bgi[Background image]
bgi --> s[Subtract]
ii --> s
s --> fgi[Foreground image]
Figure
Local background correction using a median filter. Left - Raw data. Middle - Median filtered image (background). Right - Difference image (foreground).
Activities
Activity 1 - Background subtraction using a median filter.
/**
* Fiji script for local background subtraction
*/// Parameters (please modify)//medianFilterRadius=15;// Code (rather not modify)//run("Close All");// Open dataopen("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xy_8bit__some_spots_with_uneven_bg.tif");rename("input");// Create background imagerun("Duplicate...","title=background");run("Median...","radius="+medianFilterRadius);rename("background");// Create foreground imageimageCalculator("Subtract create 32-bit","input","background");rename("foreground");run("Tile");// Create line profiles for a more quantitative visualisation of the processmakeLine(99,200,81,121,82,87,91,64,230,26);selectWindow("foreground");run("Plot Profile");// Also create the same line profiler on the input imageselectWindow("input");run("Restore Selection");run("Plot Profile");
Make a maximum intensity projection to create a background image ([Image › Stacks › Z Project…])
Use the image calculator function [ Process › Image Calculator…] to subtract the maximum intensity projection from the original:
Image1: xyt_8bit_polyp
Operation: Subtract
Image2: MAX_xyt_8bit_polyp
‘create new window’
‘32-bit float result’
Say ‘yes’ to the ‘Process entire stack’ message.
Activity 2 ImageJ Macro
// Open imageopen("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xyt_8bit_polyp.tif");// Create maximum intensity projectionrun("Z Project...","projection=[Max Intensity]");// Subtract maximum intensity projection from original imageimageCalculator("Subtract create 32-bit stack","xyt_8bit_polyp.tif","MAX_xyt_8bit_polyp.tif");
Activity 2 ImageJ Jython
# Use a maximum intensity projection for background subtraction
# import packages
fromijimportIJfromij.pluginimportZProjector,ImageCalculator# open image
imp=IJ.openImage("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xyt_8bit_polyp.tif")# create maximum intensity projection
maxproj=ZProjector().run(imp,"max all")# subtract maximum intensity projection from original image
background_subtracted=ImageCalculator().run(imp,maxproj,"Subtract create 32-bit stack")# show all images
imp.show()maxproj.show()background_subtracted.show()IJ.run("Tile")
Mean filter is better than the median filter to generate a background image.
On the generated background image the objects of interest should not be visible.
When creating a background image by means of filtering: The size of the filter’s structuring element should be much smaller than the size of the objects.
Solution
False (mean filter is really quite poor in terms of removing foreground information)
True (because this is the background image, so it should not contain any foreground information)
False (it should be much (maybe ~3 times) larger in order to remove the objects from the image)