image-js 1.3.0 → 1.5.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.
Files changed (104) hide show
  1. package/dist/image-js.esm.js +1050 -6561
  2. package/dist/image-js.esm.js.map +1 -1
  3. package/dist/image-js.esm.min.js +2 -2
  4. package/dist/image-js.esm.min.js.map +1 -1
  5. package/dist/image-js.umd.js +1051 -6560
  6. package/dist/image-js.umd.js.map +1 -1
  7. package/dist/image-js.umd.min.js +2 -2
  8. package/dist/image-js.umd.min.js.map +1 -1
  9. package/dist-types/image-js.d.ts +53 -13
  10. package/lib/Image.d.ts +1 -1
  11. package/lib/Image.d.ts.map +1 -1
  12. package/lib/Image.js.map +1 -1
  13. package/lib/featureMatching/index.d.ts +2 -0
  14. package/lib/featureMatching/index.d.ts.map +1 -1
  15. package/lib/featureMatching/index.js +2 -0
  16. package/lib/featureMatching/index.js.map +1 -1
  17. package/lib/featureMatching/keypoints/getEigenvaluesForScore.d.ts +11 -0
  18. package/lib/featureMatching/keypoints/getEigenvaluesForScore.d.ts.map +1 -0
  19. package/lib/featureMatching/keypoints/getEigenvaluesForScore.js +43 -0
  20. package/lib/featureMatching/keypoints/getEigenvaluesForScore.js.map +1 -0
  21. package/lib/featureMatching/keypoints/getFastKeypoints.d.ts +3 -2
  22. package/lib/featureMatching/keypoints/getFastKeypoints.d.ts.map +1 -1
  23. package/lib/featureMatching/keypoints/getFastKeypoints.js +14 -7
  24. package/lib/featureMatching/keypoints/getFastKeypoints.js.map +1 -1
  25. package/lib/featureMatching/keypoints/getHarrisScore.d.ts +2 -2
  26. package/lib/featureMatching/keypoints/getHarrisScore.d.ts.map +1 -1
  27. package/lib/featureMatching/keypoints/getHarrisScore.js +5 -37
  28. package/lib/featureMatching/keypoints/getHarrisScore.js.map +1 -1
  29. package/lib/featureMatching/keypoints/getOrientedFastKeypoints.d.ts +1 -1
  30. package/lib/featureMatching/keypoints/getOrientedFastKeypoints.d.ts.map +1 -1
  31. package/lib/featureMatching/keypoints/getOrientedFastKeypoints.js.map +1 -1
  32. package/lib/featureMatching/keypoints/getShiTomasiScore.d.ts +24 -0
  33. package/lib/featureMatching/keypoints/getShiTomasiScore.d.ts.map +1 -0
  34. package/lib/featureMatching/keypoints/getShiTomasiScore.js +18 -0
  35. package/lib/featureMatching/keypoints/getShiTomasiScore.js.map +1 -0
  36. package/lib/featureMatching/visualize/Montage.d.ts.map +1 -1
  37. package/lib/featureMatching/visualize/Montage.js.map +1 -1
  38. package/lib/filters/convolution.d.ts +1 -1
  39. package/lib/filters/convolution.d.ts.map +1 -1
  40. package/lib/filters/convolution.js +6 -1
  41. package/lib/filters/convolution.js.map +1 -1
  42. package/lib/filters/derivativeFilter.d.ts.map +1 -1
  43. package/lib/filters/derivativeFilter.js.map +1 -1
  44. package/lib/filters/medianFilter.d.ts +5 -5
  45. package/lib/filters/medianFilter.d.ts.map +1 -1
  46. package/lib/filters/medianFilter.js +3 -2
  47. package/lib/filters/medianFilter.js.map +1 -1
  48. package/lib/geometry/resize.d.ts +1 -1
  49. package/lib/geometry/resize.d.ts.map +1 -1
  50. package/lib/geometry/transform.d.ts +1 -1
  51. package/lib/geometry/transform.d.ts.map +1 -1
  52. package/lib/geometry/transform.js +6 -1
  53. package/lib/geometry/transform.js.map +1 -1
  54. package/lib/operations/extendBorders.d.ts +1 -1
  55. package/lib/operations/extendBorders.d.ts.map +1 -1
  56. package/lib/operations/extendBorders.js +6 -1
  57. package/lib/operations/extendBorders.js.map +1 -1
  58. package/lib/operations/grey.d.ts.map +1 -1
  59. package/lib/operations/grey.js.map +1 -1
  60. package/lib/operations/threshold.d.ts.map +1 -1
  61. package/lib/operations/threshold.js.map +1 -1
  62. package/lib/roi/colorRois.d.ts.map +1 -1
  63. package/lib/roi/colorRois.js.map +1 -1
  64. package/lib/roi/getRois.d.ts.map +1 -1
  65. package/lib/roi/getRois.js.map +1 -1
  66. package/lib/save/encode.d.ts.map +1 -1
  67. package/lib/save/encode.js.map +1 -1
  68. package/lib/utils/constants/colorModels.d.ts.map +1 -1
  69. package/lib/utils/constants/colorModels.js.map +1 -1
  70. package/lib/utils/cross_platform.d.ts +2 -1
  71. package/lib/utils/cross_platform.d.ts.map +1 -1
  72. package/lib/utils/cross_platform.js +9 -1
  73. package/lib/utils/cross_platform.js.map +1 -1
  74. package/lib/utils/interpolateBorder.d.ts +1 -1
  75. package/lib/utils/interpolateBorder.d.ts.map +1 -1
  76. package/lib/utils/interpolateBorder.js +4 -1
  77. package/lib/utils/interpolateBorder.js.map +1 -1
  78. package/lib/utils/interpolatePixel.d.ts +1 -1
  79. package/lib/utils/interpolatePixel.d.ts.map +1 -1
  80. package/lib/utils/interpolatePixel.js.map +1 -1
  81. package/package.json +33 -30
  82. package/src/Image.ts +2 -2
  83. package/src/featureMatching/index.ts +2 -0
  84. package/src/featureMatching/keypoints/getEigenvaluesForScore.ts +56 -0
  85. package/src/featureMatching/keypoints/getFastKeypoints.ts +22 -15
  86. package/src/featureMatching/keypoints/getHarrisScore.ts +6 -45
  87. package/src/featureMatching/keypoints/getOrientedFastKeypoints.ts +2 -3
  88. package/src/featureMatching/keypoints/getShiTomasiScore.ts +36 -0
  89. package/src/featureMatching/visualize/Montage.ts +0 -1
  90. package/src/filters/convolution.ts +8 -2
  91. package/src/filters/derivativeFilter.ts +0 -1
  92. package/src/filters/medianFilter.ts +12 -10
  93. package/src/geometry/resize.ts +1 -1
  94. package/src/geometry/transform.ts +8 -2
  95. package/src/operations/extendBorders.ts +7 -2
  96. package/src/operations/grey.ts +0 -1
  97. package/src/operations/threshold.ts +0 -1
  98. package/src/roi/colorRois.ts +0 -1
  99. package/src/roi/getRois.ts +0 -1
  100. package/src/save/encode.ts +0 -1
  101. package/src/utils/constants/colorModels.ts +0 -1
  102. package/src/utils/cross_platform.ts +11 -1
  103. package/src/utils/interpolateBorder.ts +6 -4
  104. package/src/utils/interpolatePixel.ts +1 -2
