image-js 1.0.0 → 1.1.0
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 +866 -198
- 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 +866 -198
- 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 +2 -3
- package/lib/Mask.d.ts +1 -1
- package/lib/Mask.js +1 -1
- package/lib/featureMatching/matching/filterEuclideanDistance.d.ts.map +1 -1
- package/lib/featureMatching/matching/filterEuclideanDistance.js +6 -7
- package/lib/featureMatching/matching/filterEuclideanDistance.js.map +1 -1
- package/lib/featureMatching/matching/filterSmallestDistanceMatches.d.ts.map +1 -1
- package/lib/featureMatching/matching/filterSmallestDistanceMatches.js +6 -3
- package/lib/featureMatching/matching/filterSmallestDistanceMatches.js.map +1 -1
- package/lib/featureMatching/utils/sortByDistance.d.ts.map +1 -1
- package/lib/featureMatching/utils/sortByDistance.js +3 -1
- package/lib/featureMatching/utils/sortByDistance.js.map +1 -1
- package/lib/featureMatching/utils/sortBySourceDest.d.ts.map +1 -1
- package/lib/featureMatching/utils/sortBySourceDest.js +6 -2
- package/lib/featureMatching/utils/sortBySourceDest.js.map +1 -1
- package/lib/load/decode.d.ts.map +1 -1
- package/lib/load/decode.js +2 -0
- package/lib/load/decode.js.map +1 -1
- package/lib/load/decodeBmp.d.ts +8 -0
- package/lib/load/decodeBmp.d.ts.map +1 -0
- package/lib/load/decodeBmp.js +36 -0
- package/lib/load/decodeBmp.js.map +1 -0
- package/lib/load/decodePng.d.ts.map +1 -1
- package/lib/load/decodePng.js +29 -5
- package/lib/load/decodePng.js.map +1 -1
- package/lib/load/decodeTiff.d.ts.map +1 -1
- package/lib/load/decodeTiff.js +44 -21
- package/lib/load/decodeTiff.js.map +1 -1
- package/lib/maskAnalysis/utils/getMbrAngle.d.ts.map +1 -1
- package/lib/maskAnalysis/utils/getMbrAngle.js +2 -1
- package/lib/maskAnalysis/utils/getMbrAngle.js.map +1 -1
- package/lib/maskAnalysis/utils/monotoneChainConvexHull.d.ts.map +1 -1
- package/lib/maskAnalysis/utils/monotoneChainConvexHull.js +2 -1
- package/lib/maskAnalysis/utils/monotoneChainConvexHull.js.map +1 -1
- package/lib/save/encodeBmp.d.ts +4 -4
- package/lib/save/encodeBmp.d.ts.map +1 -1
- package/lib/save/encodeBmp.js +22 -14
- package/lib/save/encodeBmp.js.map +1 -1
- package/lib/stack/load/decodeApng.d.ts +8 -0
- package/lib/stack/load/decodeApng.d.ts.map +1 -0
- package/lib/stack/load/decodeApng.js +60 -0
- package/lib/stack/load/decodeApng.js.map +1 -0
- package/lib/stack/load/decodeStack.d.ts.map +1 -1
- package/lib/stack/load/decodeStack.js +2 -0
- package/lib/stack/load/decodeStack.js.map +1 -1
- package/lib/utils/geometry/points.d.ts.map +1 -1
- package/lib/utils/geometry/points.js +3 -1
- package/lib/utils/geometry/points.js.map +1 -1
- package/lib/utils/geometry/removeClosePoints.d.ts.map +1 -1
- package/lib/utils/geometry/removeClosePoints.js +2 -1
- package/lib/utils/geometry/removeClosePoints.js.map +1 -1
- package/package.json +27 -27
- package/src/Mask.ts +1 -1
- package/src/featureMatching/matching/filterEuclideanDistance.ts +6 -13
- package/src/featureMatching/matching/filterSmallestDistanceMatches.ts +6 -9
- package/src/featureMatching/utils/sortByDistance.ts +3 -1
- package/src/featureMatching/utils/sortBySourceDest.ts +6 -2
- package/src/load/decode.ts +2 -1
- package/src/load/decodeBmp.ts +37 -0
- package/src/load/decodePng.ts +39 -7
- package/src/load/decodeTiff.ts +53 -22
- package/src/maskAnalysis/utils/getMbrAngle.ts +2 -1
- package/src/maskAnalysis/utils/monotoneChainConvexHull.ts +2 -1
- package/src/save/encodeBmp.ts +22 -15
- package/src/stack/load/decodeApng.ts +71 -0
- package/src/stack/load/decodeStack.ts +2 -0
- package/src/utils/geometry/points.ts +3 -1
- package/src/utils/geometry/removeClosePoints.ts +2 -1
package/src/save/encodeBmp.ts
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
import * as bmp from 'fast-bmp';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { Mask } from '../Mask.js';
|
|
3
|
+
import { Image } from '../Image.js';
|
|
4
|
+
import type { Mask } from '../Mask.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Creates a BMP buffer from a mask.
|
|
8
|
-
* @param
|
|
8
|
+
* @param image - The mask instance.
|
|
9
9
|
* @returns The buffer.
|
|
10
10
|
*/
|
|
11
|
-
export function encodeBmp(
|
|
12
|
-
if (
|
|
13
|
-
|
|
11
|
+
export function encodeBmp(image: Image | Mask) {
|
|
12
|
+
if (image instanceof Image) {
|
|
13
|
+
return bmp.encode({
|
|
14
|
+
width: image.width,
|
|
15
|
+
height: image.height,
|
|
16
|
+
components: image.components,
|
|
17
|
+
bitsPerPixel: image.channels * image.bitDepth,
|
|
18
|
+
channels: image.channels,
|
|
19
|
+
data: image.getRawImage().data,
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
return bmp.encode({
|
|
23
|
+
width: image.width,
|
|
24
|
+
height: image.height,
|
|
25
|
+
components: 1,
|
|
26
|
+
bitsPerPixel: 1,
|
|
27
|
+
channels: 1,
|
|
28
|
+
data: image.getRawImage().data,
|
|
29
|
+
});
|
|
14
30
|
}
|
|
15
|
-
const imageData = mask.getRawImage();
|
|
16
|
-
return bmp.encode({
|
|
17
|
-
width: imageData.width,
|
|
18
|
-
height: imageData.height,
|
|
19
|
-
components: 1,
|
|
20
|
-
bitsPerPixel: 1,
|
|
21
|
-
channels: 1,
|
|
22
|
-
data: imageData.data,
|
|
23
|
-
});
|
|
24
31
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { IndexedColors } from 'fast-png';
|
|
2
|
+
import { decodeApng } from 'fast-png';
|
|
3
|
+
|
|
4
|
+
import { Image } from '../../Image.ts';
|
|
5
|
+
import { Stack } from '../../Stack.ts';
|
|
6
|
+
import type { ImageColorModel } from '../../utils/constants/colorModels.ts';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Decodes APNG image into a Stack
|
|
10
|
+
* @param data - APNG data.
|
|
11
|
+
* @returns stack of frames.
|
|
12
|
+
*/
|
|
13
|
+
export function decodeStackFromApng(data: Uint8Array) {
|
|
14
|
+
const decodedApng = decodeApng(data);
|
|
15
|
+
const images: Image[] = [];
|
|
16
|
+
let colorModel: ImageColorModel;
|
|
17
|
+
switch (decodedApng.channels) {
|
|
18
|
+
case 1:
|
|
19
|
+
if (decodedApng.palette) {
|
|
20
|
+
colorModel = decodedApng.palette[0].length === 3 ? 'RGB' : 'RGBA';
|
|
21
|
+
} else {
|
|
22
|
+
colorModel = 'GREY';
|
|
23
|
+
}
|
|
24
|
+
break;
|
|
25
|
+
case 2:
|
|
26
|
+
colorModel = 'GREYA';
|
|
27
|
+
break;
|
|
28
|
+
case 3:
|
|
29
|
+
colorModel = 'RGB';
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
colorModel = 'RGBA';
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
if (decodedApng.palette) {
|
|
36
|
+
for (const image of decodedApng.frames) {
|
|
37
|
+
images.push(
|
|
38
|
+
new Image(decodedApng.width, decodedApng.height, {
|
|
39
|
+
data: convertIndexedData(
|
|
40
|
+
image.data as Uint8Array,
|
|
41
|
+
decodedApng.palette,
|
|
42
|
+
),
|
|
43
|
+
colorModel,
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
for (const image of decodedApng.frames) {
|
|
49
|
+
images.push(
|
|
50
|
+
new Image(decodedApng.width, decodedApng.height, {
|
|
51
|
+
data: image.data,
|
|
52
|
+
colorModel,
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const stack = new Stack(images);
|
|
59
|
+
|
|
60
|
+
return stack;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function convertIndexedData(data: Uint8Array, palette: IndexedColors) {
|
|
64
|
+
const result = new Uint8Array(data.length * palette[0].length);
|
|
65
|
+
for (let i = 0; i < data.length; i++) {
|
|
66
|
+
for (let channel = 0; channel < palette[0].length; channel++) {
|
|
67
|
+
result[i * palette[0].length + channel] = palette[data[i]][channel];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
@@ -3,6 +3,7 @@ import { match } from 'ts-pattern';
|
|
|
3
3
|
|
|
4
4
|
import type { Stack } from '../../Stack.js';
|
|
5
5
|
|
|
6
|
+
import { decodeStackFromApng } from './decodeApng.ts';
|
|
6
7
|
import { decodeStackFromTiff } from './decodeTiff.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -20,6 +21,7 @@ export function decodeStack(data: ArrayBufferView): Stack {
|
|
|
20
21
|
const type = imageType(typedArray);
|
|
21
22
|
return match(type)
|
|
22
23
|
.with({ mime: 'image/tiff' }, () => decodeStackFromTiff(typedArray))
|
|
24
|
+
.with({ mime: 'image/png' }, () => decodeStackFromApng(typedArray))
|
|
23
25
|
.otherwise(() => {
|
|
24
26
|
throw new RangeError(`invalid data format: ${type?.mime}`);
|
|
25
27
|
});
|
|
@@ -94,9 +94,11 @@ export function round(point: Point): Point {
|
|
|
94
94
|
* @returns Sorted points.
|
|
95
95
|
*/
|
|
96
96
|
export function sortByColumnRow(points: Point[]): Point[] {
|
|
97
|
-
|
|
97
|
+
const sortedPoints = points.slice();
|
|
98
|
+
sortedPoints.sort((point1, point2) => {
|
|
98
99
|
if (point1.column < point2.column) return -1;
|
|
99
100
|
if (point1.column > point2.column) return 1;
|
|
100
101
|
return point1.row - point2.row;
|
|
101
102
|
});
|
|
103
|
+
return sortedPoints;
|
|
102
104
|
}
|
|
@@ -42,7 +42,8 @@ export function removeClosePoints(
|
|
|
42
42
|
const channel = options?.channel || 0;
|
|
43
43
|
const isMax = kind === 'maximum';
|
|
44
44
|
|
|
45
|
-
const sortedPoints = points.slice()
|
|
45
|
+
const sortedPoints = points.slice();
|
|
46
|
+
sortedPoints.sort(getSort(image, channel, isMax));
|
|
46
47
|
|
|
47
48
|
if (distance > 0) {
|
|
48
49
|
for (let i = 0; i < sortedPoints.length; i++) {
|