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
@@ -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
  }
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = dilate;
7
-
8
7
  var _Image = _interopRequireDefault(require("../Image"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  /**
13
10
  * Dilatation is one of two fundamental operations (with erosion) in morphological
14
11
  * image processing from which all other morphological operations are based (from Wikipedia).
@@ -32,13 +29,10 @@ function dilate(options = {}) {
32
29
  components: 1,
33
30
  alpha: 0
34
31
  });
35
-
36
32
  if (kernel.columns % 2 === 0 || kernel.rows % 2 === 0) {
37
33
  throw new TypeError('dilate: The number of rows and columns of the kernel must be odd');
38
34
  }
39
-
40
35
  let onlyOnes = true;
41
-
42
36
  outer: for (const row of kernel) {
43
37
  for (const value of row) {
44
38
  if (value !== 1) {
@@ -47,9 +41,7 @@ function dilate(options = {}) {
47
41
  }
48
42
  }
49
43
  }
50
-
51
44
  let result = this;
52
-
53
45
  for (let i = 0; i < iterations; i++) {
54
46
  if (this.bitDepth === 1) {
55
47
  if (onlyOnes) {
@@ -57,33 +49,26 @@ function dilate(options = {}) {
57
49
  result = dilateOnceBinaryOnlyOnes(result, newImage, kernel.length, kernel[0].length);
58
50
  } else {
59
51
  const newImage = _Image.default.createFrom(result);
60
-
61
52
  result = dilateOnceBinary(result, newImage, kernel);
62
53
  }
63
54
  } else if (onlyOnes) {
64
55
  const newImage = _Image.default.createFrom(result);
65
-
66
56
  result = dilateOnceGreyOnlyOnes(result, newImage, kernel.length, kernel[0].length);
67
57
  } else {
68
58
  const newImage = _Image.default.createFrom(result);
69
-
70
59
  result = dilateOnceGrey(result, newImage, kernel);
71
60
  }
72
61
  }
73
-
74
62
  return result;
75
63
  }
76
-
77
64
  function dilateOnceGrey(img, newImage, kernel) {
78
65
  const kernelWidth = kernel.length;
79
66
  const kernelHeight = kernel[0].length;
80
67
  let radiusX = (kernelWidth - 1) / 2;
81
68
  let radiusY = (kernelHeight - 1) / 2;
82
-
83
69
  for (let y = 0; y < img.height; y++) {
84
70
  for (let x = 0; x < img.width; x++) {
85
71
  let max = 0;
86
-
87
72
  for (let jj = 0; jj < kernelHeight; jj++) {
88
73
  for (let ii = 0; ii < kernelWidth; ii++) {
89
74
  if (kernel[ii][jj] !== 1) continue;
@@ -94,64 +79,49 @@ function dilateOnceGrey(img, newImage, kernel) {
94
79
  if (value > max) max = value;
95
80
  }
96
81
  }
97
-
98
82
  newImage.setValueXY(x, y, 0, max);
99
83
  }
100
84
  }
101
-
102
85
  return newImage;
103
86
  }
104
-
105
87
  function dilateOnceGreyOnlyOnes(img, newImage, kernelWidth, kernelHeight) {
106
88
  const radiusX = (kernelWidth - 1) / 2;
107
89
  const radiusY = (kernelHeight - 1) / 2;
108
90
  const maxList = [];
109
-
110
91
  for (let x = 0; x < img.width; x++) {
111
92
  maxList.push(0);
112
93
  }
113
-
114
94
  for (let y = 0; y < img.height; y++) {
115
95
  for (let x = 0; x < img.width; x++) {
116
96
  let max = 0;
117
-
118
97
  for (let h = Math.max(0, y - radiusY); h < Math.min(img.height, y + radiusY + 1); h++) {
119
98
  const value = img.getValueXY(x, h, 0);
120
-
121
99
  if (value > max) {
122
100
  max = value;
123
101
  }
124
102
  }
125
-
126
103
  maxList[x] = max;
127
104
  }
128
-
129
105
  for (let x = 0; x < img.width; x++) {
130
106
  let max = 0;
131
-
132
107
  for (let i = Math.max(0, x - radiusX); i < Math.min(img.width, x + radiusX + 1); i++) {
133
108
  if (maxList[i] > max) {
134
109
  max = maxList[i];
135
110
  }
136
111
  }
137
-
138
112
  newImage.setValueXY(x, y, 0, max);
139
113
  }
140
114
  }
141
-
142
115
  return newImage;
143
116
  }
144
-
145
117
  function dilateOnceBinary(img, newImage, kernel) {
146
118
  const kernelWidth = kernel.length;
147
119
  const kernelHeight = kernel[0].length;
148
120
  let radiusX = (kernelWidth - 1) / 2;
149
121
  let radiusY = (kernelHeight - 1) / 2;
150
-
151
122
  for (let y = 0; y < img.height; y++) {
152
123
  for (let x = 0; x < img.width; x++) {
153
124
  let max = 0;
154
-
155
125
  intLoop: for (let jj = 0; jj < kernelHeight; jj++) {
156
126
  for (let ii = 0; ii < kernelWidth; ii++) {
157
127
  if (kernel[ii][jj] !== 1) continue;
@@ -159,36 +129,29 @@ function dilateOnceBinary(img, newImage, kernel) {
159
129
  let j = jj - radiusY + y;
160
130
  if (j < 0 || i < 0 || i >= img.width || j >= img.height) continue;
161
131
  const value = img.getBitXY(i, j);
162
-
163
132
  if (value === 1) {
164
133
  max = 1;
165
134
  break intLoop;
166
135
  }
167
136
  }
168
137
  }
169
-
170
138
  if (max === 1) {
171
139
  newImage.setBitXY(x, y);
172
140
  }
173
141
  }
174
142
  }
175
-
176
143
  return newImage;
177
144
  }
178
-
179
145
  function dilateOnceBinaryOnlyOnes(img, newImage, kernelWidth, kernelHeight) {
180
146
  const radiusX = (kernelWidth - 1) / 2;
181
147
  const radiusY = (kernelHeight - 1) / 2;
182
148
  const maxList = [];
183
-
184
149
  for (let x = 0; x < img.width; x++) {
185
150
  maxList.push(1);
186
151
  }
187
-
188
152
  for (let y = 0; y < img.height; y++) {
189
153
  for (let x = 0; x < img.width; x++) {
190
154
  maxList[x] = 0;
191
-
192
155
  for (let h = Math.max(0, y - radiusY); h < Math.min(img.height, y + radiusY + 1); h++) {
193
156
  if (img.getBitXY(x, h) === 1) {
194
157
  maxList[x] = 1;
@@ -196,10 +159,8 @@ function dilateOnceBinaryOnlyOnes(img, newImage, kernelWidth, kernelHeight) {
196
159
  }
197
160
  }
198
161
  }
199
-
200
162
  for (let x = 0; x < img.width; x++) {
201
163
  if (newImage.getBitXY(x, y) === 1) continue;
202
-
203
164
  for (let i = Math.max(0, x - radiusX); i < Math.min(img.width, x + radiusX + 1); i++) {
204
165
  if (maxList[i] === 1) {
205
166
  newImage.setBitXY(x, y);
@@ -208,6 +169,5 @@ function dilateOnceBinaryOnlyOnes(img, newImage, kernelWidth, kernelHeight) {
208
169
  }
209
170
  }
210
171
  }
211
-
212
172
  return newImage;
213
173
  }
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = erode;
7
-
8
7
  var _Image = _interopRequireDefault(require("../Image"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  /**
13
10
  * Erosion is one of two fundamental operations (with dilatation) in morphological
14
11
  * image processing from which all other morphological operations are based (from Wikipedia).
@@ -32,13 +29,10 @@ function erode(options = {}) {
32
29
  components: 1,
33
30
  alpha: 0
34
31
  });
35
-
36
32
  if (kernel.columns % 2 === 0 || kernel.rows % 2 === 0) {
37
33
  throw new TypeError('erode: The number of rows and columns of the kernel must be odd');
38
34
  }
39
-
40
35
  let onlyOnes = true;
41
-
42
36
  outer: for (const row of kernel) {
43
37
  for (const value of row) {
44
38
  if (value !== 1) {
@@ -47,9 +41,7 @@ function erode(options = {}) {
47
41
  }
48
42
  }
49
43
  }
50
-
51
44
  let result = this;
52
-
53
45
  for (let i = 0; i < iterations; i++) {
54
46
  if (this.bitDepth === 1) {
55
47
  if (onlyOnes) {
@@ -57,33 +49,26 @@ function erode(options = {}) {
57
49
  result = erodeOnceBinaryOnlyOnes(result, newImage, kernel.length, kernel[0].length);
58
50
  } else {
59
51
  const newImage = _Image.default.createFrom(result);
60
-
61
52
  result = erodeOnceBinary(result, newImage, kernel);
62
53
  }
63
54
  } else if (onlyOnes) {
64
55
  const newImage = _Image.default.createFrom(result);
65
-
66
56
  result = erodeOnceGreyOnlyOnes(result, newImage, kernel.length, kernel[0].length);
67
57
  } else {
68
58
  const newImage = _Image.default.createFrom(result);
69
-
70
59
  result = erodeOnceGrey(result, newImage, kernel);
71
60
  }
72
61
  }
73
-
74
62
  return result;
75
63
  }
76
-
77
64
  function erodeOnceGrey(img, newImage, kernel) {
78
65
  const kernelWidth = kernel.length;
79
66
  const kernelHeight = kernel[0].length;
80
67
  let radiusX = (kernelWidth - 1) / 2;
81
68
  let radiusY = (kernelHeight - 1) / 2;
82
-
83
69
  for (let y = 0; y < img.height; y++) {
84
70
  for (let x = 0; x < img.width; x++) {
85
71
  let min = img.maxValue;
86
-
87
72
  for (let jj = 0; jj < kernelHeight; jj++) {
88
73
  for (let ii = 0; ii < kernelWidth; ii++) {
89
74
  if (kernel[ii][jj] !== 1) continue;
@@ -94,64 +79,49 @@ function erodeOnceGrey(img, newImage, kernel) {
94
79
  if (value < min) min = value;
95
80
  }
96
81
  }
97
-
98
82
  newImage.setValueXY(x, y, 0, min);
99
83
  }
100
84
  }
101
-
102
85
  return newImage;
103
86
  }
104
-
105
87
  function erodeOnceGreyOnlyOnes(img, newImage, kernelWidth, kernelHeight) {
106
88
  const radiusX = (kernelWidth - 1) / 2;
107
89
  const radiusY = (kernelHeight - 1) / 2;
108
90
  const minList = [];
109
-
110
91
  for (let x = 0; x < img.width; x++) {
111
92
  minList.push(0);
112
93
  }
113
-
114
94
  for (let y = 0; y < img.height; y++) {
115
95
  for (let x = 0; x < img.width; x++) {
116
96
  let min = img.maxValue;
117
-
118
97
  for (let h = Math.max(0, y - radiusY); h < Math.min(img.height, y + radiusY + 1); h++) {
119
98
  const value = img.getValueXY(x, h, 0);
120
-
121
99
  if (value < min) {
122
100
  min = value;
123
101
  }
124
102
  }
125
-
126
103
  minList[x] = min;
127
104
  }
128
-
129
105
  for (let x = 0; x < img.width; x++) {
130
106
  let min = img.maxValue;
131
-
132
107
  for (let i = Math.max(0, x - radiusX); i < Math.min(img.width, x + radiusX + 1); i++) {
133
108
  if (minList[i] < min) {
134
109
  min = minList[i];
135
110
  }
136
111
  }
137
-
138
112
  newImage.setValueXY(x, y, 0, min);
139
113
  }
140
114
  }
141
-
142
115
  return newImage;
143
116
  }
144
-
145
117
  function erodeOnceBinary(img, newImage, kernel) {
146
118
  const kernelWidth = kernel.length;
147
119
  const kernelHeight = kernel[0].length;
148
120
  let radiusX = (kernelWidth - 1) / 2;
149
121
  let radiusY = (kernelHeight - 1) / 2;
150
-
151
122
  for (let y = 0; y < img.height; y++) {
152
123
  for (let x = 0; x < img.width; x++) {
153
124
  let min = 1;
154
-
155
125
  intLoop: for (let jj = 0; jj < kernelHeight; jj++) {
156
126
  for (let ii = 0; ii < kernelWidth; ii++) {
157
127
  if (kernel[ii][jj] !== 1) continue;
@@ -159,36 +129,29 @@ function erodeOnceBinary(img, newImage, kernel) {
159
129
  let j = jj - radiusY + y;
160
130
  if (j < 0 || i < 0 || i >= img.width || j >= img.height) continue;
161
131
  const value = img.getBitXY(i, j);
162
-
163
132
  if (value === 0) {
164
133
  min = 0;
165
134
  break intLoop;
166
135
  }
167
136
  }
168
137
  }
169
-
170
138
  if (min === 1) {
171
139
  newImage.setBitXY(x, y);
172
140
  }
173
141
  }
174
142
  }
175
-
176
143
  return newImage;
177
144
  }
178
-
179
145
  function erodeOnceBinaryOnlyOnes(img, newImage, kernelWidth, kernelHeight) {
180
146
  const radiusX = (kernelWidth - 1) / 2;
181
147
  const radiusY = (kernelHeight - 1) / 2;
182
148
  const minList = [];
183
-
184
149
  for (let x = 0; x < img.width; x++) {
185
150
  minList.push(0);
186
151
  }
187
-
188
152
  for (let y = 0; y < img.height; y++) {
189
153
  for (let x = 0; x < img.width; x++) {
190
154
  minList[x] = 1;
191
-
192
155
  for (let h = Math.max(0, y - radiusY); h < Math.min(img.height, y + radiusY + 1); h++) {
193
156
  if (img.getBitXY(x, h) === 0) {
194
157
  minList[x] = 0;
@@ -196,10 +159,8 @@ function erodeOnceBinaryOnlyOnes(img, newImage, kernelWidth, kernelHeight) {
196
159
  }
197
160
  }
198
161
  }
199
-
200
162
  for (let x = 0; x < img.width; x++) {
201
163
  if (newImage.getBitXY(x, y) === 0) continue;
202
-
203
164
  for (let i = Math.max(0, x - radiusX); i < Math.min(img.width, x + radiusX + 1); i++) {
204
165
  if (minList[i] === 0) {
205
166
  newImage.clearBitXY(x, y);
@@ -208,6 +169,5 @@ function erodeOnceBinaryOnlyOnes(img, newImage, kernelWidth, kernelHeight) {
208
169
  }
209
170
  }
210
171
  }
211
-
212
172
  return newImage;
213
173
  }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = morphologicalGradient;
7
-
8
7
  /**
9
8
  * In mathematical morphology and digital image processing, a morphological gradient is the difference between the dilation and the erosion of a given image. It is an image where each pixel value (typically non-negative) indicates the contrast intensity in the close neighborhood of that pixel. It is useful for edge detection and segmentation applications.
10
9
  * http://docs.opencv.org/2.4/doc/tutorials/imgproc/opening_closing_hats/opening_closing_hats.html
@@ -25,13 +24,10 @@ function morphologicalGradient(options = {}) {
25
24
  components: 1,
26
25
  alpha: 0
27
26
  });
28
-
29
27
  if (kernel.columns % 2 === 0 || kernel.rows % 2 === 0) {
30
28
  throw new TypeError('morphologicalGradient: The number of rows and columns of the kernel must be odd');
31
29
  }
32
-
33
30
  let newImage = this;
34
-
35
31
  for (let i = 0; i < iterations; i++) {
36
32
  let dilatedImage = newImage.dilate({
37
33
  kernel
@@ -43,6 +39,5 @@ function morphologicalGradient(options = {}) {
43
39
  absolute: true
44
40
  });
45
41
  }
46
-
47
42
  return newImage;
48
43
  }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = open;
7
-
8
7
  /**
9
8
  * In mathematical morphology, opening is the dilation of the erosion of a set A by a structuring element B.
10
9
  * Together with closing, the opening serves in computer vision and image processing as a basic workhorse of morphological noise removal.
@@ -28,13 +27,10 @@ function open(options = {}) {
28
27
  components: 1,
29
28
  alpha: 0
30
29
  });
31
-
32
30
  if (kernel.columns % 2 === 0 || kernel.rows % 2 === 0) {
33
31
  throw new TypeError('open: The number of rows and columns of the kernel must be odd');
34
32
  }
35
-
36
33
  let newImage = this;
37
-
38
34
  for (let i = 0; i < iterations; i++) {
39
35
  newImage = newImage.erode({
40
36
  kernel
@@ -43,6 +39,5 @@ function open(options = {}) {
43
39
  kernel
44
40
  });
45
41
  }
46
-
47
42
  return newImage;
48
43
  }
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = topHat;
7
-
8
7
  /**
9
8
  * This function is the white top hat (also called top hat). In mathematical morphology and digital image processing,
10
9
  * top-hat transform is an operation that extracts small elements and details from given images.
@@ -28,13 +27,10 @@ function topHat(options = {}) {
28
27
  components: 1,
29
28
  alpha: 0
30
29
  });
31
-
32
30
  if (kernel.length % 2 === 0 || kernel[0].length % 2 === 0) {
33
31
  throw new TypeError('topHat: The number of rows and columns of the kernel must be odd');
34
32
  }
35
-
36
33
  let newImage = this;
37
-
38
34
  for (let i = 0; i < iterations; i++) {
39
35
  let openImage = newImage.open({
40
36
  kernel
@@ -43,6 +39,5 @@ function topHat(options = {}) {
43
39
  absolute: true
44
40
  });
45
41
  }
46
-
47
42
  return newImage;
48
43
  }
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = cannyEdge;
7
-
8
7
  var _cannyEdgeDetector = _interopRequireDefault(require("canny-edge-detector"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  /**
13
10
  * @memberof Image
14
11
  * @instance