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

Commit 28c2ba5

Browse files
authored
fix alignMinDifference options (#394)
* docs: enhance tsDocs * fix: force alignMinDifference images to be gray * docs: correct ts docs
1 parent d06d6a4 commit 28c2ba5

File tree

3 files changed

+15
-24
lines changed

3 files changed

+15
-24
lines changed

src/align/__tests__/alignMinDifference.test.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageColorModel, overlapImages } from '../..';
1+
import { overlapImages } from '../..';
22
import { alignMinDifference } from '../alignMinDifference';
33

44
test('1 pixel source', () => {
@@ -29,9 +29,9 @@ test('4 pixels source', () => {
2929
});
3030

3131
test('twice same image', () => {
32-
const source = testUtils.load('opencv/test.png');
32+
const source = testUtils.load('opencv/test.png').grey();
3333

34-
const destination = testUtils.load('opencv/test.png');
34+
const destination = testUtils.load('opencv/test.png').grey();
3535

3636
const result = alignMinDifference(source, destination);
3737
expect(result).toStrictEqual({ row: 0, column: 0 });
@@ -56,9 +56,7 @@ test('source too big', () => {
5656
test('larger image and crop', () => {
5757
const side = 100;
5858
const origin = { row: 30, column: 30 };
59-
const destination = testUtils
60-
.load('ssim/ssim-original.png')
61-
.convertColor(ImageColorModel.RGB);
59+
const destination = testUtils.load('ssim/ssim-original.png');
6260
const source = destination.crop({ origin, width: side, height: side });
6361

6462
const result = alignMinDifference(source, destination);
@@ -69,9 +67,7 @@ test('larger image and crop', () => {
6967
test('larger image and crop 2', () => {
7068
const side = 100;
7169
const origin = { row: 50, column: 100 };
72-
const destination = testUtils
73-
.load('ssim/ssim-original.png')
74-
.convertColor(ImageColorModel.RGB);
70+
const destination = testUtils.load('ssim/ssim-original.png');
7571
const source = destination.crop({ origin, width: side, height: side });
7672

7773
const result = alignMinDifference(source, destination);
@@ -80,8 +76,8 @@ test('larger image and crop 2', () => {
8076
});
8177

8278
test('id crops', () => {
83-
const destination = testUtils.load('align/cropped.png');
84-
const source = testUtils.load('align/croppedRef.png');
79+
const destination = testUtils.load('align/cropped.png').grey();
80+
const source = testUtils.load('align/croppedRef.png').grey();
8581

8682
const result = alignMinDifference(source, destination);
8783

@@ -91,8 +87,8 @@ test('id crops', () => {
9187
});
9288

9389
test('other id crops', () => {
94-
const destination = testUtils.load('align/cropped1.png');
95-
const source = testUtils.load('align/croppedRef1.png');
90+
const destination = testUtils.load('align/cropped1.png').grey();
91+
const source = testUtils.load('align/croppedRef1.png').grey();
9692
const result = alignMinDifference(source, destination);
9793

9894
const overlap = overlapImages(source, destination, { origin: result });

src/align/alignMinDifference.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Image, ImageColorModel, Point } from '..';
1+
import { Image, Point } from '..';
2+
import checkProcessable from '../utils/validators/checkProcessable';
23

34
export interface AlignMinDifferenceOptions {
45
/**
@@ -9,9 +10,8 @@ export interface AlignMinDifferenceOptions {
910
}
1011

1112
/**
12-
* Aligns two images by finding the translation that minimizes the mean difference
13+
* Aligns two grayscale images by finding the translation that minimizes the mean difference
1314
* between them. The source image should fit entirely in the destination image.
14-
* The images are converted to grayscale internally.
1515
* @param source - Image to align.
1616
* @param destination - Image to align to.
1717
* @param options - Align images min difference options.
@@ -23,6 +23,8 @@ export function alignMinDifference(
2323
destination: Image,
2424
options: AlignMinDifferenceOptions = {},
2525
): Point {
26+
checkProcessable(source, { components: 1, bitDepth: [8, 16], alpha: false });
27+
2628
const xSpan = destination.width - source.width;
2729
const ySpan = destination.height - source.height;
2830
const {
@@ -38,13 +40,6 @@ export function alignMinDifference(
3840
throw new Error('Source image must fit entirely in destination image');
3941
}
4042

41-
if (source.colorModel !== ImageColorModel.GREY) {
42-
source = source.grey();
43-
}
44-
if (destination.colorModel !== ImageColorModel.GREY) {
45-
destination = destination.grey();
46-
}
47-
4843
let bestDifference = Number.POSITIVE_INFINITY;
4944
let bestShiftX = 0;
5045
let bestShiftY = 0;

src/featureMatching/keypoints/getHarrisScore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface GetHarrisScoreOptions {
1212
*/
1313
windowSize?: number;
1414
/**
15-
* Constant for the score computation. Should be between 0.04 and 0.06 (empirical values).
15+
* Constant for the score computation. Should be between 0.04 and 0.06 (empirical values). This consant is commonly called k.
1616
* @default `0.04`
1717
*/
1818
harrisConstant?: number;

0 commit comments

Comments
 (0)