Skip to content

Canny Edge

Unstable API

0.8.0

@project-lakechain/canny-edge-detector

TypeScript

The Canny edge detector makes it possible to extract the edges of images using the Canny edge algorithm. To do so, it takes images as an input, and produces images with the edges extracted as an output. This can be very useful for a variety of machine-learning applications, including image conditioning in image generation.


Original ImageResult Image
Original ImageResult Image



📏 Edge Extraction

To use this middleware, you import it in your CDK stack and instantiate it as part of a pipeline.

import { CannyEdgeDetector } from '@project-lakechain/canny-edge-detector';
import { CacheStorage } from '@project-lakechain/core';
class Stack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string) {
const cache = new CacheStorage(this, 'Cache');
// Extracts the edges of images.
const detector = new CannyEdgeDetector.Builder()
.withScope(this)
.withIdentifier('CannyEdgeDetector')
.withCacheStorage(cache)
.withSource(source) // 👈 Specify a data source
.build();
}
}


Thresholds

You can customize the lower and upper threshold values of the hysterisis procedure used in the Canny edge detection algorithm.

💁 The default values are 100 for the lower threshold and 200 for the upper thresholds.

import { CannyEdgeDetector } from '@project-lakechain/canny-edge-detector';
const detector = new CannyEdgeDetector.Builder()
.withScope(this)
.withIdentifier('CannyEdgeDetector')
.withCacheStorage(cache)
.withSource(source)
.withLowerThreshold(150)
.withUpperThreshold(250)
.build();


Aperture size

The aperture size represents the size of the Sobel kernel used for edge detection. You can customize it using the withApertureSize API.

💁 The default value is set to 3.

import { CannyEdgeDetector } from '@project-lakechain/canny-edge-detector';
const laplacianProcessor = new CannyEdgeDetector.Builder()
.withScope(this)
.withIdentifier('LaplacianProcessor')
.withCacheStorage(cache)
.withSource(source)
.withApertureSize(5)
.build();


L2 Gradient

The L2 gradient is a boolean value that specifies whether to use the equation for finding gradient magnitude. You can customize it using the withL2Gradient API.

💁 The default value is set to false.

import { CannyEdgeDetector } from '@project-lakechain/canny-edge-detector';
const detector = new CannyEdgeDetector.Builder()
.withScope(this)
.withIdentifier('CannyEdgeDetector')
.withCacheStorage(cache)
.withSource(source)
.withL2Gradient(true)
.build();


🏗️ Architecture

This middleware runs within a Lambda compute, and packages OpenCV to perform the Canny edge detection.

Architecture



🏷️ Properties


Supported Inputs
Mime TypeDescription
image/jpegJPEG image
image/pngPNG image
image/bmpBMP image
image/webpWebP image
Supported Outputs
Mime TypeDescription
image/pngPNG image
Supported Compute Types
TypeDescription
CPUThis middleware only supports CPU compute.


📖 Examples