image-js 0.35.2 → 0.35.4

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 (170) hide show
  1. package/index.d.ts +3 -10
  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 -11
  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 +2 -13
  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 +0 -14
  76. package/lib/image/operator/paintPolygons.js +0 -4
  77. package/lib/image/operator/paintPolyline.js +0 -7
  78. package/lib/image/operator/paintPolylines.js +0 -4
  79. package/lib/image/roi/Roi.js +27 -208
  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 -17
  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 +3 -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 +1 -1
  170. package/src/image/utility/setMatrix.js +4 -0
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = level;
7
-
8
7
  var _newArray = _interopRequireDefault(require("new-array"));
9
-
10
8
  var _channel = require("../../util/channel");
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  /**
15
11
  * Level the image for by default have the minimal and maximal values.
16
12
  * @memberof Image
@@ -35,52 +31,40 @@ function level(options = {}) {
35
31
  channels = (0, _channel.validateArrayOfChannels)(this, {
36
32
  channels: channels
37
33
  });
38
-
39
34
  if (channels.length !== this.channel) {
40
35
  // if we process only part of the channels and the min or max length corresponds to the number of channels
41
36
  // we need to take the corresponding values
42
37
  if (Array.isArray(min) && min.length === this.channels) {
43
38
  min = min.filter((a, index) => channels.includes(index));
44
39
  }
45
-
46
40
  if (Array.isArray(max) && max.length === this.channels) {
47
41
  max = max.filter((a, index) => channels.includes(index));
48
42
  }
49
43
  }
50
-
51
44
  switch (algorithm) {
52
45
  case 'range':
53
46
  if (min < 0) {
54
47
  min = 0;
55
48
  }
56
-
57
49
  if (max > this.maxValue) {
58
50
  max = this.maxValue;
59
51
  }
60
-
61
52
  if (!Array.isArray(min)) {
62
53
  min = (0, _newArray.default)(channels.length, min);
63
54
  }
64
-
65
55
  if (!Array.isArray(max)) {
66
56
  max = (0, _newArray.default)(channels.length, max);
67
57
  }
68
-
69
58
  processImage(this, min, max, channels);
70
59
  break;
71
-
72
60
  default:
73
61
  throw new Error(`level: algorithm not implement: ${algorithm}`);
74
62
  }
75
-
76
63
  return this;
77
64
  }
78
-
79
65
  function processImage(image, min, max, channels) {
80
66
  let delta = 1e-5; // sorry no better value that this "best guess"
81
-
82
67
  let factor = new Array(channels.length);
83
-
84
68
  for (let i = 0; i < channels.length; i++) {
85
69
  if (min[i] === 0 && max[i] === image.maxValue) {
86
70
  factor[i] = 0;
@@ -89,9 +73,9 @@ function processImage(image, min, max, channels) {
89
73
  } else {
90
74
  factor[i] = (image.maxValue + 1 - delta) / (max[i] - min[i]);
91
75
  }
92
-
93
76
  min[i] += (0.5 - delta / 2) / factor[i];
94
77
  }
78
+
95
79
  /*
96
80
  Note on border effect
97
81
  For 8 bits images we should calculate for the space between -0.5 and 255.5
@@ -99,10 +83,8 @@ function processImage(image, min, max, channels) {
99
83
  But doing this we need to deal with Math.round that gives 256 if the value is 255.5
100
84
  */
101
85
 
