Skip to content

Commit 314e2b8

Browse files
committed
Added adaptiveThreshold to MagickImage.
1 parent 92e044b commit 314e2b8

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

src/magick-image.ts

+54
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,44 @@ export interface IMagickImage extends IDisposable {
411411
*/
412412
adaptiveSharpen(radius: number, sigma: number, channels: Channels): void;
413413

414+
/**
415+
* Local adaptive threshold image.
416+
* http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
417+
* @param width The width of the pixel neighborhood.
418+
* @param height The height of the pixel neighborhood.
419+
*/
420+
adaptiveThreshold(width: number, height: number): void;
421+
422+
/**
423+
* Local adaptive threshold image.
424+
* http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
425+
* @param width The width of the pixel neighborhood.
426+
* @param height The height of the pixel neighborhood.
427+
* @param channels The channel(s) to threshold.
428+
*/
429+
adaptiveThreshold(width: number, height: number, channels: Channels): void;
430+
431+
/**
432+
* Local adaptive threshold image.
433+
* http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
434+
* @param width The width of the pixel neighborhood.
435+
* @param height The height of the pixel neighborhood.
436+
* @param channels The channel(s) to threshold.
437+
* @param bias Constant to subtract from pixel neighborhood mean (+/-)(0-QuantumRange).
438+
*/
439+
adaptiveThreshold(width: number, height: number, bias: Percentage,): void;
440+
441+
/**
442+
* Local adaptive threshold image.
443+
* http://www.dai.ed.ac.uk/HIPR2/adpthrsh.htm.
444+
* @param width The width of the pixel neighborhood.
445+
* @param height The height of the pixel neighborhood.
446+
* @param channels The channel(s) to threshold.
447+
* @param bias Constant to subtract from pixel neighborhood mean (+/-)(0-QuantumRange).
448+
* @param channels The channel(s) to threshold.
449+
*/
450+
adaptiveThreshold(width: number, height: number, bias: Percentage, channels: Channels): void;
451+
414452
/**
415453
* Add noise to image with the specified noise type.
416454
* @param noiseType The type of noise that should be added to the image.
@@ -2409,6 +2447,22 @@ export class MagickImage extends NativeInstance implements IMagickImage {
24092447
});
24102448
}
24112449

2450+
adaptiveThreshold(width: number, height: number): void;
2451+
adaptiveThreshold(width: number, height: number, channels: Channels): void;
2452+
adaptiveThreshold(width: number, height: number, bias: Percentage,): void;
2453+
adaptiveThreshold(width: number, height: number, bias: Percentage, channels: Channels): void;
2454+
adaptiveThreshold(width: number, height: number, biasChannelsOrUndefined?: Percentage | Channels, channelsOrUndefined?: Channels): void {
2455+
const bias = biasChannelsOrUndefined instanceof Percentage ? biasChannelsOrUndefined._toQuantum() : 0.0;
2456+
let channels = channelsOrUndefined ?? Channels.Undefined;
2457+
if (typeof biasChannelsOrUndefined === 'number')
2458+
channels = biasChannelsOrUndefined;
2459+
2460+
this.useException(exception => {
2461+
const instance = ImageMagick._api._MagickImage_AdaptiveThreshold(this._instance, width, height, bias, channels, exception.ptr);
2462+
this._setInstance(instance, exception);
2463+
});
2464+
}
2465+
24122466
addNoise(noiseType: NoiseType): void;
24132467
addNoise(noiseType: NoiseType, channels: Channels): void;
24142468
addNoise(noiseType: NoiseType, attenuate: number): void;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
3+
Licensed under the Apache License, Version 2.0.
4+
*/
5+
6+
import { Channels } from '@src/enums/channels';
7+
import { Percentage } from '@src/types/percentage';
8+
import { TestFiles } from '@test/test-files';
9+
10+
describe('MagickImage#adaptiveSharpen', () => {
11+
it('should threshold the image', () => {
12+
TestFiles.Images.fujiFilmFinePixS1ProJpg.use(image => {
13+
image.adaptiveThreshold(100, 100);
14+
15+
TestFiles.Images.fujiFilmFinePixS1ProJpg.use(original => {
16+
expect(image).toEqualImage(original, 0.45749);
17+
});
18+
});
19+
});
20+
21+
it('should use the bias percentage', () => {
22+
TestFiles.Images.fujiFilmFinePixS1ProJpg.use(image => {
23+
image.adaptiveThreshold(100, 100, new Percentage(50));
24+
25+
TestFiles.Images.fujiFilmFinePixS1ProJpg.use(original => {
26+
expect(image).toEqualImage(original, 0.42296);
27+
});
28+
});
29+
});
30+
31+
it('should use the specified channels', () => {
32+
TestFiles.Images.fujiFilmFinePixS1ProJpg.use(image => {
33+
image.adaptiveThreshold(100, 100, new Percentage(50), Channels.Green);
34+
35+
TestFiles.Images.fujiFilmFinePixS1ProJpg.use(original => {
36+
expect(image).toEqualImage(original, 0.23814);
37+
});
38+
});
39+
});
40+
});

0 commit comments

Comments
 (0)