fast-sobel-tfjs
Version:
GPU-accelerated Sobel edge detection for TensorFlow.js - 5-10x faster than CPU implementations
32 lines (31 loc) • 1.21 kB
TypeScript
import * as tf from '@tensorflow/tfjs';
import { KernelSize } from '../types';
/**
* Creates a Sobel kernel tensor for the specified direction and number of channels
*
* @param direction 'x' or 'y' for horizontal or vertical gradient
* @param kernelSize Size of the kernel (3, 5, or 7)
* @param channels Number of input channels
* @returns Tensor4D representing the kernel
*/
export declare function createSobelKernel(direction: 'x' | 'y', kernelSize: KernelSize, channels: number): tf.Tensor4D;
/**
* Normalizes a tensor to a specific range for display or output
*
* @param tensor Input tensor to normalize
* @param min Minimum value of the target range
* @param max Maximum value of the target range
* @returns Normalized tensor
*/
export declare function normalizeTensor(tensor: tf.Tensor, min?: number, max?: number): tf.Tensor;
/**
* Converts an RGB tensor to grayscale if needed
*
* @param input Input tensor
* @param grayscale Whether to convert to grayscale
* @returns Processed tensor and indicator if a new tensor was created
*/
export declare function ensureGrayscaleIfNeeded(input: tf.Tensor3D, grayscale: boolean): {
tensor: tf.Tensor3D;
newTensorCreated: boolean;
};