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.
- package/index.d.ts +99 -35
- package/lib/browser/environment.js +0 -6
- package/lib/browser/worker/extend.js +0 -3
- package/lib/browser/worker/process/background.js +0 -12
- package/lib/browser/worker/worker.js +0 -17
- package/lib/image/Image.js +18 -51
- package/lib/image/compute/colorHistogram.js +0 -8
- package/lib/image/compute/countAlphaPixels.js +0 -3
- package/lib/image/compute/extendedPoints.js +2 -7
- package/lib/image/compute/histogram.js +6 -25
- package/lib/image/compute/localMaxima.js +2 -10
- package/lib/image/compute/max.js +0 -5
- package/lib/image/compute/mean.js +0 -4
- package/lib/image/compute/median.js +0 -4
- package/lib/image/compute/min.js +0 -5
- package/lib/image/compute/minimalBoundingRectangle.js +5 -18
- package/lib/image/compute/moment.js +0 -3
- package/lib/image/compute/monotoneChainConvexHull.js +0 -3
- package/lib/image/compute/points.js +0 -3
- package/lib/image/compute/relativePosition.js +2 -8
- package/lib/image/compute/sum.js +0 -5
- package/lib/image/core/bitMethods.js +0 -11
- package/lib/image/core/checkProcessable.js +0 -13
- package/lib/image/core/environment.js +0 -8
- package/lib/image/core/export.js +0 -38
- package/lib/image/core/extend.js +0 -13
- package/lib/image/core/getRGBAData.js +0 -15
- package/lib/image/core/kind.js +4 -28
- package/lib/image/core/kindNames.js +1 -0
- package/lib/image/core/load.js +1 -53
- package/lib/image/core/mediaTypes.js +0 -2
- package/lib/image/core/valueMethods.js +0 -13
- package/lib/image/extend.js +7 -83
- package/lib/image/filter/abs.js +0 -3
- package/lib/image/filter/add.js +2 -8
- package/lib/image/filter/background.js +0 -9
- package/lib/image/filter/blurFilter.js +0 -6
- package/lib/image/filter/divide.js +0 -8
- package/lib/image/filter/flipX.js +0 -5
- package/lib/image/filter/flipY.js +0 -4
- package/lib/image/filter/gaussianFilter.js +0 -5
- package/lib/image/filter/gradientFilter.js +0 -10
- package/lib/image/filter/hypotenuse.js +0 -13
- package/lib/image/filter/invert.js +0 -9
- package/lib/image/filter/level.js +1 -19
- package/lib/image/filter/medianFilter.js +0 -15
- package/lib/image/filter/multiply.js +0 -10
- package/lib/image/filter/scharrFilter.js +0 -4
- package/lib/image/filter/sobelFilter.js +0 -4
- package/lib/image/filter/subtract.js +0 -8
- package/lib/image/filter/subtractImage.js +0 -10
- package/lib/image/internal/checks.js +1 -9
- package/lib/image/internal/clamp.js +0 -1
- package/lib/image/internal/copy.js +0 -2
- package/lib/image/internal/copyAlphaChannel.js +0 -1
- package/lib/image/internal/getImageParameters.js +0 -1
- package/lib/image/internal/getOutputImage.js +1 -13
- package/lib/image/model/model.js +1 -1
- package/lib/image/morphology/blackHat.js +0 -5
- package/lib/image/morphology/close.js +0 -5
- package/lib/image/morphology/dilate.js +0 -40
- package/lib/image/morphology/erode.js +0 -40
- package/lib/image/morphology/morphologicalGradient.js +0 -5
- package/lib/image/morphology/open.js +0 -5
- package/lib/image/morphology/topHat.js +0 -5
- package/lib/image/operator/cannyEdge.js +0 -3
- package/lib/image/operator/convolution.js +9 -34
- package/lib/image/operator/convolutionSeparable.js +0 -10
- package/lib/image/operator/extract.js +4 -13
- package/lib/image/operator/floodFill.js +2 -15
- package/lib/image/operator/getSeparatedKernel.js +0 -2
- package/lib/image/operator/paintLabels.js +8 -19
- package/lib/image/operator/paintMasks.js +2 -12
- package/lib/image/operator/paintPoints.js +0 -9
- package/lib/image/operator/paintPolygon.js +1 -15
- package/lib/image/operator/paintPolygons.js +2 -6
- package/lib/image/operator/paintPolyline.js +0 -7
- package/lib/image/operator/paintPolylines.js +1 -5
- package/lib/image/roi/Roi.js +27 -207
- package/lib/image/roi/RoiLayer.js +1 -22
- package/lib/image/roi/RoiMap.js +5 -38
- package/lib/image/roi/creator/fromMask.js +4 -22
- package/lib/image/roi/creator/fromMaskConnectedComponentLabelingAlgorithm.js +2 -20
- package/lib/image/roi/creator/fromMaxima.js +10 -43
- package/lib/image/roi/creator/fromPoints.js +2 -10
- package/lib/image/roi/creator/fromWaterShed.js +6 -17
- package/lib/image/roi/feretDiameters.js +9 -21
- package/lib/image/roi/manager.js +30 -119
- package/lib/image/roi/util/commonBorderLength.js +5 -16
- package/lib/image/roi/util/mergeRoi.js +2 -21
- package/lib/image/transform/cmyk.js +0 -9
- package/lib/image/transform/colorDepth.js +0 -12
- package/lib/image/transform/crop.js +0 -20
- package/lib/image/transform/cropAlpha.js +0 -11
- package/lib/image/transform/grey.js +0 -16
- package/lib/image/transform/greyAlgorithms.js +1 -24
- package/lib/image/transform/hsl.js +0 -16
- package/lib/image/transform/hsv.js +0 -15
- package/lib/image/transform/insert.js +0 -6
- package/lib/image/transform/mask/huang.js +3 -18
- package/lib/image/transform/mask/intermodes.js +3 -14
- package/lib/image/transform/mask/isodata.js +0 -14
- package/lib/image/transform/mask/li.js +12 -42
- package/lib/image/transform/mask/mask.js +1 -13
- package/lib/image/transform/mask/maxEntropy.js +8 -25
- package/lib/image/transform/mask/mean.js +1 -3
- package/lib/image/transform/mask/minError.js +10 -21
- package/lib/image/transform/mask/minimum.js +0 -20
- package/lib/image/transform/mask/moments.js +4 -17
- package/lib/image/transform/mask/otsu.js +1 -7
- package/lib/image/transform/mask/percentile.js +0 -8
- package/lib/image/transform/mask/renyiEntropy.js +8 -34
- package/lib/image/transform/mask/shanbhag.js +8 -25
- package/lib/image/transform/mask/thresholdAlgorithms.js +1 -17
- package/lib/image/transform/mask/triangle.js +13 -29
- package/lib/image/transform/mask/yen.js +2 -14
- package/lib/image/transform/pad.js +0 -20
- package/lib/image/transform/resize/nearestNeighbor.js +0 -6
- package/lib/image/transform/resize/resize.js +0 -16
- package/lib/image/transform/rgba.js +0 -9
- package/lib/image/transform/rgba8.js +0 -3
- package/lib/image/transform/rotate.js +0 -29
- package/lib/image/transform/rotateFree.js +0 -31
- package/lib/image/transform/warping.js +2 -35
- package/lib/image/utility/combineChannels.js +0 -11
- package/lib/image/utility/getBestMatch.js +2 -13
- package/lib/image/utility/getChannel.js +0 -10
- package/lib/image/utility/getClosestCommonParent.js +6 -23
- package/lib/image/utility/getColumn.js +0 -4
- package/lib/image/utility/getIntersection.js +2 -18
- package/lib/image/utility/getMatrix.js +0 -7
- package/lib/image/utility/getPixelsArray.js +0 -5
- package/lib/image/utility/getPixelsGrid.js +0 -11
- package/lib/image/utility/getRow.js +0 -4
- package/lib/image/utility/getSimilarity.js +3 -17
- package/lib/image/utility/getThreshold.js +0 -4
- package/lib/image/utility/setBorder.js +0 -16
- package/lib/image/utility/setChannel.js +0 -6
- package/lib/image/utility/setMatrix.js +0 -6
- package/lib/image/utility/split.js +2 -15
- package/lib/index.js +0 -12
- package/lib/kernel/kernel.js +0 -3
- package/lib/kernel/laplacianOfGaussian.js +1 -7
- package/lib/node_modules/test/binary.js +0 -3
- package/lib/node_modules/test/oneRoi.js +0 -2
- package/lib/stack/Stack.js +2 -35
- package/lib/stack/compute/histogram.js +0 -4
- package/lib/stack/compute/histograms.js +0 -4
- package/lib/stack/compute/max.js +0 -3
- package/lib/stack/compute/median.js +0 -4
- package/lib/stack/compute/min.js +0 -3
- package/lib/stack/extend.js +1 -11
- package/lib/stack/transform/matchAndCrop.js +6 -19
- package/lib/stack/utility/averageImage.js +0 -9
- package/lib/stack/utility/maxImage.js +0 -7
- package/lib/stack/utility/minImage.js +0 -7
- package/lib/util/Shape.js +3 -40
- package/lib/util/base64.js +3 -14
- package/lib/util/channel.js +1 -35
- package/lib/util/color.js +1 -25
- package/lib/util/converter.js +1 -13
- package/lib/util/deepValue.js +0 -3
- package/lib/util/histogram.js +1 -12
- package/lib/util/kernel.js +2 -12
- package/lib/util/matrix.js +0 -13
- package/lib/util/points.js +12 -35
- package/lib/util/value.js +0 -7
- package/lib/util/zerosMatrix.js +0 -3
- package/package.json +2 -2
- package/src/image/operator/paintLabels.js +6 -6
- package/src/image/operator/paintPolygon.js +1 -1
- package/src/image/operator/paintPolygons.js +2 -2
- package/src/image/operator/paintPolylines.js +1 -1
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getBestMatch;
|
|
7
|
-
|
|
8
7
|
var _matrix = _interopRequireDefault(require("../../util/matrix"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Try to match the current pictures with another one
|
|
14
11
|
* @memberof Image
|
|
@@ -24,30 +21,25 @@ function getBestMatch(image, options = {}) {
|
|
|
24
21
|
this.checkProcessable('getChannel', {
|
|
25
22
|
bitDepth: [8, 16]
|
|
26
23
|
});
|
|
27
|
-
|
|
28
24
|
if (this.bitDepth !== image.bitDepth) {
|
|
29
25
|
throw new Error('Both images must have the same bitDepth');
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
if (this.channels !== image.channels) {
|
|
33
28
|
throw new Error('Both images must have the same number of channels');
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
if (this.colorModel !== image.colorModel) {
|
|
37
31
|
throw new Error('Both images must have the same colorModel');
|
|
38
|
-
}
|
|
39
|
-
|
|
32
|
+
}
|
|
40
33
|
|
|
34
|
+
// there could be many names
|
|
41
35
|
let similarityMatrix = new _matrix.default(image.width, image.height, -Infinity);
|
|
42
36
|
let currentX = Math.floor(image.width / 2);
|
|
43
37
|
let currentY = Math.floor(image.height / 2);
|
|
44
38
|
let middleX = currentX;
|
|
45
39
|
let middleY = currentY;
|
|
46
40
|
let theEnd = false;
|
|
47
|
-
|
|
48
41
|
while (!theEnd) {
|
|
49
42
|
let toCalculatePositions = similarityMatrix.localSearch(currentX, currentY, -Infinity);
|
|
50
|
-
|
|
51
43
|
for (let i = 0; i < toCalculatePositions.length; i++) {
|
|
52
44
|
let position = toCalculatePositions[i];
|
|
53
45
|
let similarity = this.getSimilarity(image, {
|
|
@@ -56,9 +48,7 @@ function getBestMatch(image, options = {}) {
|
|
|
56
48
|
});
|
|
57
49
|
similarityMatrix[position[0]][position[1]] = similarity;
|
|
58
50
|
}
|
|
59
|
-
|
|
60
51
|
let max = similarityMatrix.localMax(currentX, currentY);
|
|
61
|
-
|
|
62
52
|
if (max.position[0] !== currentX || max.position[1] !== currentY) {
|
|
63
53
|
currentX = max.position[0];
|
|
64
54
|
currentY = max.position[1];
|
|
@@ -66,6 +56,5 @@ function getBestMatch(image, options = {}) {
|
|
|
66
56
|
theEnd = true;
|
|
67
57
|
}
|
|
68
58
|
}
|
|
69
|
-
|
|
70
59
|
return [currentX - middleX, currentY - middleY];
|
|
71
60
|
}
|
|
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getChannel;
|
|
7
|
-
|
|
8
7
|
var _channel = require("../../util/channel");
|
|
9
|
-
|
|
10
8
|
var _Image = _interopRequireDefault(require("../Image"));
|
|
11
|
-
|
|
12
9
|
var _model = require("../model/model");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
/**
|
|
17
12
|
* Create a grey image based on the selected channel
|
|
18
13
|
* @memberof Image
|
|
@@ -34,26 +29,21 @@ function getChannel(channel, options = {}) {
|
|
|
34
29
|
bitDepth: [8, 16]
|
|
35
30
|
});
|
|
36
31
|
channel = (0, _channel.validateChannel)(this, channel);
|
|
37
|
-
|
|
38
32
|
let newImage = _Image.default.createFrom(this, {
|
|
39
33
|
components: 1,
|
|
40
34
|
alpha: keepAlpha,
|
|
41
35
|
colorModel: _model.GREY
|
|
42
36
|
});
|
|
43
|
-
|
|
44
37
|
let ptr = 0;
|
|
45
|
-
|
|
46
38
|
for (let j = 0; j < this.data.length; j += this.channels) {
|
|
47
39
|
if (mergeAlpha) {
|
|
48
40
|
newImage.data[ptr++] = this.data[j + channel] * this.data[j + this.components] / this.maxValue;
|
|
49
41
|
} else {
|
|
50
42
|
newImage.data[ptr++] = this.data[j + channel];
|
|
51
|
-
|
|
52
43
|
if (keepAlpha) {
|
|
53
44
|
newImage.data[ptr++] = this.data[j + this.components];
|
|
54
45
|
}
|
|
55
46
|
}
|
|
56
47
|
}
|
|
57
|
-
|
|
58
48
|
return newImage;
|
|
59
49
|
}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getClosestCommonParent;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Finds common parent between two different masks
|
|
10
9
|
* @memberof Image
|
|
@@ -16,59 +15,49 @@ function getClosestCommonParent(mask) {
|
|
|
16
15
|
let depthMask1 = getDepth(this);
|
|
17
16
|
let depthMask2 = getDepth(mask);
|
|
18
17
|
let furthestParent;
|
|
19
|
-
|
|
20
18
|
if (depthMask1 >= depthMask2) {
|
|
21
19
|
furthestParent = getFurthestParent(this, depthMask1);
|
|
22
20
|
} else {
|
|
23
21
|
furthestParent = getFurthestParent(mask, depthMask2);
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
if (depthMask1 === 0 || depthMask2 === 0) {
|
|
27
24
|
// comparing with at least one original image -> no common parent
|
|
28
25
|
return furthestParent;
|
|
29
26
|
}
|
|
30
|
-
|
|
31
27
|
let m1 = this;
|
|
32
28
|
let m2 = mask;
|
|
33
|
-
|
|
34
29
|
while (depthMask1 !== depthMask2) {
|
|
35
30
|
if (depthMask1 > depthMask2) {
|
|
36
31
|
m1 = m1.parent;
|
|
37
|
-
|
|
38
32
|
if (m1 === null) {
|
|
39
33
|
return furthestParent;
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
depthMask1 = depthMask1 - 1;
|
|
43
36
|
} else {
|
|
44
37
|
m2 = m2.parent;
|
|
45
|
-
|
|
46
38
|
if (m2 === null) {
|
|
47
39
|
return furthestParent;
|
|
48
40
|
}
|
|
49
|
-
|
|
50
41
|
depthMask2 = depthMask2 - 1;
|
|
51
42
|
}
|
|
52
43
|
}
|
|
53
|
-
|
|
54
44
|
while (m1 !== m2 && m1 !== null && m2 !== null) {
|
|
55
45
|
m1 = m1.parent;
|
|
56
46
|
m2 = m2.parent;
|
|
57
|
-
|
|
58
47
|
if (m1 === null || m2 === null) {
|
|
59
48
|
return furthestParent;
|
|
60
49
|
}
|
|
61
|
-
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// TODO
|
|
62
53
|
// no common parent, use parent at top of hierarchy of m1
|
|
63
54
|
// we assume it works for now
|
|
64
|
-
|
|
65
|
-
|
|
66
55
|
if (m1 !== m2) {
|
|
67
56
|
return furthestParent;
|
|
68
57
|
}
|
|
69
|
-
|
|
70
58
|
return m1;
|
|
71
59
|
}
|
|
60
|
+
|
|
72
61
|
/**
|
|
73
62
|
* Find the depth of the mask with respect to its arborescence.
|
|
74
63
|
* Helper function to find the common parent between two masks.
|
|
@@ -76,27 +65,21 @@ function getClosestCommonParent(mask) {
|
|
|
76
65
|
* @return {number} - depth of mask
|
|
77
66
|
* @private
|
|
78
67
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
68
|
function getDepth(mask) {
|
|
82
69
|
let d = 0;
|
|
83
|
-
let m = mask;
|
|
84
|
-
|
|
70
|
+
let m = mask;
|
|
71
|
+
// a null parent means it's the original image
|
|
85
72
|
while (m.parent != null) {
|
|
86
73
|
m = m.parent;
|
|
87
74
|
d++;
|
|
88
75
|
}
|
|
89
|
-
|
|
90
76
|
return d;
|
|
91
77
|
}
|
|
92
|
-
|
|
93
78
|
function getFurthestParent(mask, depth) {
|
|
94
79
|
let m = mask;
|
|
95
|
-
|
|
96
80
|
while (depth > 0) {
|
|
97
81
|
m = m.parent;
|
|
98
82
|
depth = depth - 1;
|
|
99
83
|
}
|
|
100
|
-
|
|
101
84
|
return m;
|
|
102
85
|
}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getColumn;
|
|
7
|
-
|
|
8
7
|
var _checks = require("../internal/checks");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* @memberof Image
|
|
12
10
|
* @instance
|
|
@@ -23,10 +21,8 @@ function getColumn(column, channel = 0) {
|
|
|
23
21
|
let array = new Array(this.height);
|
|
24
22
|
let ptr = 0;
|
|
25
23
|
let step = this.width * this.channels;
|
|
26
|
-
|
|
27
24
|
for (let j = channel + column * this.channels; j < this.data.length; j += step) {
|
|
28
25
|
array[ptr++] = this.data[j];
|
|
29
26
|
}
|
|
30
|
-
|
|
31
27
|
return array;
|
|
32
28
|
}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getIntersection;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Find intersection of points between two different masks
|
|
10
9
|
* @memberof Image
|
|
@@ -29,49 +28,41 @@ function getIntersection(mask2) {
|
|
|
29
28
|
whitePixelsMask2: [],
|
|
30
29
|
commonWhitePixels: []
|
|
31
30
|
};
|
|
32
|
-
|
|
33
31
|
for (let i = 0; i < commonSurface.length; i++) {
|
|
34
32
|
let currentRelativePos = commonSurface[i];
|
|
35
33
|
let realPos1 = [currentRelativePos[0] - startPos1[0], currentRelativePos[1] - startPos1[1]];
|
|
36
34
|
let realPos2 = [currentRelativePos[0] - startPos2[0], currentRelativePos[1] - startPos2[1]];
|
|
37
35
|
let valueBitMask1 = mask1.getBitXY(realPos1[0], realPos1[1]);
|
|
38
36
|
let valueBitMask2 = mask2.getBitXY(realPos2[0], realPos2[1]);
|
|
39
|
-
|
|
40
37
|
if (valueBitMask1 === 1 && valueBitMask2 === 1) {
|
|
41
38
|
intersection.commonWhitePixels.push(currentRelativePos);
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
|
-
|
|
45
41
|
for (let i = 0; i < allRelPos1.length; i++) {
|
|
46
42
|
let posX;
|
|
47
43
|
let posY;
|
|
48
|
-
|
|
49
44
|
if (i !== 0) {
|
|
50
45
|
posX = Math.floor(i / mask1.width);
|
|
51
46
|
posY = i % mask1.width;
|
|
52
47
|
}
|
|
53
|
-
|
|
54
48
|
if (mask1.getBitXY(posX, posY) === 1) {
|
|
55
49
|
intersection.whitePixelsMask1.push(allRelPos1[i]);
|
|
56
50
|
}
|
|
57
51
|
}
|
|
58
|
-
|
|
59
52
|
for (let i = 0; i < allRelPos2.length; i++) {
|
|
60
53
|
let posX = 0;
|
|
61
54
|
let posY = 0;
|
|
62
|
-
|
|
63
55
|
if (i !== 0) {
|
|
64
56
|
posX = Math.floor(i / mask2.width);
|
|
65
57
|
posY = i % mask2.width;
|
|
66
58
|
}
|
|
67
|
-
|
|
68
59
|
if (mask2.getBitXY(posX, posY) === 1) {
|
|
69
60
|
intersection.whitePixelsMask2.push(allRelPos2[i]);
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
|
-
|
|
73
63
|
return intersection;
|
|
74
64
|
}
|
|
65
|
+
|
|
75
66
|
/**
|
|
76
67
|
* Get relative position array for all pixels in masks
|
|
77
68
|
* @param {Image} mask - a mask (1 bit image)
|
|
@@ -79,20 +70,17 @@ function getIntersection(mask2) {
|
|
|
79
70
|
* @return {Array} - relative position of all pixels
|
|
80
71
|
* @private
|
|
81
72
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
73
|
function getRelativePositionForAllPixels(mask, startPosition) {
|
|
85
74
|
let relativePositions = [];
|
|
86
|
-
|
|
87
75
|
for (let i = 0; i < mask.height; i++) {
|
|
88
76
|
for (let j = 0; j < mask.width; j++) {
|
|
89
77
|
let originalPos = [i, j];
|
|
90
78
|
relativePositions.push([originalPos[0] + startPosition[0], originalPos[1] + startPosition[1]]);
|
|
91
79
|
}
|
|
92
80
|
}
|
|
93
|
-
|
|
94
81
|
return relativePositions;
|
|
95
82
|
}
|
|
83
|
+
|
|
96
84
|
/**
|
|
97
85
|
* Finds common surface for two arrays containing the positions of the pixels relative to parent image
|
|
98
86
|
* @param {Array<number>} positionArray1 - positions of pixels relative to parent
|
|
@@ -100,13 +88,10 @@ function getRelativePositionForAllPixels(mask, startPosition) {
|
|
|
100
88
|
* @return {Array<number>} - positions of common pixels for both arrays
|
|
101
89
|
* @private
|
|
102
90
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
91
|
function getCommonSurface(positionArray1, positionArray2) {
|
|
106
92
|
let i = 0;
|
|
107
93
|
let j = 0;
|
|
108
94
|
let commonSurface = [];
|
|
109
|
-
|
|
110
95
|
while (i < positionArray1.length && j < positionArray2.length) {
|
|
111
96
|
if (positionArray1[i][0] === positionArray2[j][0] && positionArray1[i][1] === positionArray2[j][1]) {
|
|
112
97
|
commonSurface.push(positionArray1[i]);
|
|
@@ -118,6 +103,5 @@ function getCommonSurface(positionArray1, positionArray2) {
|
|
|
118
103
|
j++;
|
|
119
104
|
}
|
|
120
105
|
}
|
|
121
|
-
|
|
122
106
|
return commonSurface;
|
|
123
107
|
}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getMatrix;
|
|
7
|
-
|
|
8
7
|
var _mlMatrix = require("ml-matrix");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* @memberof Image
|
|
12
10
|
* @instance
|
|
@@ -21,22 +19,17 @@ function getMatrix(options = {}) {
|
|
|
21
19
|
this.checkProcessable('getMatrix', {
|
|
22
20
|
bitDepth: [8, 16]
|
|
23
21
|
});
|
|
24
|
-
|
|
25
22
|
if (channel === undefined) {
|
|
26
23
|
if (this.components > 1) {
|
|
27
24
|
throw new RangeError('You need to define the channel for an image that contains more than one channel');
|
|
28
25
|
}
|
|
29
|
-
|
|
30
26
|
channel = 0;
|
|
31
27
|
}
|
|
32
|
-
|
|
33
28
|
let matrix = new _mlMatrix.Matrix(this.height, this.width);
|
|
34
|
-
|
|
35
29
|
for (let x = 0; x < this.height; x++) {
|
|
36
30
|
for (let y = 0; y < this.width; y++) {
|
|
37
31
|
matrix.set(x, y, this.getValueXY(y, x, channel));
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
|
-
|
|
41
34
|
return matrix;
|
|
42
35
|
}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getPixelsArray;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Returns an array of arrays containing the pixel values in the form
|
|
10
9
|
* [[R1, G1, B1], [R2, G2, B2], ...]
|
|
@@ -18,16 +17,12 @@ function getPixelsArray() {
|
|
|
18
17
|
});
|
|
19
18
|
let array = new Array(this.size);
|
|
20
19
|
let ptr = 0;
|
|
21
|
-
|
|
22
20
|
for (let i = 0; i < this.data.length; i += this.channels) {
|
|
23
21
|
let pixel = new Array(this.components);
|
|
24
|
-
|
|
25
22
|
for (let j = 0; j < this.components; j++) {
|
|
26
23
|
pixel[j] = this.data[i + j];
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
array[ptr++] = pixel;
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
return array;
|
|
33
28
|
}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getPixelsGrid;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* @memberof Image
|
|
10
9
|
* @instance
|
|
@@ -24,11 +23,9 @@ function getPixelsGrid(options = {}) {
|
|
|
24
23
|
bitDepth: [8, 16],
|
|
25
24
|
channels: 1
|
|
26
25
|
});
|
|
27
|
-
|
|
28
26
|
if (!Array.isArray(sampling)) {
|
|
29
27
|
sampling = [sampling, sampling];
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
const xSampling = sampling[0];
|
|
33
30
|
const ySampling = sampling[1];
|
|
34
31
|
const xyS = [];
|
|
@@ -36,33 +33,25 @@ function getPixelsGrid(options = {}) {
|
|
|
36
33
|
const xStep = this.width / xSampling;
|
|
37
34
|
const yStep = this.height / ySampling;
|
|
38
35
|
let currentX = Math.floor(xStep / 2);
|
|
39
|
-
|
|
40
36
|
for (let i = 0; i < xSampling; i++) {
|
|
41
37
|
let currentY = Math.floor(yStep / 2);
|
|
42
|
-
|
|
43
38
|
for (let j = 0; j < ySampling; j++) {
|
|
44
39
|
let x = Math.round(currentX);
|
|
45
40
|
let y = Math.round(currentY);
|
|
46
|
-
|
|
47
41
|
if (!mask || mask.getBitXY(x, y)) {
|
|
48
42
|
xyS.push([x, y]);
|
|
49
43
|
zS.push(this.getPixelXY(x, y));
|
|
50
44
|
}
|
|
51
|
-
|
|
52
45
|
currentY += yStep;
|
|
53
46
|
}
|
|
54
|
-
|
|
55
47
|
currentX += xStep;
|
|
56
48
|
}
|
|
57
|
-
|
|
58
49
|
const toReturn = {
|
|
59
50
|
xyS,
|
|
60
51
|
zS
|
|
61
52
|
};
|
|
62
|
-
|
|
63
53
|
if (painted) {
|
|
64
54
|
toReturn.painted = this.rgba8().paintPoints(xyS);
|
|
65
55
|
}
|
|
66
|
-
|
|
67
56
|
return toReturn;
|
|
68
57
|
}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getRow;
|
|
7
|
-
|
|
8
7
|
var _checks = require("../internal/checks");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* @memberof Image
|
|
12
10
|
* @instance
|
|
@@ -24,10 +22,8 @@ function getRow(row, channel = 0) {
|
|
|
24
22
|
let ptr = 0;
|
|
25
23
|
let begin = row * this.width * this.channels + channel;
|
|
26
24
|
let end = begin + this.width * this.channels;
|
|
27
|
-
|
|
28
25
|
for (let j = begin; j < end; j += this.channels) {
|
|
29
26
|
array[ptr++] = this.data[j];
|
|
30
27
|
}
|
|
31
|
-
|
|
32
28
|
return array;
|
|
33
29
|
}
|
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getSimilarity;
|
|
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
|
* Try to match the current pictures with another one. If normalize we normalize separately the 2 images.
|
|
16
12
|
* @memberof Image
|
|
@@ -31,45 +27,37 @@ function getSimilarity(image, options = {}) {
|
|
|
31
27
|
this.checkProcessable('getSimilarity', {
|
|
32
28
|
bitDepth: [8, 16]
|
|
33
29
|
});
|
|
34
|
-
|
|
35
30
|
if (!Array.isArray(border)) {
|
|
36
31
|
border = [border, border];
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
channels = (0, _channel.validateArrayOfChannels)(this, {
|
|
40
34
|
channels: channels,
|
|
41
35
|
defaultAlpha: defaultAlpha
|
|
42
36
|
});
|
|
43
|
-
|
|
44
37
|
if (this.bitDepth !== image.bitDepth) {
|
|
45
38
|
throw new Error('Both images must have the same bitDepth');
|
|
46
39
|
}
|
|
47
|
-
|
|
48
40
|
if (this.channels !== image.channels) {
|
|
49
41
|
throw new Error('Both images must have the same number of channels');
|
|
50
42
|
}
|
|
51
|
-
|
|
52
43
|
if (this.colorModel !== image.colorModel) {
|
|
53
44
|
throw new Error('Both images must have the same colorModel');
|
|
54
45
|
}
|
|
55
|
-
|
|
56
46
|
if (typeof average === 'undefined') {
|
|
57
47
|
average = true;
|
|
58
|
-
}
|
|
59
|
-
// we need to find the minX, maxX, minY, maxY
|
|
60
|
-
|
|
48
|
+
}
|
|
61
49
|
|
|
50
|
+
// we allow a shift
|
|
51
|
+
// we need to find the minX, maxX, minY, maxY
|
|
62
52
|
let minX = Math.max(border[0], -shift[0]);
|
|
63
53
|
let maxX = Math.min(this.width - border[0], this.width - shift[0]);
|
|
64
54
|
let minY = Math.max(border[1], -shift[1]);
|
|
65
55
|
let maxY = Math.min(this.height - border[1], this.height - shift[1]);
|
|
66
56
|
let results = (0, _newArray.default)(channels.length, 0);
|
|
67
|
-
|
|
68
57
|
for (let i = 0; i < channels.length; i++) {
|
|
69
58
|
let c = channels[i];
|
|
70
59
|
let sumThis = normalize ? this.sum[c] : Math.max(this.sum[c], image.sum[c]);
|
|
71
60
|
let sumImage = normalize ? image.sum[c] : Math.max(this.sum[c], image.sum[c]);
|
|
72
|
-
|
|
73
61
|
if (sumThis !== 0 && sumImage !== 0) {
|
|
74
62
|
for (let x = minX; x < maxX; x++) {
|
|
75
63
|
for (let y = minY; y < maxY; y++) {
|
|
@@ -80,10 +68,8 @@ function getSimilarity(image, options = {}) {
|
|
|
80
68
|
}
|
|
81
69
|
}
|
|
82
70
|
}
|
|
83
|
-
|
|
84
71
|
if (average) {
|
|
85
72
|
return results.reduce((sum, x) => sum + x) / results.length;
|
|
86
73
|
}
|
|
87
|
-
|
|
88
74
|
return results;
|
|
89
75
|
}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = getThreshold;
|
|
7
|
-
|
|
8
7
|
var _thresholdAlgorithms = require("../transform/mask/thresholdAlgorithms");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Returns a threshold for the creation of a binary mask with the `mask()` method.
|
|
12
10
|
* @memberof Image
|
|
@@ -23,9 +21,7 @@ function getThreshold(options = {}) {
|
|
|
23
21
|
components: 1,
|
|
24
22
|
bitDepth: [8, 16]
|
|
25
23
|
});
|
|
26
|
-
|
|
27
24
|
let method = _thresholdAlgorithms.methods[algorithm.toLowerCase()];
|
|
28
|
-
|
|
29
25
|
if (method) {
|
|
30
26
|
let histogram = this.getHistogram();
|
|
31
27
|
return method(histogram, this.size);
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = setBorder;
|
|
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
|
* This method will change the border
|
|
14
11
|
* @memberof Image
|
|
@@ -28,12 +25,10 @@ function setBorder(options = {}) {
|
|
|
28
25
|
this.checkProcessable('setBorder', {
|
|
29
26
|
bitDepth: [8, 16, 32, 64]
|
|
30
27
|
});
|
|
31
|
-
|
|
32
28
|
if (algorithm === 'set') {
|
|
33
29
|
if (color.length !== this.channels) {
|
|
34
30
|
throw new Error(`setBorder: the color array must have the same length as the number of channels. Here: ${this.channels}`);
|
|
35
31
|
}
|
|
36
|
-
|
|
37
32
|
for (let i = 0; i < color.length; i++) {
|
|
38
33
|
if (color[i] === 0) {
|
|
39
34
|
color[i] = 0.001;
|
|
@@ -42,46 +37,35 @@ function setBorder(options = {}) {
|
|
|
42
37
|
} else {
|
|
43
38
|
color = (0, _newArray.default)(this.channels, null);
|
|
44
39
|
}
|
|
45
|
-
|
|
46
40
|
if (!Array.isArray(size)) {
|
|
47
41
|
size = [size, size];
|
|
48
42
|
}
|
|
49
|
-
|
|
50
43
|
let leftRightSize = size[0];
|
|
51
44
|
let topBottomSize = size[1];
|
|
52
45
|
let channels = this.channels;
|
|
53
|
-
|
|
54
46
|
for (let i = leftRightSize; i < this.width - leftRightSize; i++) {
|
|
55
47
|
for (let k = 0; k < channels; k++) {
|
|
56
48
|
let value = color[k] || this.data[(i + this.width * topBottomSize) * channels + k];
|
|
57
|
-
|
|
58
49
|
for (let j = 0; j < topBottomSize; j++) {
|
|
59
50
|
this.data[(j * this.width + i) * channels + k] = value;
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
value = color[k] || this.data[(i + this.width * (this.height - topBottomSize - 1)) * channels + k];
|
|
63
|
-
|
|
64
53
|
for (let j = this.height - topBottomSize; j < this.height; j++) {
|
|
65
54
|
this.data[(j * this.width + i) * channels + k] = value;
|
|
66
55
|
}
|
|
67
56
|
}
|
|
68
57
|
}
|
|
69
|
-
|
|
70
58
|
for (let j = 0; j < this.height; j++) {
|
|
71
59
|
for (let k = 0; k < channels; k++) {
|
|
72
60
|
let value = color[k] || this.data[(j * this.width + leftRightSize) * channels + k];
|
|
73
|
-
|
|
74
61
|
for (let i = 0; i < leftRightSize; i++) {
|
|
75
62
|
this.data[(j * this.width + i) * channels + k] = value;
|
|
76
63
|
}
|
|
77
|
-
|
|
78
64
|
value = color[k] || this.data[(j * this.width + this.width - leftRightSize - 1) * channels + k];
|
|
79
|
-
|
|
80
65
|
for (let i = this.width - leftRightSize; i < this.width; i++) {
|
|
81
66
|
this.data[(j * this.width + i) * channels + k] = value;
|
|
82
67
|
}
|
|
83
68
|
}
|
|
84
69
|
}
|
|
85
|
-
|
|
86
70
|
return this;
|
|
87
71
|
}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = setChannel;
|
|
7
|
-
|
|
8
7
|
var _channel = require("../../util/channel");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* @memberof Image
|
|
12
10
|
* @instance
|
|
@@ -24,18 +22,14 @@ function setChannel(channel, image) {
|
|
|
24
22
|
alpha: [0],
|
|
25
23
|
components: [1]
|
|
26
24
|
});
|
|
27
|
-
|
|
28
25
|
if (image.width !== this.width || image.height !== this.height) {
|
|
29
26
|
throw new Error('Images must have exactly the same width and height');
|
|
30
27
|
}
|
|
31
|
-
|
|
32
28
|
channel = (0, _channel.validateChannel)(this, channel);
|
|
33
29
|
let ptr = channel;
|
|
34
|
-
|
|
35
30
|
for (let i = 0; i < image.data.length; i++) {
|
|
36
31
|
this.data[ptr] = image.data[i];
|
|
37
32
|
ptr += this.channels;
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
return this;
|
|
41
35
|
}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = setMatrix;
|
|
7
|
-
|
|
8
7
|
var _mlMatrix = require("ml-matrix");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* We set the data of the image from a matrix. The size of the matrix and the data have to be the same.
|
|
12
10
|
* @memberof Image
|
|
@@ -23,19 +21,15 @@ function setMatrix(matrix, options = {}) {
|
|
|
23
21
|
this.checkProcessable('getMatrix', {
|
|
24
22
|
bitDepth: [8, 16]
|
|
25
23
|
});
|
|
26
|
-
|
|
27
24
|
if (channel === undefined) {
|
|
28
25
|
if (this.components > 1) {
|
|
29
26
|
throw new RangeError('You need to define the channel for an image that contains more than one channel');
|
|
30
27
|
}
|
|
31
|
-
|
|
32
28
|
channel = 0;
|
|
33
29
|
}
|
|
34
|
-
|
|
35
30
|
if (this.width !== matrix.columns || this.height !== matrix.rows) {
|
|
36
31
|
throw new RangeError('The size of the matrix must be equal to the size of the image');
|
|
37
32
|
}
|
|
38
|
-
|
|
39
33
|
for (let x = 0; x < this.height; x++) {
|
|
40
34
|
for (let y = 0; y < this.width; y++) {
|
|
41
35
|
this.setValueXY(y, x, channel, matrix.get(x, y));
|