
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
fast-sobel-tfjs
Advanced tools
GPU-accelerated Sobel edge detection for TensorFlow.js - 5-10x faster than CPU implementations
GPU-accelerated Sobel edge detection for images & video, powered by TensorFlow.js
Blazing fast edge detection that runs on GPU via WebGL, with fallback to CPU. Perfect for real-time image processing, computer vision applications, and creative coding projects.
Our live demo showcases all the capabilities of Fast Sobel TFJS:
Benchmark Results: See 5-10x performance improvements with GPU acceleration compared to CPU-only implementations.
npm install fast-sobel-tfjs @tensorflow/tfjs
Peer Dependencies:
@tensorflow/tfjs: >=4.0.0The library uses TensorFlow.js as a peer dependency to avoid bundle duplication and allow you to choose your preferred TF.js variant (CPU, WebGL, Node, etc.).
import { detectEdges } from "fast-sobel-tfjs";
// From image element
const img = document.getElementById("myImage");
const edges = await detectEdges(img);
// From canvas ImageData
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const edgeData = await detectEdges(imageData);
import { SobelFilter } from "fast-sobel-tfjs";
const filter = new SobelFilter({
kernelSize: 5, // 3, 5, or 7
output: "gradient", // 'magnitude', 'gradient', 'normalized'
normalizationRange: [0, 255],
grayscale: true,
threshold: 0.1,
});
// Process image
const result = await filter.processImage(imageElement);
// Or work with tensors directly
const tensor = tf.browser.fromPixels(imageElement);
const edges = filter.applyToTensor(tensor);
import { SobelFilter } from "fast-sobel-tfjs";
const video = document.getElementById("myVideo");
const canvas = document.getElementById("output");
const ctx = canvas.getContext("2d");
const filter = new SobelFilter({
kernelSize: 3,
output: "normalized",
grayscale: true,
});
async function processFrame() {
if (video.readyState === video.HAVE_ENOUGH_DATA) {
const edges = await filter.processHTMLVideoElement(video);
ctx.putImageData(edges, 0, 0);
}
requestAnimationFrame(processFrame);
}
processFrame();
detectEdges(input, useGrayscale?)Quick edge detection with optimal settings.
Parameters:
input: ImageData | HTMLImageElement | HTMLVideoElement | tf.Tensor3DuseGrayscale: boolean (default: true)Returns: Promise<ImageData | tf.Tensor3D>
SobelFilterMain class for edge detection with full customization.
interface SobelOptions {
kernelSize?: 3 | 5 | 7; // Default: 3
output?: "magnitude" | "gradient" | "normalized"; // Default: 'magnitude'
normalizationRange?: [number, number]; // Default: [0, 1]
grayscale?: boolean; // Default: true
threshold?: number; // Default: 0
}
processImage(image)Process HTML image element.
HTMLImageElementPromise<ImageData>processImageData(imageData)Process canvas ImageData.
ImageDataPromise<ImageData>processHTMLVideoElement(video)Process video element frame.
HTMLVideoElementPromise<ImageData>applyToTensor(tensor)Process tensor directly (advanced usage).
tf.Tensor3Dtf.Tensor3D'magnitude': Grayscale edge strength'gradient': RGB gradient components (Gx, Gy, magnitude)'normalized': Normalized to specified rangeimport {
getAvailableKernelSizes,
getAvailableOutputFormats,
isValidKernelSize,
isValidOutputFormat,
} from "@marduk-labs/fast-sobel-tfjs";
// Artistic edge overlay
const filter = new SobelFilter({
kernelSize: 7,
output: "gradient",
threshold: 0.2,
});
const edges = await filter.processImage(img);
// Blend with original image for artistic effect
// High precision for medical imaging
const filter = new SobelFilter({
kernelSize: 5,
output: "magnitude",
normalizationRange: [0, 4095], // 12-bit medical images
grayscale: true,
});
navigator.mediaDevices.getUserMedia({ video: true }).then((stream) => {
const video = document.createElement("video");
video.srcObject = stream;
video.play();
const filter = new SobelFilter({ kernelSize: 3 });
function processWebcam() {
filter.processHTMLVideoElement(video).then((edges) => {
// Display processed frame
ctx.putImageData(edges, 0, 0);
requestAnimationFrame(processWebcam);
});
}
video.addEventListener("loadedmetadata", processWebcam);
});
'magnitude': Best for edge detection and thresholding'gradient': Best for directional analysis'normalized': Best for display and further processing// Good: Automatic cleanup
const edges = await detectEdges(image);
// Advanced: Manual tensor management
tf.tidy(() => {
const tensor = tf.browser.fromPixels(image);
const edges = filter.applyToTensor(tensor);
// Tensors automatically disposed at end of tidy
});
Requirements:
| Image Size | GPU Time | CPU Time | Speedup |
|---|---|---|---|
| 640x480 | 2.1ms | 12.8ms | 6.1x |
| 1280x720 | 4.3ms | 31.2ms | 7.3x |
| 1920x1080 | 8.1ms | 67.4ms | 8.3x |
Benchmarks run on Chrome 120, RTX 3080, i7-12700K
npm run build
npm test
# React example
npm run start:react
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our GitHub repository.
git clone https://github.com/Marduk-Labs/fast-sobel-tfjs.git
cd fast-sobel-tfjs
npm install
npm run build
MIT License - see LICENSE for details.
Fast Sobel TFJS - GPU-accelerated edge detection for the modern web
Made with ❤️ by Marduk Labs
FAQs
GPU-accelerated Sobel edge detection for TensorFlow.js - 5-10x faster than CPU implementations
The npm package fast-sobel-tfjs receives a total of 1 weekly downloads. As such, fast-sobel-tfjs popularity was classified as not popular.
We found that fast-sobel-tfjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.