## Prerequisites

Before starting this lesson, you should be familiar with:

## Learning Objectives

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.
• Open image xy_8bit__some_spots_with_uneven_bg
• Compute a background image using a median filter
• Create a foreground image by subtracting the background image from the input image
• (Optional) Segment the spots in the foreground image.
• Activity 2 - Background subtraction using a maximum intensity projection.
• Open image xyt_8bit_polyp
• Create a maximum intensity projection of this image.
• Because the polyp is moving around and is darker than the background this will create a background image.
• Create a foreground image by subtracting the maximum intensity projection from the original image.

Show activity for:

## Activity 1 ImageJ GUI

• Open image xy_8bit__some_spots_with_uneven_bg
• [ Image › Rename… ]
• “input”
• Create background image
• [ Image > Duplicate…]
• [ Process > Filters > Median… ]
• [ Image › Rename… ]
• “background”
• Create foreground image
• [ Process › Image Calculator… ]
• Image 1 = input
• Subtract
• Image 2 = background
• create
• 32-bit
• [ Image › Rename… ]
• “foreground”

## Activity 2 ImageJ GUI

• Open image xyt_8bit_polyp
• 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.

## Exercises

• Spots in a cell
• Open xy_16bit__autophagosomes_crop.tif
• Create a background image by duplicating the input image and applying a median filter to it.
• Choose the radius of the median filter just large enough such that the bright spots dissappear.
• Create the foreground image by subtracting the background image from the input image.
• You should see an image with the bright spots, now without the uneven background.
Show exercise/solution for:

## ImageJ GUI

• Open the autophagosomes input image (s.a.)
• [ Image › Rename… ]
• “input”
• [ Image › Duplicate… ]
• title = “median”
• [ Process › Filters › Median…]
• [ Image › Rename… ]
• “background”
• [ Process › Image Calculator… ]
• “input”
• Subtract
• “background”
• create
• 32-bit
• [ Image › Rename… ]

## Assessment

### True or false?

1. Mean filter is better than the median filter to generate a background image.
2. On the generated background image the objects of interest should not be visible.
3. 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

1. False (mean filter is really quite poor in terms of removing foreground information)
2. True (because this is the background image, so it should not contain any foreground information)
3. False (it should be much (maybe ~3 times) larger in order to remove the objects from the image)

## Follow-up material

Recommended follow-up modules: