Skip to main content

A simple Canny edge detector for pytorch

Project description

Canny Edges

img1_in img2_in img3_in
img1_out img2_out img3_out

A simple Torch.nn.Module to return an image mask representing edges found by the Canny Edge-Finding algorithm.


Usage

Supports:

  • Linux only
  • PyTorch Tensor images formatted in image batches [B, C, h, w], with float32 data, and values spanning [0,1]
  • Any number of channels C
  • TorchScript jit script, as well as the newer, traced torch-export, on the Canny nn.Module class

pip install

pip install canny-chenn
# or,
pixi add --pypi canny_chenn

then

from torch import Tensor
from canny_chenn import Canny
canny = Canny()
img_batch = Tensor([[[[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]],
            [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]],
            [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]],
            [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]]])
edge_mask = canny(img_batch)
# tensor([[[[0.0000, 0.6333, 0.0000, 0.0000],
#           [0.0000, 0.6333, 0.0000, 0.0000],
#           [0.0000, 0.6333, 0.0000, 0.0000]]]])

Dev

I use mise to handle project tools. Install it if you don't have it

# clone, install tools
git clone https://github.com/chrishenn/canny.git
cd canny
mise i

# list available just recipes
just --list

Available recipes:
    interactive # Detect and display canny edges on a set of test images. Use ctrl+c to kill
    lint        # run project formatters/linters [alias: l]
    test        # run basic tests
    unsafe      # run ruff with unsafe-fixes
    
# build distribution pkgs locally
uv build --package canny_chenn

# push tag to trigger pypi to build pkgs and publish to pypi
git tag -a v1.0.3 -m v1.0.3 -f && git push --tags -f

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

canny_chenn-1.0.3.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

canny_chenn-1.0.3-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file canny_chenn-1.0.3.tar.gz.

File metadata

  • Download URL: canny_chenn-1.0.3.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for canny_chenn-1.0.3.tar.gz
Algorithm Hash digest
SHA256 7f0e3a90f5d3f407275d9f1013ce021c14bdc5b6c7461406142e4c583e1f596f
MD5 dc35a12487a0b27fbcc21517614a91ee
BLAKE2b-256 22c01952c17f0a7c7e58a023d3d708e8b80458fa5ae5b41d13bc158b9437602d

See more details on using hashes here.

File details

Details for the file canny_chenn-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: canny_chenn-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.11 {"installer":{"name":"uv","version":"0.9.11"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for canny_chenn-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 28aa5bf32ce96991ba59ef17e5d7589d4692c1b008b57a47e6f24b6cf6c18e0c
MD5 3b1ecd695ee534b560b415edb43abf0d
BLAKE2b-256 587fc3ea719e464292e381c52fd096c9645d62c8f2f1857fe5b189ef62276735

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page