fast-sobel-tfjs
Version:
GPU-accelerated Sobel edge detection for TensorFlow.js - 5-10x faster than CPU implementations
35 lines (34 loc) • 1.38 kB
TypeScript
import * as tf from '@tensorflow/tfjs';
/**
* Converts a tensor to an ImageData object
*
* @param tensor Input tensor (should be [height, width, channels])
* @param normalize Whether to normalize the values to 0-255 range
* @returns ImageData object
*/
export declare function tensorToImageData(tensor: tf.Tensor3D, normalize?: boolean): Promise<ImageData>;
/**
* Creates a canvas element from an ImageData object
*
* @param imageData ImageData to put on canvas
* @returns Canvas element
*/
export declare function imageDataToCanvas(imageData: ImageData): HTMLCanvasElement;
/**
* Converts a pixel array to a tensor
*
* @param pixels Pixel data
* @param width Image width
* @param height Image height
* @param channels Number of channels (1, 3, or 4)
* @returns 3D tensor of shape [height, width, channels]
*/
export declare function pixelArrayToTensor(pixels: Uint8ClampedArray | Uint8Array | Float32Array, width: number, height: number, channels?: number): tf.Tensor3D;
/**
* Processes an HTML Image element and returns a canvas with the filtered result
*
* @param image HTML Image element
* @param processFunction Function to process the ImageData
* @returns Canvas element with processed image
*/
export declare function processHTMLImage(image: HTMLImageElement, processFunction: (imageData: ImageData) => Promise<ImageData>): Promise<HTMLCanvasElement>;