A collection of image edge detection filters built with PyTorch — fully vectorized, GPU-compatible, and easy to drop into any pytorch pipeline.
- Canny — classic multi-stage edge detector with Gaussian blur, Sobel gradients, non-maximum suppression, and hysteresis
- DoG (Difference of Gaussians) — fast approximation of the Laplacian of Gaussian for edge detection
- XDoG (Extended Difference of Gaussians) — stylized edge detection with soft thresholding, great for non-photorealistic rendering
pip install pytorch-filtersimport torch
import torchvision.transforms.functional as TF
from PIL import Image
from pytorch_filters import canny, difference_of_gaussians, ex_difference_of_gaussians
# Load image as tensor [1, 1, H, W]
img = TF.to_tensor(Image.open("photo.jpg").convert("L")).unsqueeze(0)
edges = canny(img)
dog = difference_of_gaussians(img, sigma=1.4, k=1.6)
xdog = ex_difference_of_gaussians(img, sigma=1.0, tau=0.99, phi=100)pip install -r requirements.txt
python demo.py images/demo1.jpgThis will display the original image alongside Canny, DoG, and XDoG results side by side.
- Python 3.10+
- PyTorch 2.0+
- torchvision
- NumPy
