Skip to content

Commit beebf62

Browse files
EscapedGibbonstropitek
authored andcommitted
docs: write morphology methods of image class
1 parent 8f77342 commit beebf62

18 files changed

+208
-31
lines changed

docs/API reference/Image/Morphology/Dilate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import DilateDemo from './dilate.demo.tsx'
22

33
[Check options and parameters of dilate method](https://image-js.github.io/image-js-typescript/classes/Image.html#resize 'github.io link')
44

5-
[Dilation](<https://en.wikipedia.org/wiki/Dilation_(morphology)> 'wikipedia link on dilation') is a fundamental morphological operation in image processing that is used to expand the size of foreground objects (regions of interest) within an image while preserving their shape and structure. It involves moving a structuring element (also known as a kernel) over the image and replacing each pixel with the maximum value of the pixels covered by the structuring element. Dilation is commonly used for tasks like noise reduction, object enlargement, and feature enhancement.
5+
[Dilation](<https://en.wikipedia.org/wiki/Dilation_(morphology)> 'wikipedia link on dilation') is a fundamental morphological operation in image processing that is used to expand the size of foreground objects ([regions of interest](../../../Glossary.md#roiregion-of-interest 'internal link on region of interest')) within an image while preserving their shape and structure. It involves moving a structuring element (also known as a [kernel](../../../Glossary.md#kernel 'internal link on kernel')) over the image and replacing each pixel with the **maximum** value of the pixels covered by the structuring element. Dilation is commonly used for tasks like noise reduction, object enlargement, and feature enhancement.
66

77
<DilateDemo />
88

docs/API reference/Image/Morphology/Erode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ErodeDemo from './erode.demo.tsx'
22

33
[Check options and parameters of erode method](https://image-js.github.io/image-js-typescript/classes/Image.html#erode 'github.io link')
44

5-
[Erosion](https://en.wikipedia.org/wiki/Erosion 'wikipedia link on erosion') is a fundamental morphological operation in image processing that is used to reduce the size of foreground objects ([regions of interest](../../../Glossary.md#roiregion-of-interest 'internal link on region of interest')) within an image while preserving their shape and structure. It works by moving a structuring element (also known as a [kernel](../../../Glossary.md#kernel 'internal link on kernel')) over the image and replacing each pixel with the minimum value of the pixels covered by the structuring element. Erosion is particularly useful for tasks like noise reduction, edge detection, and object separation.
5+
[Erosion](https://en.wikipedia.org/wiki/Erosion 'wikipedia link on erosion') is a fundamental morphological operation in image processing that is used to reduce the size of foreground objects ([regions of interest](../../../Glossary.md#roiregion-of-interest 'internal link on region of interest')) within an image while preserving their shape and structure. It works by moving a structuring element (also known as a [kernel](../../../Glossary.md#kernel 'internal link on kernel')) over the image and replacing each pixel with the **minimum** value of the pixels covered by the structuring element. Erosion is particularly useful for tasks like noise reduction, edge detection, and object separation.
66

77
<ErodeDemo />
88

docs/API reference/Image/Morphology/Morphology.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Morphological operations are simple yet powerful tools that play a significant r
88

99
## Core concepts
1010

11+
There are two main processes in morphology:
12+
1113
- [Erode](Erode.md 'internal link on erode')
1214

1315
- [Dilate](Dilate.md 'internal link on dilate')
16+
17+
These two operations are the foundation of most of the morphological operation that ImageJs possesses.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Image } from 'image-js';
2+
3+
export default function bottomHat(image: Image) {
4+
image = image.grey();
5+
return image.bottomHat({
6+
kernel: [
7+
[1, 1, 1, 1, 1],
8+
[1, 1, 1, 1, 1],
9+
[1, 1, 1, 1, 1],
10+
[1, 1, 1, 1, 1],
11+
[1, 1, 1, 1, 1],
12+
],
13+
});
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import BottomHatDemo from './bottomHat.demo.tsx'
2+
3+
Similarly to [topHat](./topHat.md 'internal link to top hat'), [bottom hat](https://en.wikipedia.org/wiki/Top-hat_transform 'wikipedia link to top hat') operation computes the difference between two images. However, if top hat was using [opening method](./open.md 'internal link on open method'), bottom hat is using [closing method](./close.md 'internal link on close method').
4+
The purpose of bottom hat(or, as it is also called, _black-hat_) is to enhance and extract **darker** regions of the image.
5+
6+
<BottomHatDemo />
7+
8+
### Parameters and default values
9+
10+
- `options`
11+
12+
#### Options
13+
14+
| Property | Required | Default value |
15+
| ---------------------------------------------------------------------------------------------------------- | -------- | --------------------------------- |
16+
| [`iterations`](https://image-js.github.io/image-js-typescript/interfaces/BottomHatOptions.html#iterations) | no | `1` |
17+
| [`kernel`](https://image-js.github.io/image-js-typescript/interfaces/BottomHatOptions.html#kernel) | no | `[[1, 1, 1],[1, 1, 1],[1, 1, 1]]` |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Image } from 'image-js';
2+
3+
export default function cannyEdgeDetector(image: Image) {
4+
image = image.grey();
5+
return image.cannyEdgeDetector();
6+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import CannyEdgeDemo from './cannyEdgeDetector.demo.tsx'
2+
3+
[Check options and parameters of cannyEdgeDetector method](https://image-js.github.io/image-js-typescript/classes/Image.html#cannyEdgeDetector 'github.io link')
4+
5+
The Canny edge detector is a popular and widely used image processing technique for detecting edges in images. It is widely used in computer vision, image processing, and various applications such as object recognition, image segmentation, and feature extraction due to its ability to accurately detect edges and suppress noise.
6+
7+
The Canny edge detector is known for its ability to:
8+
9+
- Detect edges with good localization (i.e., edges are thin and located precisely).
10+
- Suppress noise due to the Gaussian smoothing.
11+
- Handle edges with varying levels of intensity (gradient).
12+
- Allow for customization through the selection of appropriate threshold values.
13+
14+
<CannyEdgeDemo />
15+
16+
### Parameters and default values
17+
18+
- `options`
19+
20+
#### Options
21+
22+
| Property | Required | Default value |
23+
| ---------------------------------------------------------------------------------------------------------------------------- | -------- | ------------- |
24+
| [`gaussianBlurOptions`](https://image-js.github.io/image-js-typescript/interfaces/CannyEdgeOptions.html#gaussianBlurOptions) | no | `1` |
25+
| [`highThreshold`](https://image-js.github.io/image-js-typescript/interfaces/CannyEdgeOptions.html#highThreshold) | no | `0.1` |
26+
| [`lowThreshold`](https://image-js.github.io/image-js-typescript/interfaces/CannyEdgeOptions.html#hysteresis) | no | `0.04` |
27+
| [`hysteresis`](https://image-js.github.io/image-js-typescript/interfaces/CannyEdgeOptions.html#hysteresis) | no | `true` |
28+
| [`out`](https://image-js.github.io/image-js-typescript/interfaces/CannyEdgeOptions.html#hysteresis) | no | - |
29+
30+
<details>
31+
<summary>
32+
<b>Implementation</b>
33+
</summary>
34+
The Canny edge detector consists of several stages:
35+
36+
_Smoothing_: The first step involves applying a Gaussian filter to the input image. This helps reduce noise and smooth out small variations in pixel values.
37+
38+
_Gradient Calculation_: After smoothing, the gradient of the image is calculated using convolution with Sobel masks in both the horizontal and vertical directions. This step highlights regions of rapid intensity change in the image.
39+
40+
_Non-maximum Suppression_: In this step, the gradient magnitude is examined at each pixel location, and non-maximum values are suppressed. This means that only the local maxima in gradient magnitude are retained, which helps thinning the edges and keeping only the most prominent ones.
41+
42+
**(optional)**
43+
44+
_Edge Tracking by [Hysteresis](../../../Glossary.md#hysteresis "internal link on hysteresis)_: This step involves tracking edges by applying two thresholds: a high threshold and a low threshold. Pixels with gradient magnitude values above the high threshold are considered strong edges, while those between the low and high thresholds are considered potential edges. The algorithm then connects potential edges to strong edges, forming continuous edge contours.
45+
46+
Finally, edge tracking by hysteresis is performed to link weak edges to strong edges. This helps in forming continuous edges and eliminating isolated weak edges caused by noise.
47+
48+
The output of the Canny edge detector is a binary image(mask) where edges are represented as white lines.
49+
50+
</details>
51+
52+
:::info
53+
The choice of threshold values for the high and low thresholds can affect the performance of the Canny edge detector and may need to be adjusted depending on the specific application and the characteristics of the input image.
54+
:::
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Image } from 'image-js';
2+
3+
export default function close(image: Image) {
4+
image = image.grey();
5+
return image.close({
6+
kernel: [
7+
[1, 1, 1, 1, 1],
8+
[1, 1, 1, 1, 1],
9+
[1, 1, 1, 1, 1],
10+
[1, 1, 1, 1, 1],
11+
[1, 1, 1, 1, 1],
12+
],
13+
});
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import CloseDemo from './close.demo.tsx'
2+
3+
Opposed to [opening](./open.md 'internal link to open method'), [closing process](<https://en.wikipedia.org/wiki/Closing_(morphology)> 'wikipedia link on closing') first [erodes](./Erode.md 'internal link to erode method') an image and only then [dilates](./Dilate.md 'internal link to dilate method') it.
4+
It is a useful process for filling small holes in the image, while preserving the shape and size of large holes and objects.
5+
6+
<CloseDemo />
7+
8+
### Parameters and default values
9+
10+
- `options`
11+
12+
#### Options
13+
14+
| Property | Required | Default value |
15+
| ------------------------------------------------------------------------------------------------------ | -------- | --------------------------------- |
16+
| [`iterations`](https://image-js.github.io/image-js-typescript/interfaces/CloseOptions.html#iterations) | no | `1` |
17+
| [`kernel`](https://image-js.github.io/image-js-typescript/interfaces/CloseOptions.html#kernel) | no | `[[1, 1, 1],[1, 1, 1],[1, 1, 1]]` |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { Image } from 'image-js';
2+
3+
export default function morphologicalGradient(image: Image) {
4+
image = image.grey();
5+
return image.morphologicalGradient();
6+
}

0 commit comments

Comments
 (0)