Commit 7e89e7f5 authored by Christian Tischer's avatar Christian Tischer

Merge branch 'rank_filter_context' into 'markdown'

Rank filter context

See merge request grp-bio-it/image-analysis-training-resources!21
parents 3ad1fcd2 0d7bc44f
Pipeline #9988 passed with stage
in 29 seconds
---
title: Morphological filters
layout: page
permalink: /filtermorphological
---
# Morphological filters
## Requirements
- Neighbourhood filters
- Rank filters
## Motivation
This module explains how filters can be used to change size and shape of objects in the image.
## Learning objectives
- Understand how to design morphological filters using rank filters
- Execute morpholofical filters on binary or grayscale images and explain the output
## Concept map
```mermaid
graph TD;
image --> max1[max]
image --> min1[min]
image --> max2[max]
image --> min2[min]
subgraph one or more rank filters applied sequentially
max2 --> min3[min]
min2 --> max3[max]
max1
min1
end
max1 --> dilation
min1 --> erosion
max3 --> opening
min3 --> closing
subgraph result
dilation
erosion
opening
closing
end
```
[*] Concept map above assumes bright objects on dark background. For dark objects on bright background effect of min and max filters inverses
### Activity: Explore erosion and dilation on binary images
- Open image: xy_8bit_binary__two_spots_different_size.tif
- Explore how structures grow and shrink, using erosion and dilation
### Activity: Explore opening and closing on binary images
- Open image: xy_8bit_binary__for_open_and_close.tif
- Explore effects of morphological closing and opening:
- closing can fill holes
- closing can connect gaps
- opening can remove thin structures
### Formative assessment
Fill in the blanks, using those words: shrinks, increases, decreases, enlarges.
1. An erosion _____ objects in a binary image.
2. An erosion in a binary image _____ the number of foreground pixels.
3. A dilation in a grayscale image _____ the average intensity in the image.
4. A dilation _____ objects in a binary image.
True of false? Discuss with your neighbour!
1. Morphological openings on binary images can decrease the number of foreground pixels.
2. Morphological closings on binary images never decreases the number of foreground pixels.
3. Performing a morphological closing a twice in a row does not make sense, because the second closing does not further change the image.
## Learn more
- https://imagej.net/MorphoLibJ#Grayscale_morphological_filters
---
title: Neighbourhood image filters
layout: page
permalink: /filtersneighbourhood
---
# Neighborhood filters
## Requirements
To understand this episode you need to know:
- Pixel properties
## Motivation
This module explains how image features (objects) can be enhanced using filters
## Learning objectives
- Understand common filter principles.
- test mean filter on noisy image data
## Concept map
```mermaid
graph TB
pixel --> neighbours[neighbourhood pixels]
neighbours --> better["`better` value for central pixel"]
better --> update[updated pixel]
```
| | | | | | | | |
|---|---|---|---|---|---|---|---|
| NC | NC | NC | | | | | |
| NC | C, NC | NC | | | | | |
| NC | NC | NC | | | | | |
| | | | | NB | NB | NB | |
| | | | | NB | B, NB| NB | |
| | | | | NB | NB | NB | |
| | | | | | | | |
## Activity
TODO: construct example with mean filter on noisy data.
\ No newline at end of file
# Neighborhood filters
---
title: Rank filters
layout: page
permalink: /filterrank
---
<img src='https://g.gravizo.com/svg?
digraph G {
shift [fontcolor=white,color=white];
"neighbourhood filter" -> "central neighbourhood pixel" [label=" replaces"];
"neighbourhood filter" -> "size" [label=" has"];
"neighbourhood filter" -> "shape" [label=" has"];
"neighbourhood filter" -> "convolution filters";
"neighbourhood filter" -> "rank filters";
}
'/>
# Rank filters
| | | | | | | | |
|---|---|---|---|---|---|---|---|
| NC | NC | NC | | | | | |
| NC | C, NC | NC | | | | | |
| NC | NC | NC | | | | | |
| | | | | NB | NB | NB | |
| | | | | NB | B, NB| NB | |
| | | | | NB | NB | NB | |
| | | | | | | | |
## Basic rank filters
## Requirements
To understand this episode you need to know:
- Pixel properties
- Neighbourhood filters
## Motivation
# Rank filters
In this module one would learn basic principles of rank image filters and understand when using this type filters might be beneficial.
## Basic rank filters
<img src='https://g.gravizo.com/svg?
digraph G {
shift [fontcolor=white,color=white];
"rank filters" -> "neighbourhood filters" [label=" are"];
"rank filters" -> minimum;
minimum -> erosion [label=" aka"];
"rank filters" -> maximum;
maximum -> dilation [label=" aka"];
"rank filters" -> median;
"rank filters" -> "size" [label=" have"];
}
'/>
## Learning objectives
- Understand how rank filters function.
- Execute and compare several rank filters.
- Compare image smoothing using rank (e.g. median) vs another filter type (e.g. mean).
### Activity: Explore rank filters on binary images
## Concept map
```mermaid
graph TB
pixel --> values[neighbourhood pixel values]
values --> sorted[sorted pixel values]
sorted --> min
sorted --> max
sorted --> median
sorted --> ...
subgraph rank value
min
max
median
...
end
min --> fpixel[filtered image pixel]
max --> fpixel
median --> fpixel
... --> fpixel
```
- Open image: xy_8bit_binary__two_spots_different_size.tif
- Explore how structures grow and shrink, using erosion and dilation
### Activity: Explore rank filters on grayscale images
......@@ -66,130 +66,5 @@ True or false? Discuss with your neighbour!
1. Median filter is just another name for mean filter.
2. Small structures can completely disappear from an image when applying a median filter.
Fill in the blanks, using those words: shrinks, increases, decreases, enlarges.
1. An erosion _____ objects in a binary image.
2. An erosion in a binary image _____ the number of foreground pixels.
3. A dilation in a grayscale image _____ the average intensity in the image.
4. A dilation _____ objects in a binary image.
## Morphological opening and closing
<img src='https://g.gravizo.com/svg?
digraph G {
shift [fontcolor=white,color=white];
"opening" -> "rank filter sequence" [label=" is"];
"closing" -> "rank filter sequence" [label=" is"];
"opening" -> "removes small structures";
"closing" -> "fills small gaps";
}
'/>
```
opening( image, r ) = dilation( erosion( image, r ), r )
```
```
closing( image, r ) = erosion( dilation( image, r ), r )
```
### Activity: Explore opening and closing on binary images
- Open image: xy_8bit_binary__for_open_and_close.tif
- Explore effects of morphological closing and opening:
- closing can fill holes
- closing can connect gaps
- opening can remove thin structures
### Formative assessment
True of false? Discuss with your neighbour!
1. Morphological openings on binary images can decrease the number of foreground pixels.
2. Morphological closings on binary images never decreases the number of foreground pixels.
3. Performing a morphological closing a twice in a row does not make sense, because the second closing does not further change the image.
## Top hat filter for local background subtraction
<img src='https://g.gravizo.com/svg?
digraph G {
shift [fontcolor=white,color=white];
"tophat" -> "rank filter sequence";
"tophat" -> "local background subtraction";
}
'/>
```
tophat( image ) = image - opening( image, r ) = image - dilation( erosion( image, r), r )
```
### Activity: Explore tophat filter
- Open image: xy_8bit__spots_local_background.tif
- Use a tophat filter to remove local background
## Activity: Implement a tophat filter
- Devise code implementing a tophat filter, using minimum and maximum filters
## Activity: Explore tophat filter on biological data
- Open image: xy_16bit__autophagosomes.tif
- Appreciate that you cannot readliy segment the spots.
- Use a tophat filter to remove local background.
- Threshold the spots in the tophat filtered image.
## Activity: Explore tophat filter on noisy data
- Open image: xy_8bit__spots_local_background_with_noise.tif
- Use topHat filter to remove local background
- Appreciate that noise poses a challenge to the tophat filter
## Median filter for local background subtraction
<img src='https://g.gravizo.com/svg?
digraph G {
shift [fontcolor=white,color=white];
"median" -> "local background" [label=" approximates"];
"median" -> "radius" -> "> object width";
"radius" -> "< spatial background frequency";
}
'/>
```
median_based_background_correction = image - median( image, r)
```
### Activity: Implement median based background subtraction
- Write code to implement a median based background subtraction
### Activity: Explore median filter for local background subtraction
- Open images:
- xy_8bit__spots_local_background.tif
- xy_8bit__spots_local_background_with_noise.tif
- Use tophat filter to remove local background
- Devise code to implement a tophat filter using basic functions
### Formative assessment
Answer below questions. Discuss with your neighbour!
1. What could one do to close small gaps in a binary image?
2. What could one do to remove small objects in a image?
3. What could you use for local background subtraction in a very noisy image?
## Learn more
- https://imagej.net/MorphoLibJ#Grayscale_morphological_filters
---
title: Local background subtraction
layout: page
permalink: /localbackground
---
# Local background subtraction
## Requirements
- Neighbourhood filters
- Rank filters
- Convolutional filters
- Pixel math
## Motivation
This module explains how to remove background which has different values in different image parts.
## Learning objectives
- Understand how to use filters to create background image
- Learn differences between different methods/filters for generating background image
- Practice background subtraction
## Concept map
```mermaid
graph TD;
image --> smooth1[small radius filter]
image --> smooth2[big radius filter]
smooth1 --> image1[Noise suppressed image]
smooth2 --> image2[Background image]
image1 --> subtraction["[Noise suppressed image] - [Background image]"]
image2 --> subtraction
subtraction --> result[Background subtracted image]
```
## Possible filters for creating bacground image
- Median filter
- Opening filter: the result of background subtraction operation is called **Top-Hat filter**
- Gaussian filter
## Activity: Implement a tophat filter
- Devise code implementing a tophat filter, using minimum and maximum filters
### Activity: Explore tophat filter
- Open image: xy_8bit__spots_local_background.tif
- Use a tophat filter to remove local background
## Activity: Explore tophat filter on biological data
- Open image: xy_16bit__autophagosomes.tif
- Appreciate that you cannot readliy segment the spots.
- Use a tophat filter to remove local background.
- Threshold the spots in the tophat filtered image.
## Activity: Explore tophat filter on noisy data
- Open image: xy_8bit__spots_local_background_with_noise.tif
- Use topHat filter to remove local background
- Appreciate that noise poses a challenge to the tophat filter
### Activity: Implement median based background subtraction
- Write code to implement a median based background subtraction
### Activity: Explore median filter for local background subtraction
- Open images:
- xy_8bit__spots_local_background.tif
- xy_8bit__spots_local_background_with_noise.tif
- Use tophat filter to remove local background
- Devise code to implement a tophat filter using basic functions
### Formative assessment
Answer below questions. Discuss with your neighbour!
1. What could one do to close small gaps in a binary image?
2. What could one do to remove small objects in a image?
3. What could you use for local background subtraction in a very noisy image?
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment