Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add tophat explanation for baseline correction #106

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/Tutorials/Correcting baseline with topHat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
There are moments when an image doesn't have a perfect lightning and you have uneven background like here.

![sudoku](./images/topHat%20correction/sudoku.png)

So, when extracting regions of interest the regular way you will have a mask like that:

```ts
//The default algorithm used is
//"otsu".
mask = image.threshold();
```

![Global threshold](./images/topHat%20correction/globalThreshMask.jpg)

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.
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.

```ts
image = image.grey().invert();
//Big structuring element is necessary for
const kernel = Array(101).fill(Array(101).fill(1));
image = image.topHat({ kernel });
```

![topHat comparison](./images/topHat%20correction/topHatComp.png)

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.

### Histogram before applying topHat

![](./images/topHat%20correction/histBeforeTopHat.svg)

### Histogram after applying topHat

![](./images/topHat%20correction/histAfterTopHat.svg)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading