Skip to content

Commit d6f3505

Browse files
committed
test(align): enhance tests
1 parent 460b0b8 commit d6f3505

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/align/__tests__/align.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { overlapImages } from '../../featureMatching';
12
import { align } from '../align';
23

34
test('1 pixel source', () => {
@@ -15,3 +16,60 @@ test('1 pixel source', () => {
1516
const result = align(source, destination);
1617
expect(result).toStrictEqual({ row: 2, column: 1 });
1718
});
19+
test('4 pixels source', () => {
20+
const source = testUtils.createGreyImage([
21+
[0, 80],
22+
[150, 200],
23+
]);
24+
const destination = testUtils.createGreyImage([
25+
[0, 0, 0],
26+
[0, 0, 100],
27+
[0, 255, 255],
28+
]);
29+
30+
const result = align(source, destination, { blurKernelSize: 1 });
31+
expect(result).toStrictEqual({
32+
row: 1,
33+
column: 1,
34+
});
35+
});
36+
37+
test('twice same image', () => {
38+
const source = testUtils.load('opencv/test.png').grey();
39+
40+
const destination = testUtils.load('opencv/test.png').grey();
41+
42+
const result = align(source, destination);
43+
expect(result).toStrictEqual({ row: 0, column: 0 });
44+
});
45+
46+
test('larger image and crop', () => {
47+
const side = 100;
48+
const origin = { row: 30, column: 30 };
49+
const destination = testUtils.load('ssim/ssim-original.png');
50+
const source = destination.crop({ origin, width: side, height: side });
51+
52+
const result = align(source, destination);
53+
54+
expect(result).toStrictEqual(origin);
55+
});
56+
57+
test('id crops', () => {
58+
const destination = testUtils.load('align/cropped.png').grey();
59+
const source = testUtils.load('align/croppedRef.png').grey();
60+
61+
const result = align(source, destination);
62+
63+
const overlap = overlapImages(source, destination, { origin: result });
64+
65+
expect(overlap).toMatchImageSnapshot();
66+
});
67+
68+
test('other id crops', () => {
69+
const destination = testUtils.load('align/cropped1.png').grey();
70+
const source = testUtils.load('align/croppedRef1.png').grey();
71+
const result = align(source, destination, { level: 'uniform' });
72+
73+
const overlap = overlapImages(source, destination, { origin: result });
74+
expect(overlap).toMatchImageSnapshot();
75+
});

0 commit comments

Comments
 (0)