image-js 0.35.1 → 0.35.3

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 (173) hide show
  1. package/index.d.ts +99 -35
  2. package/lib/browser/environment.js +0 -6
  3. package/lib/browser/worker/extend.js +0 -3
  4. package/lib/browser/worker/process/background.js +0 -12
  5. package/lib/browser/worker/worker.js +0 -17
  6. package/lib/image/Image.js +18 -51
  7. package/lib/image/compute/colorHistogram.js +0 -8
  8. package/lib/image/compute/countAlphaPixels.js +0 -3
  9. package/lib/image/compute/extendedPoints.js +2 -7
  10. package/lib/image/compute/histogram.js +6 -25
  11. package/lib/image/compute/localMaxima.js +2 -10
  12. package/lib/image/compute/max.js +0 -5
  13. package/lib/image/compute/mean.js +0 -4
  14. package/lib/image/compute/median.js +0 -4
  15. package/lib/image/compute/min.js +0 -5
  16. package/lib/image/compute/minimalBoundingRectangle.js +5 -18
  17. package/lib/image/compute/moment.js +0 -3
  18. package/lib/image/compute/monotoneChainConvexHull.js +0 -3
  19. package/lib/image/compute/points.js +0 -3
  20. package/lib/image/compute/relativePosition.js +2 -8
  21. package/lib/image/compute/sum.js +0 -5
  22. package/lib/image/core/bitMethods.js +0 -11
  23. package/lib/image/core/checkProcessable.js +0 -13
  24. package/lib/image/core/environment.js +0 -8
  25. package/lib/image/core/export.js +0 -38
  26. package/lib/image/core/extend.js +0 -13
  27. package/lib/image/core/getRGBAData.js +0 -15
  28. package/lib/image/core/kind.js +4 -28
  29. package/lib/image/core/kindNames.js +1 -0
  30. package/lib/image/core/load.js +1 -53
  31. package/lib/image/core/mediaTypes.js +0 -2
  32. package/lib/image/core/valueMethods.js +0 -13
  33. package/lib/image/extend.js +7 -83
  34. package/lib/image/filter/abs.js +0 -3
  35. package/lib/image/filter/add.js +2 -8
  36. package/lib/image/filter/background.js +0 -9
  37. package/lib/image/filter/blurFilter.js +0 -6
  38. package/lib/image/filter/divide.js +0 -8
  39. package/lib/image/filter/flipX.js +0 -5
  40. package/lib/image/filter/flipY.js +0 -4
  41. package/lib/image/filter/gaussianFilter.js +0 -5
  42. package/lib/image/filter/gradientFilter.js +0 -10
  43. package/lib/image/filter/hypotenuse.js +0 -13
  44. package/lib/image/filter/invert.js +0 -9
  45. package/lib/image/filter/level.js +1 -19
  46. package/lib/image/filter/medianFilter.js +0 -15
  47. package/lib/image/filter/multiply.js +0 -10
  48. package/lib/image/filter/scharrFilter.js +0 -4
  49. package/lib/image/filter/sobelFilter.js +0 -4
  50. package/lib/image/filter/subtract.js +0 -8
  51. package/lib/image/filter/subtractImage.js +0 -10
  52. package/lib/image/internal/checks.js +1 -9
  53. package/lib/image/internal/clamp.js +0 -1
  54. package/lib/image/internal/copy.js +0 -2
  55. package/lib/image/internal/copyAlphaChannel.js +0 -1
  56. package/lib/image/internal/getImageParameters.js +0 -1
  57. package/lib/image/internal/getOutputImage.js +1 -13
  58. package/lib/image/model/model.js +1 -1
  59. package/lib/image/morphology/blackHat.js +0 -5
  60. package/lib/image/morphology/close.js +0 -5
  61. package/lib/image/morphology/dilate.js +0 -40
  62. package/lib/image/morphology/erode.js +0 -40
  63. package/lib/image/morphology/morphologicalGradient.js +0 -5
  64. package/lib/image/morphology/open.js +0 -5
  65. package/lib/image/morphology/topHat.js +0 -5
  66. package/lib/image/operator/cannyEdge.js +0 -3
  67. package/lib/image/operator/convolution.js +9 -34
  68. package/lib/image/operator/convolutionSeparable.js +0 -10
  69. package/lib/image/operator/extract.js +4 -13
  70. package/lib/image/operator/floodFill.js +2 -15
  71. package/lib/image/operator/getSeparatedKernel.js +0 -2
  72. package/lib/image/operator/paintLabels.js +8 -19
  73. package/lib/image/operator/paintMasks.js +2 -12
  74. package/lib/image/operator/paintPoints.js +0 -9
  75. package/lib/image/operator/paintPolygon.js +1 -15
  76. package/lib/image/operator/paintPolygons.js +2 -6
  77. package/lib/image/operator/paintPolyline.js +0 -7
  78. package/lib/image/operator/paintPolylines.js +1 -5
  79. package/lib/image/roi/Roi.js +27 -207
  80. package/lib/image/roi/RoiLayer.js +1 -22
  81. package/lib/image/roi/RoiMap.js +5 -38
  82. package/lib/image/roi/creator/fromMask.js +4 -22
  83. package/lib/image/roi/creator/fromMaskConnectedComponentLabelingAlgorithm.js +2 -20
  84. package/lib/image/roi/creator/fromMaxima.js +10 -43
  85. package/lib/image/roi/creator/fromPoints.js +2 -10
  86. package/lib/image/roi/creator/fromWaterShed.js +6 -17
  87. package/lib/image/roi/feretDiameters.js +9 -21
  88. package/lib/image/roi/manager.js +30 -119
  89. package/lib/image/roi/util/commonBorderLength.js +5 -16
  90. package/lib/image/roi/util/mergeRoi.js +2 -21
  91. package/lib/image/transform/cmyk.js +0 -9
  92. package/lib/image/transform/colorDepth.js +0 -12
  93. package/lib/image/transform/crop.js +0 -20
  94. package/lib/image/transform/cropAlpha.js +0 -11
  95. package/lib/image/transform/grey.js +0 -16
  96. package/lib/image/transform/greyAlgorithms.js +1 -24
  97. package/lib/image/transform/hsl.js +0 -16
  98. package/lib/image/transform/hsv.js +0 -15
  99. package/lib/image/transform/insert.js +0 -6
  100. package/lib/image/transform/mask/huang.js +3 -18
  101. package/lib/image/transform/mask/intermodes.js +3 -14
  102. package/lib/image/transform/mask/isodata.js +0 -14
  103. package/lib/image/transform/mask/li.js +12 -42
  104. package/lib/image/transform/mask/mask.js +1 -13
  105. package/lib/image/transform/mask/maxEntropy.js +8 -25
  106. package/lib/image/transform/mask/mean.js +1 -3
  107. package/lib/image/transform/mask/minError.js +10 -21
  108. package/lib/image/transform/mask/minimum.js +0 -20
  109. package/lib/image/transform/mask/moments.js +4 -17
  110. package/lib/image/transform/mask/otsu.js +1 -7
  111. package/lib/image/transform/mask/percentile.js +0 -8
  112. package/lib/image/transform/mask/renyiEntropy.js +8 -34
  113. package/lib/image/transform/mask/shanbhag.js +8 -25
  114. package/lib/image/transform/mask/thresholdAlgorithms.js +1 -17
  115. package/lib/image/transform/mask/triangle.js +13 -29
  116. package/lib/image/transform/mask/yen.js +2 -14
  117. package/lib/image/transform/pad.js +0 -20
  118. package/lib/image/transform/resize/nearestNeighbor.js +0 -6
  119. package/lib/image/transform/resize/resize.js +0 -16
  120. package/lib/image/transform/rgba.js +0 -9
  121. package/lib/image/transform/rgba8.js +0 -3
  122. package/lib/image/transform/rotate.js +0 -29
  123. package/lib/image/transform/rotateFree.js +0 -31
  124. package/lib/image/transform/warping.js +2 -35
  125. package/lib/image/utility/combineChannels.js +0 -11
  126. package/lib/image/utility/getBestMatch.js +2 -13
  127. package/lib/image/utility/getChannel.js +0 -10
  128. package/lib/image/utility/getClosestCommonParent.js +6 -23
  129. package/lib/image/utility/getColumn.js +0 -4
  130. package/lib/image/utility/getIntersection.js +2 -18
  131. package/lib/image/utility/getMatrix.js +0 -7
  132. package/lib/image/utility/getPixelsArray.js +0 -5
  133. package/lib/image/utility/getPixelsGrid.js +0 -11
  134. package/lib/image/utility/getRow.js +0 -4
  135. package/lib/image/utility/getSimilarity.js +3 -17
  136. package/lib/image/utility/getThreshold.js +0 -4
  137. package/lib/image/utility/setBorder.js +0 -16
  138. package/lib/image/utility/setChannel.js +0 -6
  139. package/lib/image/utility/setMatrix.js +0 -6
  140. package/lib/image/utility/split.js +2 -15
  141. package/lib/index.js +0 -12
  142. package/lib/kernel/kernel.js +0 -3
  143. package/lib/kernel/laplacianOfGaussian.js +1 -7
  144. package/lib/node_modules/test/binary.js +0 -3
  145. package/lib/node_modules/test/oneRoi.js +0 -2
  146. package/lib/stack/Stack.js +2 -35
  147. package/lib/stack/compute/histogram.js +0 -4
  148. package/lib/stack/compute/histograms.js +0 -4
  149. package/lib/stack/compute/max.js +0 -3
  150. package/lib/stack/compute/median.js +0 -4
  151. package/lib/stack/compute/min.js +0 -3
  152. package/lib/stack/extend.js +1 -11
  153. package/lib/stack/transform/matchAndCrop.js +6 -19
  154. package/lib/stack/utility/averageImage.js +0 -9
  155. package/lib/stack/utility/maxImage.js +0 -7
  156. package/lib/stack/utility/minImage.js +0 -7
  157. package/lib/util/Shape.js +3 -40
  158. package/lib/util/base64.js +3 -14
  159. package/lib/util/channel.js +1 -35
  160. package/lib/util/color.js +1 -25
  161. package/lib/util/converter.js +1 -13
  162. package/lib/util/deepValue.js +0 -3
  163. package/lib/util/histogram.js +1 -12
  164. package/lib/util/kernel.js +2 -12
  165. package/lib/util/matrix.js +0 -13
  166. package/lib/util/points.js +12 -35
  167. package/lib/util/value.js +0 -7
  168. package/lib/util/zerosMatrix.js +0 -3
  169. package/package.json +2 -2
  170. package/src/image/operator/paintLabels.js +6 -6
  171. package/src/image/operator/paintPolygon.js +1 -1
  172. package/src/image/operator/paintPolygons.js +2 -2
  173. package/src/image/operator/paintPolylines.js +1 -1
