image-js 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/image-js.esm.js +337 -18
- package/dist/image-js.esm.js.map +1 -1
- package/dist/image-js.esm.min.js +2 -2
- package/dist/image-js.esm.min.js.map +1 -1
- package/dist/image-js.umd.js +339 -22
- package/dist/image-js.umd.js.map +1 -1
- package/dist/image-js.umd.min.js +2 -2
- package/dist/image-js.umd.min.js.map +1 -1
- package/dist-types/image-js.d.ts +23 -2
- package/lib/Mask.d.ts +8 -0
- package/lib/Mask.d.ts.map +1 -1
- package/lib/Mask.js +10 -0
- package/lib/Mask.js.map +1 -1
- package/lib/load/decodePng.d.ts.map +1 -1
- package/lib/load/decodePng.js +26 -15
- package/lib/load/decodePng.js.map +1 -1
- package/lib/maskAnalysis/getContourMoore.d.ts +10 -0
- package/lib/maskAnalysis/getContourMoore.d.ts.map +1 -0
- package/lib/maskAnalysis/getContourMoore.js +107 -0
- package/lib/maskAnalysis/getContourMoore.js.map +1 -0
- package/lib/maskAnalysis/getContourPavlidis.d.ts +11 -0
- package/lib/maskAnalysis/getContourPavlidis.d.ts.map +1 -0
- package/lib/maskAnalysis/getContourPavlidis.js +90 -0
- package/lib/maskAnalysis/getContourPavlidis.js.map +1 -0
- package/lib/maskAnalysis/getExternalContour.d.ts +11 -0
- package/lib/maskAnalysis/getExternalContour.d.ts.map +1 -0
- package/lib/maskAnalysis/getExternalContour.js +18 -0
- package/lib/maskAnalysis/getExternalContour.js.map +1 -0
- package/lib/maskAnalysis/maskAnalysis.types.d.ts +8 -2
- package/lib/maskAnalysis/maskAnalysis.types.d.ts.map +1 -1
- package/lib/maskAnalysis/utils/getExtendedBorderPoints.d.ts.map +1 -1
- package/lib/maskAnalysis/utils/getExtendedBorderPoints.js +2 -4
- package/lib/maskAnalysis/utils/getExtendedBorderPoints.js.map +1 -1
- package/lib/maskAnalysis/utils/getExternalContourUtils.d.ts +17 -0
- package/lib/maskAnalysis/utils/getExternalContourUtils.d.ts.map +1 -0
- package/lib/maskAnalysis/utils/getExternalContourUtils.js +32 -0
- package/lib/maskAnalysis/utils/getExternalContourUtils.js.map +1 -0
- package/lib/roi/Roi.d.ts +7 -0
- package/lib/roi/Roi.d.ts.map +1 -1
- package/lib/roi/Roi.js +9 -0
- package/lib/roi/Roi.js.map +1 -1
- package/lib/roi/getExternalContour.d.ts +10 -0
- package/lib/roi/getExternalContour.d.ts.map +1 -0
- package/lib/roi/getExternalContour.js +11 -0
- package/lib/roi/getExternalContour.js.map +1 -0
- package/package.json +8 -5
- package/src/Mask.ts +12 -0
- package/src/load/decodePng.ts +25 -17
- package/src/maskAnalysis/getContourMoore.ts +143 -0
- package/src/maskAnalysis/getContourPavlidis.ts +102 -0
- package/src/maskAnalysis/getExternalContour.ts +27 -0
- package/src/maskAnalysis/maskAnalysis.types.ts +8 -2
- package/src/maskAnalysis/utils/getExtendedBorderPoints.ts +2 -4
- package/src/maskAnalysis/utils/getExternalContourUtils.ts +33 -0
- package/src/roi/Roi.ts +11 -0
- package/src/roi/getExternalContour.ts +17 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Mask } from '../../Mask.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Gets point's row and column from their index and mask width.
|
|
4
|
+
* @param index - point's index.
|
|
5
|
+
* @param maskWidth - mask width.
|
|
6
|
+
* @returns array of point's row and column.
|
|
7
|
+
*/
|
|
8
|
+
export function getCoordsFromIndex(index: number, maskWidth: number) {
|
|
9
|
+
return [Math.floor(index / maskWidth), index % maskWidth];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Safely get the bit value at the given column and row in the mask, returning 0 if out of bounds.
|
|
14
|
+
* @param mask - Mask to get the bit from.
|
|
15
|
+
* @param col - Column index.
|
|
16
|
+
* @param row - Row index.
|
|
17
|
+
* @returns the bit value.
|
|
18
|
+
*/
|
|
19
|
+
export function getBitSafe(mask: Mask, col: number, row: number): number {
|
|
20
|
+
if (!isInBounds(mask, col, row)) return 0;
|
|
21
|
+
return mask.getBit(col, row);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Checks if the given column and row are within the bounds of the mask.
|
|
26
|
+
* @param mask - Mask to check against.
|
|
27
|
+
* @param col - Column index.
|
|
28
|
+
* @param row - Row index.
|
|
29
|
+
* @returns whether the given column and row are within the bounds of the mask.
|
|
30
|
+
*/
|
|
31
|
+
function isInBounds(mask: Mask, col: number, row: number): boolean {
|
|
32
|
+
return col >= 0 && col < mask.width && row >= 0 && row < mask.height;
|
|
33
|
+
}
|
package/src/roi/Roi.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Mask } from '../Mask.js';
|
|
2
2
|
import { getConvexHull } from '../maskAnalysis/getConvexHull.js';
|
|
3
|
+
import type { GetExternalContourOptions } from '../maskAnalysis/getExternalContour.ts';
|
|
3
4
|
import { getFeret } from '../maskAnalysis/getFeret.js';
|
|
4
5
|
import { getMbr } from '../maskAnalysis/getMbr.js';
|
|
5
6
|
import type {
|
|
@@ -11,6 +12,7 @@ import type { Point } from '../utils/geometry/points.js';
|
|
|
11
12
|
|
|
12
13
|
import type { RoiMap } from './RoiMapManager.js';
|
|
13
14
|
import { getBorderPoints } from './getBorderPoints.js';
|
|
15
|
+
import { getExternalContour } from './getExternalContour.ts';
|
|
14
16
|
import type { GetMaskOptions } from './getMask.js';
|
|
15
17
|
import { getMask } from './getMask.js';
|
|
16
18
|
import { getEllipse } from './properties/getEllipse.js';
|
|
@@ -129,6 +131,15 @@ export class Roi {
|
|
|
129
131
|
return getBorderPoints(this, options);
|
|
130
132
|
}
|
|
131
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Finds external contour of the roi from its mask.
|
|
136
|
+
* @param options - GetExternalContourOptions.
|
|
137
|
+
* @returns Array of contour points.
|
|
138
|
+
*/
|
|
139
|
+
public getExternalContour(options?: GetExternalContourOptions): Point[] {
|
|
140
|
+
return getExternalContour(this, options);
|
|
141
|
+
}
|
|
142
|
+
|
|
132
143
|
/**
|
|
133
144
|
* Returns an array of ROIs IDs that are included in the current ROI.
|
|
134
145
|
* This will be useful to know if there are some holes in the ROI.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { GetExternalContourOptions } from '../maskAnalysis/getExternalContour.ts';
|
|
2
|
+
|
|
3
|
+
import type { Roi } from './Roi.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Finds external contour of the roi from its mask.
|
|
7
|
+
* @param roi - roi to find contour from.
|
|
8
|
+
* @param options - GetExternalContourOptions.
|
|
9
|
+
* @returns Array of contour points.
|
|
10
|
+
*/
|
|
11
|
+
export function getExternalContour(
|
|
12
|
+
roi: Roi,
|
|
13
|
+
options?: GetExternalContourOptions,
|
|
14
|
+
) {
|
|
15
|
+
const mask = roi.getMask();
|
|
16
|
+
return mask.getExternalContour(options);
|
|
17
|
+
}
|