Skip to content

Commit f2a811c

Browse files
docs: add tophat explanation for baseline correction (#106)
1 parent 5bca291 commit f2a811c

File tree

8 files changed

+6137
-0
lines changed

8 files changed

+6137
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
There are moments when an image doesn't have a perfect lightning and you have uneven background like here.
2+
3+
![sudoku](./images/topHat%20correction/sudoku.png)
4+
5+
So, when extracting regions of interest the regular way you will have a mask like that:
6+
7+
```ts
8+
//The default algorithm used is
9+
//"otsu".
10+
mask = image.threshold();
11+
```
12+
13+
![Global threshold](./images/topHat%20correction/globalThreshMask.jpg)
14+
15+
The cause of this is the nature of the threshold algorithm. In ImageJS it takes a global threshold variable, which means that the algorithms calculate one value and compare it with all the pixels to create a Mask. Obviously, such approach is not very effective when there are smooth shades and uneven illumination.
16+
One of the ways to deal with uneven illumination and improve the output is to apply `topHat`() method. It is a method that subtracts the result of morphological opening from the original image.
17+
18+
```ts
19+
image = image.grey().invert();
20+
//Big structuring element is necessary for
21+
const kernel = Array(101).fill(Array(101).fill(1));
22+
image = image.topHat({ kernel });
23+
```
24+
25+
![topHat comparison](./images/topHat%20correction/topHatComp.png)
26+
27+
Therefore if we look at the histograms of these two images at a given point we will see that the intensities are spread more evenly after topHat, rather than before.
28+
29+
### Histogram before applying topHat
30+
31+
![](./images/topHat%20correction/histBeforeTopHat.svg)
32+
33+
### Histogram after applying topHat
34+
35+
![](./images/topHat%20correction/histAfterTopHat.svg)
12.4 KB
Loading

0 commit comments

Comments
 (0)