package/index.d.ts CHANGED
@@ -2,6 +2,8 @@
2
2
  // Project: https://github.com/image-js/image-js
3
3
  // Definitions by: Michaël Zasso <https://github.com/targos>
4
4
 
5
+ import Matrix from 'ml-matrix';
6
+
5
7
  // Global variable exposed by UMD bundle
6
8
  export as namespace IJS;
7
9
 
@@ -124,7 +126,12 @@ export declare class Image {
124
126
  blackHat(options?: MorphologicalOptions): Image;
125
127
  morphologicalGradient(options?: MorphologicalOptions): Image;
126
128
 
127
- // warpingFourPoints
129
+ warpingFourPoints(
130
+ pts: Array<Array<number>>,
131
+ options?: {
132
+ calculateRatio?: boolean;
133
+ },
134
+ ): Image;
128
135
  crop(options?: CropOptions): Image;
129
136
  cropAlpha(options?: { threshold?: number }): Image;
130
137
  resize(options?: ResizeOptions): Image;
@@ -154,7 +161,7 @@ export declare class Image {
154
161
  getMatrix(options?: { channel?: number }): Matrix;
155
162
  setMatrix(matrix: Matrix, options?: { channel?: number });
156
163
  getPixelsArray(): Array<Array<number>>;
157
- // getIntersection
164
+ getIntersection(mask2: Image): object;
158
165
  getClosestCommonParent(mask: Image): Image;
159
166
  getThreshold(options?: { algorithm?: ThresholdAlgorithm }): number;
160
167
 
@@ -191,9 +198,23 @@ export declare class Image {
191
198
 
192
199
  // cannyEdge
193
200
  convolution(kernel: Kernel, options?: ConvolutionOptions): Image;
194
- // extract
201
+ extract(
202
+ mask: Image,
203
+ options?: {
204
+ position?: Array<number>;
205
+ },
206
+ ): this;
195
207
  // floodFill
196
- // paintLabels
208
+ paintLabels(
209
+ labels: Array<string>,
210
+ positions: Array<Array<number>>,
211
+ options?: {
212
+ color?: Array<number> | string;
213
+ colors?: Array<Array<number>> | Array<string>;
214
+ font?: string | Array<string>;
215
+ rotate?: number | Array<number>;
216
+ },
217
+ ): this;
197
218
  paintMasks(
198
219
  masks: Image | Array<Image>,
199
220
  options?: {
@@ -207,35 +228,87 @@ export declare class Image {
207
228
  labelColor?: string;
208
229
  labelFont?: string;
209
230
  },
210
- ): Image;
211
- // paintPoints
212
- // paintPolyline
213
- // paintPolylines
231
+ ): this;
232
+ paintPoints(
233
+ points: Array<Array<number>>,
234
+ options?: {
235
+ color?: Array<number> | string;
236
+ colors?: Array<Array<number>> | Array<string>;
237
+ randomColors?: boolean;
238
+ distinctColors?: boolean;
239
+ shape?: object;
240
+ },
241
+ ): this;
242
+ paintPolyline(
243
+ points: Array<Array<number>>,
244
+ options?: {
245
+ color?: Array<number>;
246
+ closed?: boolean;
247
+ },
248
+ ): this;
249
+ paintPolylines(
250
+ polylines: Array<Array<Array<number>>>,
251
+ options?: {
252
+ color?: Array<number> | string;
253
+ colors?: Array<Array<number>> | Array<string>;
254
+ randomColors?: boolean;
255
+ distinctColors?: boolean;
256
+ shape?: object;
257
+ },
258
+ ): this;
214
259
  paintPolygon(
215
260
  points: Array<Array<number>>,
216
261
  options?: {
217
262
  color?: Array<number>;
218
263
  filled?: boolean;
219
264
  },
220
- ): Image;
265
+ ): this;
266
+ paintPolygons(
267
+ points: Array<Array<Array<number>>>,
268
+ options?: {
269
+ color?: Array<number> | string;
270
+ colors?: Array<Array<number>> | Array<string>;
271
+ randomColors?: boolean;
272
+ distinctColors?: boolean;
273
+ shape?: object;
274
+ },
275
+ ): this;
221
276
 
222
- // paintPolygons
223
-
224
- // countAlphaPixels
225
- // monotoneChainConvexHull
226
- // minimalBoundingRectangle
227
- // getHistogram
228
- // getHistograms
229
- // getColorHistogram
230
- // getMin
231
- // getMax
232
- // getSum
233
- // getMoment
234
- // getLocalMaxima
235
- // getMedian
236
- // getMean
237
- // getPoints
238
- // getRelativePosition
277
+ countAlphaPixels(options?: { alpha?: number }): number;
278
+ monotoneChainConvexHull(): Array<Array<number>>;
279
+ minimalBoundingRectangle(options?: {
280
+ originalPoints?: Array<Array<number>>;
281
+ }): Array<Array<number>>;
282
+ getHistogram(options?: {
283
+ maxSlots?: number;
284
+ channel?: number;
285
+ useAlpha?: boolean;
286
+ }): Array<number>;
287
+ getHistograms(options?: { maxSlots?: number }): Array<Array<number>>;
288
+ getColorHistogram(options?: {
289
+ useAlpha?: boolean;
290
+ nbSlots?: number;
291
+ }): Array<number>;
292
+ getMin(): Array<number>;
293
+ getMax(): Array<number>;
294
+ getSum(): Array<number>;
295
+ getMoment(xPower: number, yPower: number): number;
296
+ getLocalMaxima(options?: {
297
+ mask?: Image;
298
+ region?: number;
299
+ removeClosePoints?: number;
300
+ invert?: boolean;
301
+ maxEquals?: number;
302
+ }): Array<number>;
303
+ getMedian(): Array<number>;
304
+ getMean(): Array<number>;
305
+ getPoints(): Array<Array<number>>;
306
+ getRelativePosition(
307
+ targetImage: Image,
308
+ options?: {
309
+ defaultFurther?: boolean;
310
+ },
311
+ ): Array<number> | boolean;
239
312
  }
240
313
 
241
314
  export declare class Stack extends Array<Image> {
@@ -257,15 +330,6 @@ export declare class Stack extends Array<Image> {
257
330
 
258
331
  export declare class RoiManager {}
259
332
 
260
- export declare class Matrix extends Array<Array<number>> {
261
- constructor();
262
- constructor(width: number, height: number, defaultValue?: number);
263
-
264
- localMin(x: number, y: number): { position: Array<number>; value: number };
265
- localMax(x: number, y: number): { position: Array<number>; value: number };
266
- localSearch(x: number, y: number, value: number): Array<Array<number>>;
267
- }
268
-
269
333
  export interface ImageConstructorOptions {
270
334
  width?: number;
271
335
  height?: number;
@@ -15,14 +15,12 @@ const ImageData = self.ImageData;
15
15
  exports.ImageData = ImageData;
16
16
  const DOMImage = self.Image;
17
17
  exports.DOMImage = DOMImage;
18
-
19
18
  function createCanvas(width, height) {
20
19
  let canvas = self.document.createElement('canvas');
21
20
  canvas.width = width;
22
21
  canvas.height = height;
23
22
  return canvas;
24
23
  }
25
-
26
24
  function fetchBinary(url, {
27
25
  withCredentials = false
28
26
  } = {}) {
@@ -31,20 +29,16 @@ function fetchBinary(url, {
31
29
  xhr.open('GET', url, true);
32
30
  xhr.responseType = 'arraybuffer';
33
31
  xhr.withCredentials = withCredentials;
34
-
35
32
  xhr.onload = function (e) {
36
33
  if (this.status !== 200) reject(e);else resolve(this.response);
37
34
  };
38
-
39
35
  xhr.onerror = reject;
40
36
  xhr.send();
41
37
  });
42
38
  }
43
-
44
39
  function createWriteStream() {
45
40
  throw new Error('createWriteStream does not exist in the browser');
46
41
  }
47
-
48
42
  function writeFile() {
49
43
  throw new Error('writeFile does not exist in the browser');
50
44
  }
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = extend;
7
-
8
7
  var _background = _interopRequireDefault(require("./process/background"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  function extend(Worker) {
13
10
  Worker.extendMethod('background', _background.default);
14
11
  }
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _Image = _interopRequireDefault(require("../../../image/Image"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  const defaultOptions = {
13
10
  regression: {
14
11
  kernelType: 'polynomial',
@@ -25,36 +22,29 @@ const defaultOptions = {
25
22
  sampling: 20,
26
23
  include: []
27
24
  };
28
-
29
25
  function run(image, options, onStep) {
30
26
  options = Object.assign({}, defaultOptions, options);
31
27
  const manager = this.manager;
32
-
33
28
  if (Array.isArray(image)) {
34
29
  return Promise.all(image.map(function (img) {
35
30
  const run = runOnce(manager, img, options);
36
-
37
31
  if (typeof onStep === 'function') {
38
32
  run.then(onStep);
39
33
  }
40
-
41
34
  return run;
42
35
  }));
43
36
  } else {
44
37
  return runOnce(manager, image, options);
45
38
  }
46
39
  }
47
-
48
40
  function runOnce(manager, image, options) {
49
41
  return manager.post('data', [image, options]).then(function (response) {
50
42
  for (let i in response) {
51
43
  response[i] = new _Image.default(response[i]);
52
44
  }
53
-
54
45
  return response;
55
46
  });
56
47
  }
57
-
58
48
  function work() {
59
49
  worker.on('data', function (send, image, options) {
60
50
  image = new IJS(image);
@@ -81,7 +71,6 @@ function work() {
81
71
  result.result = corrected;
82
72
  toTransfer.push(corrected.data.buffer);
83
73
  send(result, toTransfer);
84
-
85
74
  function maybeInclude(name, image) {
86
75
  if (options.include.includes(name)) {
87
76
  result[name] = image;
@@ -90,7 +79,6 @@ function work() {
90
79
  }
91
80
  });
92
81
  }
93
-
94
82
  const background = {
95
83
  run,
96
84
  work
@@ -4,43 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _webWorkerManager = _interopRequireDefault(require("web-worker-manager"));
9
-
10
8
  var _extend = _interopRequireDefault(require("./extend"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  class Worker {
15
11
  constructor() {
16
12
  this._url = null;
17
13
  this._deps = [null];
18
14
  }
19
-
20
15
  checkUrl() {
21
16
  if (this._url === null) {
22
17
  throw new Error('image worker must be initialized with an URL');
23
18
  }
24
19
  }
25
-
26
20
  get url() {
27
21
  return this._url;
28
22
  }
29
-
30
23
  set url(value) {
31
24
  if (typeof value !== 'string') {
32
25
  throw new TypeError('worker URL must be a string');
33
26
  }
34
-
35
27
  this._url = value;
36
28
  this._deps[0] = value;
37
29
  }
38
-
39
30
  static extendMethod(name, method) {
40
31
  let manager;
41
32
  let url;
42
33
  let runner = {};
43
-
44
34
  function run(...args) {
45
35
  if (!manager) {
46
36
  this.checkUrl();
@@ -50,10 +40,8 @@ class Worker {
50
40
  });
51
41
  runner.manager = manager;
52
42
  }
53
-
54
43
  return method.run.call(runner, ...args);
55
44
  }
56
-
57
45
  run.reset = function () {
58
46
  if (manager) {
59
47
  manager.terminate();
@@ -63,14 +51,9 @@ class Worker {
63
51
  runner.manager = manager;
64
52
  }
65
53
  };
66
-
67
54
  Worker.prototype[name] = run;
68
55
  }
69
-
70
56
  }
71
-
72
57
  (0, _extend.default)(Worker);
73
-
74
58
  var _default = new Worker();
75
-
76
59
  exports.default = _default;
@@ -4,34 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _bitMethods = _interopRequireDefault(require("./core/bitMethods"));
9
-
10
8
  var _checkProcessable = _interopRequireDefault(require("./core/checkProcessable"));
11
-
12
9
  var _export = _interopRequireDefault(require("./core/export"));
13
-
14
10
  var _extend = require("./core/extend");
15
-
16
11
  var _getRGBAData = _interopRequireDefault(require("./core/getRGBAData"));
17
-
18
12
  var _kind = require("./core/kind");
19
-
20
13
  var _kindNames = require("./core/kindNames");
21
-
22
14
  var _load = _interopRequireDefault(require("./core/load"));
23
-
24
15
  var _valueMethods = _interopRequireDefault(require("./core/valueMethods"));
25
-
26
16
  var _extend2 = _interopRequireDefault(require("./extend"));
27
-
28
17
  var _getImageParameters = _interopRequireDefault(require("./internal/getImageParameters"));
29
-
30
18
  var _manager = _interopRequireDefault(require("./roi/manager"));
31
-
32
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
-
34
20
  const objectToString = Object.prototype.toString;
21
+
35
22
  /**
36
23
  * Class representing an image.
37
24
  * This class allows to manipulate easily images directly in the browser or in node.
@@ -197,7 +184,6 @@ const objectToString = Object.prototype.toString;
197
184
  * // or
198
185
  * const image = new Image({ width: 2, height: 3, data, kind: 'RGB'});
199
186
  */
200
-
201
187
  class Image {
202
188
  constructor(width, height, data, options) {
203
189
  if (arguments.length === 1) {
@@ -213,40 +199,31 @@ class Image {
213
199
  data
214
200
  } = options);
215
201
  }
216
-
217
202
  if (width === undefined) width = 1;
218
203
  if (height === undefined) height = 1;
219
204
  if (options === undefined) options = {};
220
-
221
205
  if (typeof options !== 'object' || options === null) {
222
206
  throw new TypeError('options must be an object');
223
207
  }
224
-
225
208
  if (!Number.isInteger(width) || width <= 0) {
226
209
  throw new RangeError('width must be a positive integer');
227
210
  }
228
-
229
211
  if (!Number.isInteger(height) || height <= 0) {
230
212
  throw new RangeError('height must be a positive integer');
231
213
  }
232
-
233
214
  const {
234
215
  kind = _kindNames.RGBA
235
216
  } = options;
236
-
237
217
  if (typeof kind !== 'string') {
238
218
  throw new TypeError('kind must be a string');
239
219
  }
240
-
241
220
  const theKind = (0, _kind.getKind)(kind);
242
221
  const kindDefinition = Object.assign({}, options);
243
-
244
222
  for (const prop in theKind) {
245
223
  if (kindDefinition[prop] === undefined) {
246
224
  kindDefinition[prop] = theKind[prop];
247
225
  }
248
226
  }
249
-
250
227
  (0, _kind.verifyKindDefinition)(kindDefinition);
251
228
  const {
252
229
  components,
@@ -257,85 +234,83 @@ class Image {
257
234
  const size = width * height;
258
235
  const channels = components + alpha;
259
236
  const maxValue = bitDepth === 32 ? Number.MAX_VALUE : 2 ** bitDepth - 1;
260
-
261
237
  if (data === undefined) {
262
238
  data = (0, _kind.createPixelArray)(size, components, alpha, channels, bitDepth, maxValue);
263
239
  } else {
264
240
  const expectedLength = (0, _kind.getTheoreticalPixelArraySize)(size, channels, bitDepth);
265
-
266
241
  if (data.length !== expectedLength) {
267
242
  throw new RangeError(`incorrect data size: ${data.length}. Should be ${expectedLength}`);
268
243
  }
269
244
  }
245
+
270
246
  /**
271
247
  * Width of the image.
272
248
  * @member {number}
273
249
  */
274
-
275
-
276
250
  this.width = width;
251
+
277
252
  /**
278
253
  * Height of the image.
279
254
  * @member {number}
280
255
  */
281
-
282
256
  this.height = height;
257
+
283
258
  /**
284
259
  * Typed array holding the image data.
285
260
  * @member {TypedArray}
286
261
  */
287
-
288
262
  this.data = data;
263
+
289
264
  /**
290
265
  * Total number of pixels (width * height).
291
266
  * @member {number}
292
267
  */
293
-
294
268
  this.size = size;
269
+
295
270
  /**
296
271
  * Number of color channels in the image.
297
272
  * A grey image has 1 component. An RGB image has 3 components.
298
273
  * @member {number}
299
274
  */
300
-
301
275
  this.components = components;
276
+
302
277
  /**
303
278
  * Alpha is 1 if there is an alpha channel, 0 otherwise.
304
279
  * @member {number}
305
280
  */
306
-
307
281
  this.alpha = alpha;
282
+
308
283
  /**
309
284
  * Number of bits per value in each channel.
310
285
  * @member {number}
311
286
  */
312
-
313
287
  this.bitDepth = bitDepth;
288
+
314
289
  /**
315
290
  * Maximum value that a pixel can have.
316
291
  * @member {number}
317
292
  */
318
-
319
293
  this.maxValue = maxValue;
294
+
320
295
  /**
321
296
  * Color model of the image.
322
297
  * @member {ColorModel}
323
298
  */
324
-
325
299
  this.colorModel = colorModel;
300
+
326
301
  /**
327
302
  * Total number of channels. Is equal to `image.components + image.alpha`.
328
303
  * @member {number}
329
304
  */
330
-
331
305
  this.channels = channels;
306
+
332
307
  /**
333
308
  * Metadata associated with the image.
334
309
  * @member {object}
335
310
  */
311
+ this.meta = options.meta || {};
336
312
 
337
- this.meta = options.meta || {}; // TODO review those props
338
-
313
+ // TODO review those props
339
314
  Object.defineProperty(this, 'parent', {
340
315
  enumerable: false,
341
316
  writable: true,
@@ -354,22 +329,21 @@ class Image {
354
329
  get [Symbol.toStringTag]() {
355
330
  return 'IJSImage';
356
331
  }
357
-
358
332
  static isImage(object) {
359
333
  return objectToString.call(object) === '[object IJSImage]';
360
334
  }
335
+
361
336
  /**
362
337
  * Creates an image from an HTML Canvas object
363
338
  * @param {Canvas} canvas
364
339
  * @return {Image}
365
340
  */
366
-
367
-
368
341
  static fromCanvas(canvas) {
369
342
  const ctx = canvas.getContext('2d');
370
343
  const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
371
344
  return new Image(imageData.width, imageData.height, imageData.data);
372
345
  }
346
+
373
347
  /**
374
348
  * Create a new Image based on the characteristics of another one.
375
349
  * @param {Image} other
@@ -378,8 +352,6 @@ class Image {
378
352
  * @example
379
353
  * const newImage = Image.createFrom(image, { width: 100 });
380
354
  */
381
-
382
-
383
355
  static createFrom(other, options) {
384
356
  const newOptions = (0, _getImageParameters.default)(other);
385
357
  Object.assign(newOptions, {
@@ -388,28 +360,25 @@ class Image {
388
360
  }, options);
389
361
  return new Image(newOptions);
390
362
  }
363
+
391
364
  /**
392
365
  * Create a new manager for regions of interest based on the current image.
393
366
  * @param {object} [options]
394
367
  * @return {RoiManager}
395
368
  */
396
-
397
-
398
369
  getRoiManager(options) {
399
370
  return new _manager.default(this, options);
400
371
  }
372
+
401
373
  /**
402
374
  * Create a copy a the current image, including its data.
403
375
  * @instance
404
376
  * @return {Image}
405
377
  */
406
-
407
-
408
378
  clone() {
409
379
  const newData = this.data.slice();
410
380
  return new Image(this.width, this.height, newData, this);
411
381
  }
412
-
413
382
  apply(filter) {
414
383
  for (let y = 0; y < this.height; y++) {
415
384
  for (let x = 0; x < this.width; x++) {
@@ -418,9 +387,7 @@ class Image {
418
387
  }
419
388
  }
420
389
  }
421
-
422
390
  }
423
-
424
391
  exports.default = Image;
425
392
  (0, _valueMethods.default)(Image);
426
393
  (0, _bitMethods.default)(Image);
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = getColorHistogram;
7
-
8
7
  var _newArray = _interopRequireDefault(require("new-array"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  /**
13
10
  * @memberof Image
14
11
  * @instance
@@ -27,26 +24,21 @@ function getColorHistogram(options = {}) {
27
24
  components: [3]
28
25
  });
29
26
  let nbSlotsCheck = Math.log(nbSlots) / Math.log(8);
30
-
31
27
  if (nbSlotsCheck !== Math.floor(nbSlotsCheck)) {
32
28
  throw new RangeError('nbSlots must be a power of 8. Usually 8, 64, 512 or 4096');
33
29
  }
34
-
35
30
  let bitShift = this.bitDepth - nbSlotsCheck;
36
31
  let data = this.data;
37
32
  let result = (0, _newArray.default)(Math.pow(8, nbSlotsCheck), 0);
38
33
  let factor2 = Math.pow(2, nbSlotsCheck * 2);
39
34
  let factor1 = Math.pow(2, nbSlotsCheck);
40
-
41
35
  for (let i = 0; i < data.length; i += this.channels) {
42
36
  let slot = (data[i] >> bitShift) * factor2 + (data[i + 1] >> bitShift) * factor1 + (data[i + 2] >> bitShift);
43
-
44
37
  if (useAlpha && this.alpha) {
45
38
  result[slot] += data[i + this.channels - 1] / this.maxValue;
46
39
  } else {
47
40
  result[slot]++;
48
41
  }
49
42
  }
50
-
51
43
  return result;
52
44
  }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = countAlphaPixels;
7
-
8
7
  /**
9
8
  * Returns the number of transparent pixels
10
9
  * @memberof Image
@@ -22,14 +21,12 @@ function countAlphaPixels(options = {}) {
22
21
  alpha: 1
23
22
  });
24
23
  let count = 0;
25
-
26
24
  if (alpha !== undefined) {
27
25
  for (let i = this.components; i < this.data.length; i += this.channels) {
28
26
  if (this.data[i] === alpha) {
29
27
  count++;
30
28
  }
31
29
  }
32
-
33
30
  return count;
34
31
  } else {
35
32
  // because there is an alpha channel all the pixels have an alpha