rank-filters.md 3.85 KB
Newer Older
Christian Tischer's avatar
Christian Tischer committed
1 2
# Rank filters

Christian Tischer's avatar
Christian Tischer committed
3 4 5 6 7 8
## Basic rank filters

<img src='https://g.gravizo.com/svg?
 digraph G {
    shift [fontcolor=white,color=white];
	"rank filters" -> awesome [label="  are"];
Christian Tischer's avatar
Christian Tischer committed
9 10 11 12
	"rank filters" -> minimum -> erosion [label="  aka"];
	"rank filters" -> maximum -> dilation [label="  aka"];
	"rank filters" -> median;
	"rank filters" -> "size" [label="  have"];
Christian Tischer's avatar
Christian Tischer committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
  }
'/>

### Activity: Explore rank filters on binary images

- Open image: xy_8bit_binary__two_spots_different_size.tif
- Explore how the structures grow and shrink when using erosion and dilation

### Activity: Explore rank filters on grayscale images

- Open image: xy_8bit__two_noisy_squares_different_size.tif
- Explore how a median filter
	- removes noise
	- removes small structures
	- preserves egdes
Christian Tischer's avatar
Christian Tischer committed
28
- Compare median filter to mean filter of same radius
Christian Tischer's avatar
Christian Tischer committed
29 30 31 32


### Formative assessment

Christian Tischer's avatar
Christian Tischer committed
33 34 35 36 37 38 39 40 41 42 43
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.
Christian Tischer's avatar
Christian Tischer committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95


## 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 ) = dilation( erosion( image ) )
```

```
closing( image ) = erosion( dilation ( image ) )
```


### Activity: Explore opening and closing on binary images

- Open image: xy_8bit_binary__for_open_and_close.tif
- Explore the effect of morphological closing and opening
	- Closing can fill the hole
	- Closing can connect the circle
	- Opening can remove thin structures 


### Formative assessment

TODO


## Top hat filter for local background subtraction

<img src='https://g.gravizo.com/svg?
 digraph G {
    shift [fontcolor=white,color=white];
	"top hat filter" -> "rank filter sequence" [label="  is"];
	"top hat filter" -> "local background subtraction";
  }
'/>


```
topHat( image ) = image - dilation( erosion( image, r), r )
```

Christian Tischer's avatar
Christian Tischer committed
96 97 98
TODO: Add image from pdf


Christian Tischer's avatar
Christian Tischer committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
### Activity: Explore tophat filter

- Open image: xy_8bit__spots_local_background.tif
- Use topHat filter to remove local background

## Activity: Implement a tophat filter

- Devise code to implement a tophat filter using basic functions

## Activity: Explore tophat filter on biological data

- Open image: xy_16bit__autophagosomes.tif 
- Use topHat filter to remove local background

## Activity: Explore tophat fiter 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


### Formative assessment

TODO


## Median filter for local background subtraction

<img src='https§://g.gravizo.com/svg?
 digraph G {
    shift [fontcolor=white,color=white];
	"median" -> "local background";
	"median" -> "radius" -> "about 3 times larger than foreground objects";
  }
'/>


```
median_based_background_correction = image - median( image, r)
```

Christian Tischer's avatar
Christian Tischer committed
140 141 142
TODO: Add image from pdf


Christian Tischer's avatar
Christian Tischer committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
### 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

TODO