Skip to content

Commit 8f21159

Browse files
committed
Added cannyEdge to MagickImage.
1 parent 9ce8213 commit 8f21159

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/magick-image.ts

+24
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,16 @@ export interface IMagickImage extends IDisposable {
658658
*/
659659
brightnessContrast(brightness: Percentage, contrast: Percentage, channels: Channels): void;
660660

661+
/**
662+
* Uses a multi-stage algorithm to detect a wide range of edges in images.
663+
*/
664+
cannyEdge(): void;
665+
666+
/**
667+
* Uses a multi-stage algorithm to detect a wide range of edges in images.
668+
*/
669+
cannyEdge(radius: number, sigma: number, lower: Percentage, upper: Percentage): void;
670+
661671
/**
662672
* Charcoal effect image (looks like charcoal sketch).
663673
*/
@@ -2642,6 +2652,20 @@ export class MagickImage extends NativeInstance implements IMagickImage {
26422652
});
26432653
}
26442654

2655+
cannyEdge(): void;
2656+
cannyEdge(radius: number, sigma: number, lower: Percentage, upper: Percentage): void;
2657+
cannyEdge(radiusOrUndefined?: number, sigmaOrUndefined?: number, lowerOrUndefined?: Percentage, upperOrUndefined?: Percentage): void {
2658+
const radius = this.valueOrDefault(radiusOrUndefined, 0);
2659+
const sigma = this.valueOrDefault(sigmaOrUndefined, 1);
2660+
const lower = this.valueOrDefault(lowerOrUndefined, new Percentage(10)).toDouble() / 100;
2661+
const upper = this.valueOrDefault(upperOrUndefined, new Percentage(30)).toDouble() / 100;
2662+
2663+
this.useException(exception => {
2664+
const instance = ImageMagick._api._MagickImage_CannyEdge(this._instance, radius, sigma, lower, upper, exception.ptr);
2665+
this._setInstance(instance, exception);
2666+
});
2667+
}
2668+
26452669
charcoal(): void;
26462670
charcoal(radius: number, sigma: number): void;
26472671
charcoal(radiusOrUndefined?: number, sigmaOrUndefined?: number): void {

tests/magick-image/canny-edge.spec.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright Dirk Lemstra https://github.com/dlemstra/magick-wasm.
3+
Licensed under the Apache License, Version 2.0.
4+
*/
5+
6+
import { ErrorMetric } from '@src/enums/error-metric';
7+
import { Percentage } from '@src/types/percentage';
8+
import { TestFiles } from '@test/test-files';
9+
10+
describe('MagickImage#cannyEdge', () => {
11+
it('should change pixels of the image', () => {
12+
TestFiles.Images.Builtin.logo.use(image => {
13+
image.cannyEdge();
14+
15+
expect(image).toHavePixelWithColor(313, 288, '#fff');
16+
expect(image).toHavePixelWithColor(314, 288, '#000');
17+
expect(image).toHavePixelWithColor(466, 224, '#fff');
18+
expect(image).toHavePixelWithColor(467, 224, '#000');
19+
});
20+
});
21+
22+
it('should use the correct default values', () => {
23+
TestFiles.Images.Builtin.logo.use(image => {
24+
image.clone(other => {
25+
image.cannyEdge();
26+
other.cannyEdge(0, 1, new Percentage(10), new Percentage(30));
27+
28+
const difference = other.compare(image, ErrorMetric.RootMeanSquared);
29+
expect(difference).toBe(0);
30+
})
31+
});
32+
});
33+
});

0 commit comments

Comments
 (0)