@@ -9,7 +9,6 @@ export const RoiKind = {
9
9
  WHITE: 'white',
10
10
  BW: 'bw',
11
11
  } as const;
12
- // eslint-disable-next-line @typescript-eslint/no-redeclare
13
12
  export type RoiKind = (typeof RoiKind)[keyof typeof RoiKind];
14
13
 
15
14
  export interface GetRoisOptions {
@@ -15,7 +15,6 @@ export const ImageFormat = {
15
15
  JPEG: 'jpeg',
16
16
  BMP: 'bmp',
17
17
  } as const;
18
- // eslint-disable-next-line @typescript-eslint/no-redeclare
19
18
  export type ImageFormat = (typeof ImageFormat)[keyof typeof ImageFormat];
20
19
 
21
20
  export interface EncodeOptionsPng {
@@ -5,7 +5,6 @@ export const ImageColorModel = {
5
5
  RGBA: 'RGBA',
6
6
  BINARY: 'BINARY',
7
7
  } as const;
8
- // eslint-disable-next-line @typescript-eslint/no-redeclare
9
8
  export type ImageColorModel =
10
9
  (typeof ImageColorModel)[keyof typeof ImageColorModel];
11
10
 
@@ -24,6 +24,7 @@ let CanvasCtorNode: typeof SkiaCanvas;
24
24
 
25
25
  /**
26
26
  * Returns a 2D canvas context for rendering on the browser or Node.js.
27
+ * On Node.js this requires the optional `skia-canvas` package to be installed.
27
28
  * @param width - Width of the canvas.
28
29
  * @param height - Height of the canvas.
29
30
  * @returns The initialised canvas context.
@@ -33,7 +34,16 @@ export function getCanvasContext(
33
34
  height: number,
34
35
  ): OffscreenCanvasRenderingContext2D | SkiaCanvasRenderingContext2D {
35
36
  if (isNode()) {
36
- CanvasCtorNode ??= getRequireFn()('skia-canvas').Canvas;
37
+ if (!CanvasCtorNode) {
38
+ try {
39
+ CanvasCtorNode = getRequireFn()('skia-canvas').Canvas;
40
+ } catch (error) {
41
+ throw new Error(
42
+ 'drawText on Node.js requires the optional "skia-canvas" package. Install it with: npm install skia-canvas',
43
+ { cause: error },
44
+ );
45
+ }
46
+ }
37
47
  return new CanvasCtorNode(width, height).getContext('2d');
38
48
  } else {
39
49
  CanvasCtorBrowser ??= globalThis.OffscreenCanvas;
@@ -11,7 +11,6 @@ export const BorderType = {
11
11
  WRAP: 'wrap',
12
12
  REFLECT_101: 'reflect101',
13
13
  } as const;
14
- // eslint-disable-next-line @typescript-eslint/no-redeclare
15
14
  export type BorderType = (typeof BorderType)[keyof typeof BorderType];
16
15
 
17
16
  /**
@@ -24,8 +23,11 @@ export type BorderType = (typeof BorderType)[keyof typeof BorderType];
24
23
  */
25
24
  export function getBorderInterpolation(
26
25
  type: BorderType,
27
- value: number,
26
+ value: number | number[],
28
27
  ): BorderInterpolationFunction {
28
+ if (typeof value === 'number') {
29
+ value = new Array(4).fill(value);
30
+ }
29
31
  return match(type)
30
32
  .with('constant', () => getInterpolateConstant(value))
31
33
  .with('replicate', () => interpolateReplicate)
@@ -41,7 +43,7 @@ function checkRange(point: number, length: number): void {
41
43
  }
42
44
  }
43
45
 
44
- function getInterpolateConstant(value: number): BorderInterpolationFunction {
46
+ function getInterpolateConstant(value: number[]): BorderInterpolationFunction {
45
47
  return function interpolateConstant(
46
48
  column: number,
47
49
  row: number,
@@ -51,7 +53,7 @@ function getInterpolateConstant(value: number): BorderInterpolationFunction {
51
53
  const newColumn = interpolateConstantPoint(column, image.width);
52
54
  const newRow = interpolateConstantPoint(row, image.height);
53
55
  if (newColumn === -1 || newRow === -1) {
54
- return value;
56
+ return value[channel];
55
57
  }
56
58
  return image.getValue(newColumn, newRow, channel);
57
59
  };
@@ -13,7 +13,6 @@ export const InterpolationType = {
13
13
  BILINEAR: 'bilinear',
14
14
  BICUBIC: 'bicubic',
15
15
  } as const;
16
- // eslint-disable-next-line @typescript-eslint/no-redeclare
17
16
  export type InterpolationType =
18
17
  (typeof InterpolationType)[keyof typeof InterpolationType];
19
18
 
@@ -22,7 +21,7 @@ type InterpolationFunction = (
22
21
  column: number,
23
22
  row: number,
24
23
  channel: number,
25
- intepolateBorder: BorderInterpolationFunction,
24
+ interpolateBorder: BorderInterpolationFunction,
26
25
  clamp: ClampFunction,
27
26
  ) => number;
28
27