Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit 347c36b

Browse files
committed
test(getPatchIntensityCentroid): enhance tests
1 parent a938fdf commit 347c36b

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed
Loading
Loading

src/featureMatching/keypoints/__tests__/getPatchIntensityCentroid.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ test('check window is circular', () => {
5454
expect(result).toStrictEqual([{ column: 1, row: 0 }]);
5555
});
5656

57+
test('triangle center of mass', () => {
58+
const image = testUtils.createGreyImage([
59+
[0, 0, 0, 1, 0],
60+
[0, 0, 1, 1, 0],
61+
[0, 1, 1, 1, 0],
62+
[0, 0, 1, 1, 0],
63+
[0, 0, 0, 1, 0],
64+
]);
65+
const result = getPatchIntensityCentroid(image, { radius: 2 });
66+
expect(result).toBeDeepCloseTo([{ column: 0.444, row: 0 }]);
67+
});
68+
5769
test('patch, default options', () => {
5870
const image = testUtils.load('featureMatching/patch.png');
5971
image.invert({ out: image });
@@ -74,3 +86,75 @@ test('patch, default options', () => {
7486

7587
expect(result).toMatchImageSnapshot();
7688
});
89+
90+
test('better triangle keypoint', () => {
91+
const origin = { row: 332, column: 253 };
92+
const size = 7;
93+
const radius = (size - 1) / 2;
94+
95+
const cropOrigin = {
96+
row: origin.row - radius,
97+
column: origin.column - radius,
98+
};
99+
100+
const origialImage = testUtils
101+
.load('featureMatching/polygons/betterScaleneTriangle.png')
102+
.convertColor(ImageColorModel.GREY)
103+
.invert();
104+
105+
const image = origialImage.crop({
106+
origin: cropOrigin,
107+
width: size,
108+
height: size,
109+
});
110+
111+
const centroid = getPatchIntensityCentroid(image, { radius })[0];
112+
expect(centroid).toBeDeepCloseTo({ column: 1.281, row: 0.204 });
113+
114+
const center = image.getCoordinates(ImageCoordinates.CENTER);
115+
116+
const point = round(sum(center, centroid));
117+
118+
const result = image.convertColor(ImageColorModel.RGB);
119+
result.drawCircle(center, radius + 1, { color: [255, 0, 0], out: result });
120+
121+
result.drawPoints([point], { color: [0, 255, 0], out: result });
122+
123+
expect(result).toMatchImageSnapshot();
124+
});
125+
126+
test('better triangle 90 keypoint', () => {
127+
const origin = { row: 730, column: 291 };
128+
const size = 7;
129+
const radius = (size - 1) / 2;
130+
131+
const cropOrigin = {
132+
row: origin.row - radius,
133+
column: origin.column - radius,
134+
};
135+
136+
const origialImage = testUtils
137+
.load('featureMatching/polygons/betterScaleneTriangle90.png')
138+
.convertColor(ImageColorModel.GREY)
139+
.invert();
140+
141+
const image = origialImage.crop({
142+
origin: cropOrigin,
143+
width: size,
144+
height: size,
145+
});
146+
147+
const centroid = getPatchIntensityCentroid(image, { radius })[0];
148+
expect(centroid).toBeDeepCloseTo({ column: 0.634, row: -1.074 });
149+
150+
const center = image.getCoordinates(ImageCoordinates.CENTER);
151+
152+
const point = round(sum(center, centroid));
153+
154+
const result = image.convertColor(ImageColorModel.RGB);
155+
result.drawCircle(center, radius + 1, { color: [255, 0, 0], out: result });
156+
157+
result.drawPoints([point], { color: [0, 255, 0], out: result });
158+
159+
expect(result).toMatchImageSnapshot();
160+
});

0 commit comments

Comments
 (0)