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

Commit ed84ed2

Browse files
authored
align (#395)
* chore: add private in .gitignore * feat: add autoLevel on Image instance * feat: optional mask in alignMinDifference
1 parent 28c2ba5 commit ed84ed2

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,6 @@ src/**/*.png
130130

131131
# ignore images in test scripts folder
132132
scripts/**/**.png
133-
scripts/**/**.json
133+
scripts/**/**.json
134+
135+
private

src/Image.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import {
4343
InvertOptions,
4444
level,
4545
LevelOptions,
46+
autoLevel,
47+
AutoLevelOptions,
4648
pixelate,
4749
PixelateOptions,
4850
medianFilter,
@@ -935,6 +937,15 @@ export class Image {
935937
return level(this, options);
936938
}
937939

940+
/**
941+
* Enhance the contrast of an image by spanning each channel on the range [0, image.maxValue].
942+
* @param options - Enhance contrast options.
943+
* @returns The enhanced image.
944+
*/
945+
public autoLevel(options: AutoLevelOptions = {}): Image {
946+
return autoLevel(this, options);
947+
}
948+
938949
/**
939950
* Correct the colors in an image using the reference colors.
940951
* @param measuredColors - Colors from the image, which will be compared to the reference.

src/align/alignMinDifference.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Image, Point } from '..';
1+
import { Image, Mask, Point } from '..';
22
import checkProcessable from '../utils/validators/checkProcessable';
33

44
export interface AlignMinDifferenceOptions {
@@ -7,6 +7,7 @@ export interface AlignMinDifferenceOptions {
77
* @default `Math.max(Math.round(Math.min(source.width, source.height, Math.max(xSpan, ySpan)) / 10,),1,)`
88
*/
99
startStep?: number;
10+
mask?: Mask;
1011
}
1112

1213
/**
@@ -34,6 +35,7 @@ export function alignMinDifference(
3435
),
3536
1,
3637
),
38+
mask,
3739
} = options;
3840

3941
if (xSpan < 0 || ySpan < 0) {
@@ -57,6 +59,9 @@ export function alignMinDifference(
5759
let currentDifference = 0;
5860
next: for (let column = 0; column < source.width; column++) {
5961
for (let row = 0; row < source.height; row++) {
62+
if (mask && !mask.getBit(column, row)) {
63+
continue;
64+
}
6065
const sourceValue = source.getValue(column, row, 0);
6166
const destinationValue = destination.getValue(
6267
column + shiftX,

0 commit comments

Comments
 (0)