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

PyPi version PyPI download month PyPI format PyPI pyversions PyPI status

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

Supports:

  • Linux
  • PyTorch Tensor images formatted in image batches [B, C, h, w], with float32 data, and values spanning [0,1]
  • Any number of image channels C
  • All PyTorch backends
  • 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
# or,
uv add 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.

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

# list available just recipes
just --list

Available recipes:
    demo   # Show canny detections on a set of test images. Kill with ctrl+c
    lint   # run project formatters/linters [alias: l]
    test   # run basic tests
    unsafe # run ruff with unsafe-fixes
    
# build wheel, sdist pkgs locally
uv build --package canny_chenn

# push tag to trigger github action to build pkgs and publish to pypi
git tag -a v1.0.4 -m v1.0.4 -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.5.tar.gz (3.5 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.5-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: canny_chenn-1.0.5.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"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.5.tar.gz
Algorithm Hash digest
SHA256 1bf7d8366758c91cf679f2b64097d86158d66c9033bf72d8ddef71a567a85f98
MD5 addb117380cfadd33a6ba44aff46bacf
BLAKE2b-256 190a3ec42962357afca30128e1b8078341d2689438f36d90e2f0cf70fa47a026

See more details on using hashes here.

File details

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

File metadata

  • Download URL: canny_chenn-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a16c675905ca2e115124fb41a0875fd7216240e4cbd73933a95e7b6d8187a7ec
MD5 df441c44f7210ab65b6f4d6ab7ce6b6d
BLAKE2b-256 5b82cdf7db2b4cb4b998e75f7c28242d50ddce1c5be6298de0ca45bbcadf6302

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