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

Commit 8052336

Browse files
committed
feat: implement sliceBrief
1 parent 1a8424f commit 8052336

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

scripts/featureMatching/featureMatchingTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { GetColorsOptions } from '../../src/featureMatching/utils/getColors';
1717
import { getMinMax } from '../../src/utils/getMinMax';
1818

1919
import util from 'util';
20-
import { sliceBrief } from './sliceBrief';
20+
import { sliceBrief } from '../../src/featureMatching/descriptors/utils/sliceBrief';
2121
util.inspect.defaultOptions.depth = 5;
2222

2323
const getBriefOptions: GetBriefOptions = {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { ImageColorModel } from '../../../../Image';
2+
import { getOrientedFastKeypoints } from '../../../keypoints/getOrientedFastKeypoints';
3+
import { getBriefDescriptors } from '../../getBriefDescriptors';
4+
import { sliceBrief } from '../sliceBrief';
5+
6+
test('default options', () => {
7+
const image = testUtils
8+
.load(`featureMatching/polygons/polygon.png`)
9+
.convertColor(ImageColorModel.GREY)
10+
.invert();
11+
12+
const keypoints = getOrientedFastKeypoints(image);
13+
14+
const brief = getBriefDescriptors(image, keypoints);
15+
16+
const result = sliceBrief(brief);
17+
18+
expect(result).toStrictEqual(brief);
19+
});
20+
21+
test('slice 0 to 3', () => {
22+
const image = testUtils
23+
.load(`featureMatching/polygons/polygon.png`)
24+
.convertColor(ImageColorModel.GREY)
25+
.invert();
26+
27+
const keypoints = getOrientedFastKeypoints(image);
28+
29+
const brief = getBriefDescriptors(image, keypoints);
30+
31+
const result = sliceBrief(brief, { end: 3 });
32+
33+
expect(result.descriptors.length).toBe(3);
34+
});
35+
36+
test('range error', () => {
37+
const image = testUtils
38+
.load(`featureMatching/polygons/polygon.png`)
39+
.convertColor(ImageColorModel.GREY)
40+
.invert();
41+
42+
const keypoints = getOrientedFastKeypoints(image);
43+
44+
const brief = getBriefDescriptors(image, keypoints);
45+
46+
expect(() => sliceBrief(brief, { start: -1 })).toThrow(
47+
'start or end are out of range',
48+
);
49+
});

scripts/featureMatching/sliceBrief.ts renamed to src/featureMatching/descriptors/utils/sliceBrief.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { option } from 'yargs';
2-
import { Brief } from '../../src/featureMatching';
1+
import { Brief } from '../..';
32

43
export interface SliceBriefOptions {
54
/**
@@ -16,12 +15,19 @@ export interface SliceBriefOptions {
1615
end?: number;
1716
}
1817

18+
/**
19+
* Slice a Brief to keep only the desired keypoints and the corresponding descriptors.
20+
*
21+
* @param brief - Brief to process
22+
* @param options - Slice Brief options.
23+
* @returns The desired keypoints + descriptors.
24+
*/
1925
export function sliceBrief(
2026
brief: Brief,
2127
options: SliceBriefOptions = {},
2228
): Brief {
2329
const { start = 0, end = brief.keypoints.length } = options;
24-
if (start < 0 || end > brief.keypoints.length - 1) {
30+
if (start < 0 || end > brief.keypoints.length) {
2531
throw new Error('start or end are out of range');
2632
}
2733
return {

0 commit comments

Comments
 (0)