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

Commit 9773fe7

Browse files
committed
test(patchIntensityCentroid): found a bug in this function
1 parent 9e09e6b commit 9773fe7

9 files changed

+99
-4
lines changed

src/Image.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ export class Image {
333333
const start = (row * this.width + column) * this.channels;
334334
for (let i = 0; i < this.channels; i++) {
335335
this.data[start + i] = value[i];
336+
console.log(this.data[start + i], value[i]);
336337
}
337338
}
338339

@@ -345,6 +346,7 @@ export class Image {
345346
*/
346347
public setVisiblePixel(column: number, row: number, value: number[]): void {
347348
if (column >= 0 && column < this.width && row >= 0 && row < this.height) {
349+
console.log(value);
348350
this.setPixel(column, row, value);
349351
}
350352
}
Loading
Loading
Loading

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ImageColorModel } from '../../../Image';
2+
import { drawKeypoints } from '../../visualize/drawKeypoints';
23
import { getOrientedFastKeypoints } from '../getOrientedFastKeypoints';
34

45
test('7x7 image, angle = 90°', () => {
@@ -148,3 +149,60 @@ test('check angle for different windowSize', () => {
148149
1,
149150
);
150151
});
152+
153+
test('angle diff should be 90°', () => {
154+
const windowSize = 15;
155+
const markerSize = 15;
156+
157+
const image = testUtils
158+
.load('featureMatching/polygons/betterScaleneTriangle.png')
159+
.convertColor(ImageColorModel.GREY);
160+
161+
const rotated = testUtils
162+
.load('featureMatching/polygons/betterScaleneTriangle90.png')
163+
.convertColor(ImageColorModel.GREY);
164+
165+
const keypoints = getOrientedFastKeypoints(image, { windowSize });
166+
const keypointsRotated = getOrientedFastKeypoints(rotated, { windowSize });
167+
console.log(keypoints, keypointsRotated);
168+
169+
expect(
170+
drawKeypoints(image, keypoints, { markerSize, showOrientation: true }),
171+
).toMatchImageSnapshot();
172+
expect(
173+
drawKeypoints(rotated, keypointsRotated, {
174+
markerSize,
175+
showOrientation: true,
176+
}),
177+
).toMatchImageSnapshot();
178+
179+
expect([keypoints, keypointsRotated]).toBeDeepCloseTo(
180+
[
181+
[
182+
{
183+
origin: { row: 607, column: 132 },
184+
score: 2680,
185+
angle: 145.3,
186+
},
187+
{
188+
origin: { row: 50, column: 292 },
189+
score: 2662,
190+
angle: -112.2,
191+
},
192+
],
193+
[
194+
{
195+
origin: { row: 607, column: 132 },
196+
score: 2680,
197+
angle: 123.7,
198+
},
199+
{
200+
origin: { row: 50, column: 292 },
201+
score: 2662,
202+
angle: -95.4,
203+
},
204+
],
205+
],
206+
1,
207+
);
208+
});
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
1-
import { ImageColorModel, Image } from '../../../Image';
1+
import { ImageColorModel, Image, ImageCoordinates } from '../../../Image';
2+
import { round, sum } from '../../../utils/geometry/points';
23
import { getPatchIntensityCentroid } from '../getPatchIntensityCentroid';
34

45
test('3x3 empty image', () => {
56
const image = new Image(7, 7, { colorModel: ImageColorModel.GREY });
67
const result = getPatchIntensityCentroid(image);
78
expect(result).toStrictEqual([{ column: 0, row: 0 }]);
89
});
10+
11+
test.only('patch, default options', () => {
12+
const image = testUtils.load('featureMatching/patch.png');
13+
console.log(image.colorModel);
14+
15+
const centroid = round(getPatchIntensityCentroid(image)[0]);
16+
console.log(centroid);
17+
18+
const center = image.getCoordinates(ImageCoordinates.CENTER);
19+
20+
const point = sum(center, centroid);
21+
console.log(point);
22+
23+
const result = image.convertColor(ImageColorModel.RGB);
24+
for (let i = 14; i < 15; i++) {
25+
result.drawPoints([{ row: i, column: i }], {
26+
color: [0, 255, 0],
27+
out: result,
28+
});
29+
}
30+
31+
expect(result).toMatchImageSnapshot();
32+
});

src/utils/geometry/points.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface Point {
2626
* @param p2 - Second Point.
2727
* @returns Difference between the two points.
2828
*/
29-
export function difference(p1: Point, p2: Point) {
29+
export function difference(p1: Point, p2: Point): Point {
3030
return { column: p1.column - p2.column, row: p1.row - p2.row };
3131
}
3232

@@ -37,7 +37,7 @@ export function difference(p1: Point, p2: Point) {
3737
* @param p2 - Second Point.
3838
* @returns Sum of the two points.
3939
*/
40-
export function sum(p1: Point, p2: Point) {
40+
export function sum(p1: Point, p2: Point): Point {
4141
return { column: p1.column + p2.column, row: p1.row + p2.row };
4242
}
4343

@@ -47,7 +47,7 @@ export function sum(p1: Point, p2: Point) {
4747
* @param point - Point to normalize.
4848
* @returns - Normalized point.
4949
*/
50-
export function normalize(point: Point) {
50+
export function normalize(point: Point): Point {
5151
let length = Math.sqrt(point.column ** 2 + point.row ** 2);
5252
return { column: point.column / length, row: point.row / length };
5353
}
@@ -83,3 +83,13 @@ export function rotate(radians: number, points: readonly Point[]): Point[] {
8383
export function dot(p1: Point, p2: Point) {
8484
return p1.column * p2.column + p1.row * p2.row;
8585
}
86+
87+
/**
88+
* Round the coordinates of the point.
89+
*
90+
* @param point - The point.
91+
* @returns Rounded coordinates of the point.
92+
*/
93+
export function round(point: Point): Point {
94+
return { column: Math.round(point.column), row: Math.round(point.row) };
95+
}

test/TestImagePath.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export type TestImagePath =
6060
| 'featureMatching/crop1.png'
6161
| 'featureMatching/crop2.png'
6262
| 'featureMatching/crop3.png'
63+
| 'featureMatching/patch.png'
6364
| 'featureMatching/polygons/star.png'
6465
| 'featureMatching/polygons/betterScaleneTriangle.png'
6566
| 'featureMatching/polygons/betterScaleneTriangle90.png'

test/img/featureMatching/patch.png

176 Bytes
Loading

0 commit comments

Comments
 (0)