102
-
103
86
  for (let j = 0; j < channels.length; j++) {
104
87
  let c = channels[j];
105
-
106
88
  if (factor[j] !== 0) {
107
89
  for (let i = 0; i < image.data.length; i += image.channels) {
108
90
  image.data[i + c] = Math.min(Math.max(0, (image.data[i + c] - min[j]) * factor[j] + 0.5 | 0), image.maxValue);
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = medianFilter;
7
-
8
7
  var _medianQuickselect = _interopRequireDefault(require("median-quickselect"));
9
-
10
8
  var _channel = require("../../util/channel");
11
-
12
9
  var _Image = _interopRequireDefault(require("../Image"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  /**
17
12
  * Each pixel of the image becomes the median of the neighbor pixels.
18
13
  * @memberof Image
@@ -32,46 +27,36 @@ function medianFilter(options = {}) {
32
27
  this.checkProcessable('medianFilter', {
33
28
  bitDepth: [8, 16]
34
29
  });
35
-
36
30
  if (radius < 1) {
37
31
  throw new Error('radius must be greater than 0');
38
32
  }
39
-
40
33
  channels = (0, _channel.validateArrayOfChannels)(this, channels, true);
41
34
  let kWidth = radius;
42
35
  let kHeight = radius;
43
-
44
36
  let newImage = _Image.default.createFrom(this);
45
-
46
37
  let size = (kWidth * 2 + 1) * (kHeight * 2 + 1);
47
38
  let kernel = new Array(size);
48
-
49
39
  for (let channel = 0; channel < channels.length; channel++) {
50
40
  let c = channels[channel];
51
-
52
41
  for (let y = kHeight; y < this.height - kHeight; y++) {
53
42
  for (let x = kWidth; x < this.width - kWidth; x++) {
54
43
  let n = 0;
55
-
56
44
  for (let j = -kHeight; j <= kHeight; j++) {
57
45
  for (let i = -kWidth; i <= kWidth; i++) {
58
46
  let index = ((y + j) * this.width + x + i) * this.channels + c;
59
47
  kernel[n++] = this.data[index];
60
48
  }
61
49
  }
62
-
63
50
  let index = (y * this.width + x) * this.channels + c;
64
51
  newImage.data[index] = (0, _medianQuickselect.default)(kernel);
65
52
  }
66
53
  }
67
54
  }
68
-
69
55
  if (this.alpha && !channels.includes(this.channels)) {
70
56
  for (let i = this.components; i < this.data.length; i = i + this.channels) {
71
57
  newImage.data[i] = this.data[i];
72
58
  }
73
59
  }
74
-
75
60
  newImage.setBorder({
76
61
  size: [kWidth, kHeight],
77
62
  algorithm: border
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = multiply;
7
-
8
7
  var _channel = require("../../util/channel");
9
-
10
8
  var _value = require("../../util/value");
11
-
12
9
  /**
13
10
  * @memberof Image
14
11
  * @instance
@@ -23,20 +20,16 @@ function multiply(value, options = {}) {
23
20
  this.checkProcessable('multiply', {
24
21
  bitDepth: [8, 16]
25
22
  });
26
-
27
23
  if (value <= 0) {
28
24
  throw new Error('multiply: the value must be greater than 0');
29
25
  }
30
-
31
26
  channels = (0, _channel.validateArrayOfChannels)(this, {
32
27
  channels: channels
33
28
  });
34
29
  value = (0, _value.checkNumberArray)(value);
35
-
36
30
  if (!isNaN(value)) {
37
31
  for (let j = 0; j < channels.length; j++) {
38
32
  let c = channels[j];
39
-
40
33
  for (let i = 0; i < this.data.length; i += this.channels) {
41
34
  this.data[i + c] = Math.min(this.maxValue, this.data[i + c] * value >> 0);
42
35
  }
@@ -45,15 +38,12 @@ function multiply(value, options = {}) {
45
38
  if (this.data.length !== value.length) {
46
39
  throw new Error('multiply: the data size is different');
47
40
  }
48
-
49
41
  for (let j = 0; j < channels.length; j++) {
50
42
  let c = channels[j];
51
-
52
43
  for (let i = 0; i < this.data.length; i += this.channels) {
53
44
  this.data[i + c] = Math.max(0, Math.min(this.maxValue, this.data[i + c] * value[i + c] >> 0));
54
45
  }
55
46
  }
56
47
  }
57
-
58
48
  return this;
59
49
  }
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = scharrFilter;
7
-
8
7
  var _kernels = require("../../util/kernels");
9
-
10
8
  var _gradientFilter = _interopRequireDefault(require("./gradientFilter"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  /**
15
11
  * Applies the Scharr operator.
16
12
  * @memberof Image
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = sobelFilter;
7
-
8
7
  var _kernels = require("../../util/kernels");
9
-
10
8
  var _gradientFilter = _interopRequireDefault(require("./gradientFilter"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  /**
15
11
  * Applies the Sobel operator.
16
12
  * @memberof Image
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = subtract;
7
-
8
7
  var _channel = require("../../util/channel");
9
-
10
8
  var _value = require("../../util/value");
11
-
12
9
  /**
13
10
  * @memberof Image
14
11
  * @instance
@@ -27,11 +24,9 @@ function subtract(value, options = {}) {
27
24
  channels: channels
28
25
  });
29
26
  value = (0, _value.checkNumberArray)(value);
30
-
31
27
  if (!isNaN(value)) {
32
28
  for (let j = 0; j < channels.length; j++) {
33
29
  let c = channels[j];
34
-
35
30
  for (let i = 0; i < this.data.length; i += this.channels) {
36
31
  this.data[i + c] = Math.max(0, this.data[i + c] - value >> 0);
37
32
  }
@@ -40,15 +35,12 @@ function subtract(value, options = {}) {
40
35
  if (this.data.length !== value.length) {
41
36
  throw new Error('subtract: the data size is different');
42
37
  }
43
-
44
38
  for (let j = 0; j < channels.length; j++) {
45
39
  let c = channels[j];
46
-
47
40
  for (let i = 0; i < this.data.length; i += this.channels) {
48
41
  this.data[i + c] = Math.max(0, Math.min(this.maxValue, this.data[i + c] - value[i + c] >> 0));
49
42
  }
50
43
  }
51
44
  }
52
-
53
45
  return this;
54
46
  }
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = subtractImage;
7
-
8
7
  var _channel = require("../../util/channel");
9
-
10
8
  /**
11
9
  * Calculate a new image that is the subtraction between the current image and the otherImage.
12
10
  * @memberof Image
@@ -25,30 +23,23 @@ function subtractImage(otherImage, options = {}) {
25
23
  this.checkProcessable('subtractImage', {
26
24
  bitDepth: [8, 16]
27
25
  });
28
-
29
26
  if (this.width !== otherImage.width || this.height !== otherImage.height) {
30
27
  throw new Error('subtractImage: both images must have the same size');
31
28
  }
32
-
33
29
  if (this.alpha !== otherImage.alpha || this.bitDepth !== otherImage.bitDepth) {
34
30
  throw new Error('subtractImage: both images must have the same alpha and bitDepth');
35
31
  }
36
-
37
32
  if (this.channels !== otherImage.channels) {
38
33
  throw new Error('subtractImage: both images must have the same number of channels');
39
34
  }
40
-
41
35
  let newImage = this.clone();
42
36
  channels = (0, _channel.validateArrayOfChannels)(this, {
43
37
  channels: channels
44
38
  });
45
-
46
39
  for (let j = 0; j < channels.length; j++) {
47
40
  let c = channels[j];
48
-
49
41
  for (let i = c; i < this.data.length; i += this.channels) {
50
42
  let value = this.data[i] - otherImage.data[i];
51
-
52
43
  if (absolute) {
53
44
  newImage.data[i] = Math.abs(value);
54
45
  } else {
@@ -56,6 +47,5 @@ function subtractImage(otherImage, options = {}) {
56
47
  }
57
48
  }
58
49
  }
59
-
60
50
  return newImage;
61
51
  }
@@ -8,46 +8,38 @@ exports.checkColumn = checkColumn;
8
8
  exports.checkInterpolation = checkInterpolation;
9
9
  exports.checkRow = checkRow;
10
10
  exports.validInterpolations = void 0;
11
-
12
11
  function checkRow(image, row) {
13
12
  if (row < 0 || row >= image.height) {
14
13
  throw new RangeError(`row must be included between 0 and ${image.height - 1}. Current value: ${row}`);
15
14
  }
16
15
  }
17
-
18
16
  function checkColumn(image, column) {
19
17
  if (column < 0 || column >= image.width) {
20
18
  throw new RangeError(`column must be included between 0 and ${image.width - 1}. Current value: ${column}`);
21
19
  }
22
20
  }
23
-
24
21
  function checkChannel(image, channel) {
25
22
  if (channel < 0 || channel >= image.channels) {
26
23
  throw new RangeError(`channel must be included between 0 and ${image.channels - 1}. Current value: ${channel}`);
27
24
  }
28
25
  }
26
+
29
27
  /**
30
28
  * @typedef {('nearestNeighbor'|'bilinear')} InterpolationAlgorithm
31
29
  */
32
-
33
-
34
30
  const validInterpolations = {
35
31
  nearestneighbor: 'nearestNeighbor',
36
32
  nearestneighbour: 'nearestNeighbor',
37
33
  bilinear: 'bilinear'
38
34
  };
39
35
  exports.validInterpolations = validInterpolations;
40
-
41
36
  function checkInterpolation(interpolation) {
42
37
  if (typeof interpolation !== 'string') {
43
38
  throw new TypeError('interpolation must be a string');
44
39
  }
45
-
46
40
  interpolation = interpolation.toLowerCase();
47
-
48
41
  if (!validInterpolations[interpolation]) {
49
42
  throw new RangeError(`invalid interpolation algorithm: ${interpolation}`);
50
43
  }
51
-
52
44
  return validInterpolations[interpolation];
53
45
  }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.clamp = clamp;
7
-
8
7
  function clamp(value, image) {
9
8
  return Math.round(Math.min(Math.max(value, 0), image.maxValue));
10
9
  }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = copyImage;
7
-
8
7
  /**
9
8
  * Make a copy of the current image
10
9
  * @memberof Image
@@ -19,7 +18,6 @@ function copyImage(fromImage, toImage, x, y) {
19
18
  let fromHeight = fromImage.height;
20
19
  let toWidth = toImage.width;
21
20
  let channels = fromImage.channels;
22
-
23
21
  for (let i = 0; i < fromWidth; i++) {
24
22
  for (let j = 0; j < fromHeight; j++) {
25
23
  for (let k = 0; k < channels; k++) {
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = copyAlphaChannel;
7
-
8
7
  /**
9
8
  * Copies the alpha channel from an image to another. no-op if one of the images has no alpha
10
9
  * @private
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = getImageParameters;
7
-
8
7
  function getImageParameters(image) {
9
8
  return {
10
9
  width: image.width,
@@ -5,13 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getOutputImage = getOutputImage;
7
7
  exports.getOutputImageOrInPlace = getOutputImageOrInPlace;
8
-
9
8
  var _Image = _interopRequireDefault(require("../Image"));
10
-
11
9
  var _getImageParameters = _interopRequireDefault(require("./getImageParameters"));
12
-
13
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
11
  /**
16
12
  * Use this function to support getting the output image of an algorithm from user-supplied
17
13
  * options.
@@ -27,7 +23,6 @@ function getOutputImage(thisImage, options, newParameters, internalOptions = {})
27
23
  const {
28
24
  out
29
25
  } = options;
30
-
31
26
  if (out === undefined) {
32
27
  if (internalOptions.copy) {
33
28
  return thisImage.clone();
@@ -38,18 +33,16 @@ function getOutputImage(thisImage, options, newParameters, internalOptions = {})
38
33
  if (!_Image.default.isImage(out)) {
39
34
  throw new TypeError('out must be an Image object');
40
35
  }
41
-
42
36
  const requirements = Object.assign((0, _getImageParameters.default)(thisImage), newParameters);
43
-
44
37
  for (const property in requirements) {
45
38
  if (out[property] !== requirements[property]) {
46
39
  throw new RangeError(`cannot use out. Its ${property} must be "${requirements[property]}" (found "${out[property]}")`);
47
40
  }
48
41
  }
49
-
50
42
  return out;
51
43
  }
52
44
  }
45
+
53
46
  /**
54
47
  * Same as getOutputImage but allows for an `inPlace` option.
55
48
  * @private
@@ -61,20 +54,15 @@ function getOutputImage(thisImage, options, newParameters, internalOptions = {})
61
54
  * @param {boolean} [interalOptions.copy] - If true will copy the original image instead of creating a new empty image
62
55
  * @return {Image}
63
56
  */
64
-
65
-
66
57
  function getOutputImageOrInPlace(thisImage, options, internalOptions) {
67
58
  if (options.inPlace !== undefined && typeof options.inPlace !== 'boolean') {
68
59
  throw new TypeError('inPlace option must be a boolean');
69
60
  }
70
-
71
61
  if (options.inPlace) {
72
62
  if (options.out !== undefined) {
73
63
  throw new TypeError('out option must not be set if inPlace option is true');
74
64
  }
75
-
76
65
  return thisImage;
77
66
  }
78
-
79
67
  return getOutputImage(thisImage, options, null, internalOptions);
80
68
  }
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.RGB = exports.HSV = exports.HSL = exports.GREY = exports.CMYK = void 0;
7
-
8
7
  /**
9
8
  * Color model of an image
10
9
  * @typedef {('GREY'|'RGB'|'HSL'|'HSV'|'CMYK')} ColorModel
11
10
  */
11
+
12
12
  const GREY = 'GREY';
13
13
  exports.GREY = GREY;
14
14
  const RGB = 'RGB';
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = blackHat;
7
-
8
7
  /**
9
8
  * This function is the black top hat (also called black hat).
10
9
  * In mathematical morphology and digital image processing,
@@ -30,13 +29,10 @@ function blackHat(options = {}) {
30
29
  components: 1,
31
30
  alpha: 0
32
31
  });
33
-
34
32
  if (kernel.columns % 2 === 0 || kernel.rows % 2 === 0) {
35
33
  throw new TypeError('blackHat: The number of rows and columns of the kernel must be odd');
36
34
  }
37
-
38
35
  let newImage = this;
39
-
40
36
  for (let i = 0; i < iterations; i++) {
41
37
  const closeImage = newImage.close({
42
38
  kernel
@@ -45,6 +41,5 @@ function blackHat(options = {}) {
45
41
  absolute: true
46
42
  });
47
43
  }
48
-
49
44
  return newImage;
50
45
  }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = close;
7
-
8
7
  /**
9
8
  * In mathematical morphology, the closing of a set A by a structuring element B is the erosion of the dilation of that set (Wikipedia).
10
9
  * In image processing, closing is, together with opening, the basic workhorse of morphological noise removal.
@@ -27,13 +26,10 @@ function close(options = {}) {
27
26
  components: 1,
28
27
  alpha: 0
29
28
  });
30
-
31
29
  if (kernel.columns % 2 === 0 || kernel.rows % 2 === 0) {
32
30
  throw new TypeError('close: The number of rows and columns of the kernel must be odd');
33
31
  }
34
-
35
32
  let newImage = this;
36
-
37
33
  for (let i = 0; i < iterations; i++) {
38
34
  newImage = newImage.dilate({
39
35
  kernel
@@ -41,6 +37,5 @@ function close(options = {}) {
41
37
  kernel
42
38
  });
43
39
  }
44
-
45
40
  return newImage;
46
41
  }