Skip to content

Commit c89df71

Browse files
docs: add documentation for region of interests (#79)
1 parent 4a9feb2 commit c89df71

20 files changed

+693
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
sidebar_position: 70
3+
---
4+
5+
_Center of mass of the current ROI._
6+
7+
[🔎 ROI options and parameters of `centroid` accessor](https://image-js.github.io/image-js-typescript/classes/Roi.html#centroid 'github.io link')
8+
9+
In image processing, centroid is the weighted average of all the coordinates that belong to the region of interest.
10+
11+
Centroids can be useful for determining the location of an object within an image as well as for tracking the movement of objects over time.
12+
13+
In ImageJS centroid is a ROI class accessor that returns a point:
14+
15+
```ts
16+
const centroid = roi.centroid;
17+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
sidebar_position: 0
3+
---
4+
5+
_Smallest convex polygon or polyhedron that contains region of interest._
6+
7+
[🎭 Mask options and parameters `getConvexHull` method](https://image-js.github.io/image-js-typescript/classes/Mask.html#getConvexHull 'github.io link')
8+
[🔎 ROI options and parameters of `convexHull` accessor](https://image-js.github.io/image-js-typescript/classes/Roi.html#convexHull 'github.io link')
9+
10+
[Convex Hull](https://en.wikipedia.org/wiki/Convex_hull 'wikipedia link on convex hull') is a way of characterizing the shape of an image by determining which pixels are adjacent to other pixels of the same intensity. This is a good way to find convex features in an image.
11+
12+
![Image input](./img/convexHull.svg)
13+
14+
:::tip
15+
To understand what convex hull is, picture a rubber band wrapped around your object. The shape of this rubber band will be the shape of your convex hull.
16+
:::
17+
18+
In ImageJS convex hull is a ROI class accessor that returns a `ConvexHull` object.
19+
20+
| Property name | Description | Property type |
21+
| -------------------------------------------------------------------------------------------------- | ---------------------------- | ------------- |
22+
| [`points`](https://image-js.github.io/image-js-typescript/interfaces/ConvexHull.html#points) | points that form convex hull | `Point[]` |
23+
| [`surface`](https://image-js.github.io/image-js-typescript/interfaces/ConvexHull.html#surface) | convex hull's surface | `number` |
24+
| [`perimeter`](https://image-js.github.io/image-js-typescript/interfaces/ConvexHull.html#perimeter) | convex hull's perimeter | `number` |
25+
26+
```ts
27+
const convexHull = roi.convexHull;
28+
```
29+
30+
It can also be a Mask method to calculate its convex hull:
31+
32+
```ts
33+
const convexHull = mask.getConvexHull();
34+
```
35+
36+
<details><summary><b>Implementation</b></summary>
37+
38+
Here's how convex hull algorithm is implemented in ImageJS:
39+
40+
_Calculate border points_: ImageJS uses an algorithm to identify points that constitute regions' borders.
41+
42+
_Sorting points lexicographically_: After finding border points, they get sorted in ascending order.
43+
44+
_Build the lower hull_: Traverse the sorted list of points to build the lower hull of the convex hull. Use a stack to keep track of the points in the lower hull. For each point, check whether it forms a left or right turn with the previous two points in the stack. If it forms a right turn, pop the last point from the stack until a left turn is formed. Then push the current point onto the stack.
45+
46+
_Build the upper hull_: Traverse the sorted list of points in reverse order to build the upper hull of the convex hull. Use the same stack as before. Again, ensure that the points in the stack form a convex hull.
47+
48+
_Combine the lower and upper hulls_: The combined result of the lower and upper hulls is the convex hull of the entire set of points.
49+
50+
</details>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
sidebar_position: 60
3+
---
4+
5+
_Diameter of a circle that has the same area as the projection area of the region of interest._
6+
7+
[🔎 ROI options and parameters of `eqpc` accessor](https://image-js.github.io/image-js-typescript/classes/Roi.html#eqpc 'github.io link')
8+
9+
EQPC represents a circle of equal projection area. This means that it is a diameter of a circle that has the same area as an object of interest.
10+
It is widely used for the evaluation of particles sizes from the projection area A of a non-spherical particle.
11+
12+
![roi image](./img/roi.svg)
13+
14+
The formula finds diameter from potential circle's surface:
15+
16+
$$
17+
EQPC = 2\sqrt{\frac{Surface}{\pi}}
18+
$$
19+
20+
In ImageJS EQPC is a ROI class accessor that returns a diameter length in pixels:
21+
22+
```ts
23+
const eqpcResult = roi.eqpc;
24+
```
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
sidebar_position: 10
3+
---
4+
5+
_The longest and shortest distances between two parallel lines that touch a region of interest._
6+
7+
[🎭 Mask options and parameters of `getFeret` method](https://image-js.github.io/image-js-typescript/classes/Mask.html#getFeret 'github.io link')
8+
[🔎 ROI options and parameters of `feret` accessor](https://image-js.github.io/image-js-typescript/classes/Roi.html#feret 'github.io link')
9+
10+
[Feret diameters](https://en.wikipedia.org/wiki/Feret_diameter 'wikipedia link on feret diameter') are determined by measuring the minimum and the maximum distances between two parallel tangents that touch the boundary of the region of interest.
11+
This measurement is commonly employed for the analysis of shapes and structures in images.
12+
13+
:::tip
14+
Feret diameters can be defined by the points as if the object was measured by [caliper](https://en.wikipedia.org/wiki/Calipers 'wikipedia link on caliper'). Therefore its other name, caliper diameter.
15+
:::
16+
17+
![Feret output](./img/feret.svg)
18+
19+
In ImageJS Feret diameters are a ROI class accessor that return a Feret object:
20+
21+
| Property name | Description | Property type |
22+
| ------------------------------------------------------------------------------------------------- | ------------------------------ | --------------- |
23+
| [`minDiameter`](https://image-js.github.io/image-js-typescript/interfaces/Feret.html#minDiameter) | minimum diameter | `FeretDiameter` |
24+
| [`maxDiameter`](https://image-js.github.io/image-js-typescript/interfaces/Feret.html#maxDiameter) | maximum diameter | `FeretDiameter` |
25+
| [`aspectRatio`](https://image-js.github.io/image-js-typescript/interfaces/Feret.html#aspectRatio) | ratio between diameter lengths | `number` |
26+
27+
```ts
28+
const feret = roi.feret;
29+
```
30+
31+
It can also be a Mask method to calculate its feret's diameters:
32+
33+
```ts
34+
const feret = mask.getFeret();
35+
```
36+
37+
:::info
38+
Each diameter in itself is also an object which has its own properties:
39+
40+
| Property name | Description | Property type |
41+
| ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ | ---------------------------------- |
42+
| [`angle`](https://image-js.github.io/image-js-typescript/interfaces/FeretDiameter.html#angle) | Angle between the diameter and a horizontal line in degrees. | `number` |
43+
| [`calliperLines`](https://image-js.github.io/image-js-typescript/interfaces/FeretDiameter.html#calliperLines) | Calliper lines that pass by endpoints of Feret diameters. | `[[Point, Point], [Point, Point]]` |
44+
| [`length`](https://image-js.github.io/image-js-typescript/interfaces/FeretDiameter.html#length) | length of the diameter | `number` |
45+
| [`points`](https://image-js.github.io/image-js-typescript/interfaces/FeretDiameter.html#points) | start and end points of the diameter | `[Point, Point]` |
46+
47+
:::
48+
49+
<details><summary><b>Implementation</b></summary>
50+
51+
Here's how Feret diameter is implemented in ImageJS:
52+
53+
_Finding convex hull points_: an algorithm is based on the fact that one of the lines is aligned with one of the convex hull sides. This significantly facilitates Feret's diameter's search. Here, a preexisting convex hull method is implemented.(see [convex hull page](./Convex%20Hull.md 'internal link on convex hull') for more information).
54+
55+
_Rotating an object_: an object gets rotated parallel to the X-axis. It allows finding tilt angles of the diameters. It also simplifies search for points. After all the data is found, it just gets rotated back by the same angle to get actual result.
56+
57+
_Calculating maximum distance between points_: the algorithm iterates through each point and looks for the biggest distance between other points of convex hull. For the minimum diameter it also compares it with the previous maximum value and if it is smaller, it becomes new current minimum diameter.
58+
For maximum diameter it just calculates the maximum distance between points of convex hull.
59+
60+
_Finding caliper lines_: First, region's extreme values are found among rotated points. For minimum these are X values, for maximum - Y values. After that, lines can be found rather easily. For minimum caliper lines lines have a common Y coordinate with feret points and they are situated at the extremities of an object, which is also easy to obtain, since the object is rotated. Same process for maximum diameter, but this time, it's an X coordinate which is common.
61+
62+
</details>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
sidebar_position: 80
3+
---
4+
5+
[🔎 ROI options and parameters of `fillRatio` accessor](https://image-js.github.io/image-js-typescript/classes/Roi.html#fillRatio 'github.io link')
6+
7+
_Ratio of the actual filled space to the total available space._
8+
9+
Fill ratio represents the ratio of how much of region's surface is filled with holes. Basically it helps understanding the actual ROI shape and how it is affected by holes in it. For example, if an object does not have holes or cavities in it the fill ratio will be equal to 1.
10+
11+
The ratio is calculated in a simple manner:
12+
13+
$$
14+
fill Ratio = \frac{Surface}{Surface + HolesInfo.surface}
15+
$$
16+
17+
Where $$HolesInfo.surface$$ is the surface property of the method that specifically calculates the information about ROI's holes.
18+
19+
In ImageJS fill ratio is a ROI class accessor that returns a ratio:
20+
21+
```ts
22+
const fillRatio = roi.fillRatio;
23+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
sidebar_position: 20
3+
---
4+
5+
_Smallest rectangle that fully encloses a region of interest, providing a bounding box with minimal area._
6+
7+
[🎭 Mask options and parameters of `getMbr` method](https://image-js.github.io/image-js-typescript/classes/Mask.html#getMbr 'github.io link')
8+
[🔎 ROI options and parameters of `mbr` accessor](https://image-js.github.io/image-js-typescript/classes/Roi.html#mbr 'github.io link')
9+
10+
Minimum Bounding Rectangle(MBR) is the smallest rectangle which can fit the region of interest in question.
11+
12+
![MBR output](./img/mbr.svg)
13+
14+
MBR is relevant for such things as extracting features, detecting collisions or simply localizing objects.
15+
16+
In ImageJS minimum bounding rectangle is a ROI class accessor that returns a `Mbr` object.
17+
18+
| Property name | Description | Property type |
19+
| ----------------------------------------------------------------------------------------------- | ------------------------------------ | ------------- |
20+
| [`points`](https://image-js.github.io/image-js-typescript/interfaces/Mbr.html#points) | points that form MBR | `Point[]` |
21+
| [`perimeter`](https://image-js.github.io/image-js-typescript/interfaces/Mbr.html#perimeter) | MBR's perimeter | `number` |
22+
| [`surface`](https://image-js.github.io/image-js-typescript/interfaces/Mbr.html#surface) | MBR's surface | `number` |
23+
| [`height`](https://image-js.github.io/image-js-typescript/interfaces/Mbr.html#height) | MBR's height | `number` |
24+
| [`width`](https://image-js.github.io/image-js-typescript/interfaces/Mbr.html#width) | MBR's width | `number` |
25+
| [`angle`](https://image-js.github.io/image-js-typescript/interfaces/Mbr.html#angle) | MBR's angle | `number` |
26+
| [`aspectRatio`](https://image-js.github.io/image-js-typescript/interfaces/Mbr.html#aspectRatio) | ratio between MBR's width and height | `number` |
27+
28+
```ts
29+
const mbr = roi.mbr;
30+
```
31+
32+
It can also be a Mask method to calculate its mbr:
33+
34+
```ts
35+
const mbr = mask.getMbr();
36+
```
37+
38+
<details><summary><b>Implementation</b></summary>
39+
40+
Here's how Minimum Bounding Rectangle is calculated in ImageJS:
41+
42+
_Finding convex hull_:an algorithm is based on the fact that one of the MBR sides is aligned with one of the convex hull sides.
43+
44+
_Rotating an object_: an object gets rotated parallel to the X-axis. It allows finding tilt angles of the diameters. It also facilitates calculation of the points. After all the data is found, it just gets rotated back by the same angle to get actual result.
45+
46+
_Finding extremities_: since the object is rotated, it means that vertical lines will be perpendicular to the hull side in question. Therefore, for each side, algorithm finds extremities which in turn calculate into points, width and surface.
47+
48+
</details>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
sidebar_position: 50
3+
---
4+
5+
_Diameter of a circle that has the same perimeter as the region of interest._
6+
7+
[🔎 ROI options and parameters of `ped` accessor](https://image-js.github.io/image-js-typescript/classes/Roi.html#ped 'github.io link')
8+
9+
PED represents a diameter of a circle that has the same perimeter as the particle image.
10+
Similarly to [EQPC](./EQPC.md 'internal link on eqpc') it is used to evaluate ROI's sizes albeit from its perimeter and not surface.
11+
12+
![roi image](./img/roi.svg)
13+
14+
The formula is simple:
15+
16+
$$
17+
PED = \frac{Perimeter}{\pi};
18+
$$
19+
20+
In ImageJS PED is a ROI class accessor that returns a diameter in pixels:
21+
22+
```ts
23+
const pedResult = roi.ped;
24+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
sidebar_position: 40
3+
---
4+
5+
_Total length of the object's outer borders._
6+
7+
[🔎 ROI options and parameters of `perimeter` accessor](https://image-js.github.io/image-js-typescript/classes/Roi.html#perimeter 'github.io link')
8+
9+
Although perimeter might seem like a straight-forward sum of border pixels this is not the case.
10+
In ImageJS each pixel's perimeter gets calculated depending on the number of sides that the pixel is exposed to externally.
11+
12+
This means:
13+
14+
We count all the pixel sides that are outside the ROI (each side counts as 1).
15+
If a pixel has 1 external side, this pixel's perimeter is equal to **1**.
16+
17+
If a pixel has 2 external sides, we remove from the sum **(2 - √2) = ~0.59**.
18+
Thus this **pixel's perimeter is equal to 2 - 0.59 = ~1.41**.
19+
20+
If a pixel has 3 external sides, we remove from the sum **2 \* (2 - √2) = ~1.17**.
21+
So this **pixel's perimeter is equal to 3 - 1.17 = ~1.83**.
22+
23+
![Image](./img/download.svg)
24+
25+
It is a basic tool that provides insight to region's size and length.
26+
27+
In ImageJS Perimeter is a ROI accessor that returns a perimeter in pixels:
28+
29+
```ts
30+
const perimeter = roi.perimeter;
31+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This section is dedicated to analysis of mask and its specific regions. ImageJS is first and foremost an analyzer of particles and analysis of regions of interest. Therefore there are tools that help detecting particles as well as determining their size, shape position and direction.
2+
3+
### Methods
4+
5+
| Can be applied on | ROIs | Masks |
6+
| ----------------------------------------------------------------------------------- | ------- | -------- |
7+
| [Convex Hull(`convexHull`)](./Convex%20Hull.md 'internal link on convex hull') | &#9989; | &#9989; |
8+
| [Feret diameter(`feret`)](./Feret%20Diameters.md 'internal link on feret diameter') | &#9989; | &#9989; |
9+
| [Minimum Bounding Rectangle( `mbr` )](./MBR.md 'internal link on mbr') | &#9989; | &#9989; |
10+
| [Perimeter(`perimeter`)](./Perimeter.md 'internal link on perimeter') | &#9989; | &#10060; |
11+
| [EQPC(`eqpc`)](./EQPC.md 'internal link on eqpc') | &#9989; | &#10060; |
12+
| [PED(`ped`)](./PED.md 'internal link on ped') | &#9989; | &#10060; |
13+
| [Centroid(`centroid`)](./Centroid.md 'internal link on centroid') | &#9989; | &#10060; |
14+
| [Fill ratio(`fillRatio`)](./Fill%20ratio.md 'internal link on fill ratio') | &#9989; | &#10060; |
15+
| [Solidity(`solidity`)](./Solidity.md 'internal link on solidity') | &#9989; | &#10060; |
16+
| [Roundness(`roundness`)](./Roundness.md 'internal link on roundness') | &#9989; | &#10060; |
17+
| [Sphericity(`sphericity`)](./Sphericity.md 'internal link on sphericity') | &#9989; | &#10060; |
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
sidebar_position: 100
3+
---
4+
5+
_Quantifies the deviation of an object's shape from a perfect circle._
6+
7+
[🔎 ROI options and parameters of `roundness` accessor](https://image-js.github.io/image-js-typescript/classes/Roi.html#roundness 'github.io link')
8+
9+
Roundness is the measure of how closely the shape of an object approaches that of a mathematically perfect circle.
10+
To compute it the formula is this:
11+
12+
$$
13+
Roundness = \frac{4*Surface}{\pi * FeretDiameter_{Max}^2}
14+
$$
15+
16+
Where $$FeretDiameter_{Max}$$ is the length of a maximum feret diameter.
17+
Using roundness as a metric allows for consistent and objective comparisons between different shapes, facilitating research and analysis across various disciplines.
18+
19+
In ImageJS roundness is a ROI class accessor that returns a ratio:
20+
21+
```ts
22+
const roundness = roi.roundness;
23+
```

0 commit comments

Comments
 (0)