A complete from-scratch implementation of the Canny edge detection algorithm for image processing applications.
- Complete Canny Algorithm: Full implementation of all five stages (Gaussian smoothing, gradient calculation, non-maximum suppression, double thresholding, hysteresis tracking)
- Configurable Parameters: Adjustable sigma, kernel size, and threshold values for different use cases
- Class-Based Design: Clean, reusable object-oriented implementation
- Image Utilities: Built-in functions for loading, converting RGB to grayscale, and visualization
- Educational Examples: Comprehensive Jupyter notebooks demonstrating the algorithm pipeline
- Image Alignment Applications: Extended use cases for practical image processing tasks
- Python 3.7+: Core programming language
- NumPy: Numerical computations and array operations
- SciPy: Scientific computing and image processing functions
- Matplotlib: Image visualization and plotting
- Jupyter: Interactive development and demonstration
- Python 3.7 or higher
- pip package manager
# Clone the repository
git clone https://gitlab.com/user4302_Projects/coding/python/university/iit/canny-edge-detector.git
cd canny-edge-detector
# Install required packages
pip install numpy scipy matplotlib jupyterfrom cannyedgedetector import CannyEdgeDetector
from utils import utils
# Load and preprocess images
images = utils.load_data('path/to/images')
# Initialize detector with custom parameters
detector = CannyEdgeDetector(
images,
sigma=1.4,
kernel_size=5,
low_threshold=0.09,
high_threshold=0.17
)
# Detect edges
edge_images = detector.detect()
# Visualize results
utils.visualize(edge_images, 'gray')# Custom detector configuration
detector = CannyEdgeDetector(
images,
sigma=1.0, # Gaussian smoothing parameter
kernel_size=5, # Size of Gaussian kernel
weak_pixel=75, # Intensity for weak edges
strong_pixel=255, # Intensity for strong edges
low_threshold=0.05, # Lower threshold ratio
high_threshold=0.15 # Higher threshold ratio
)canny-edge-detector/
βββ cannyedgedetector.py # Main CannyEdgeDetector class
βββ utils/
β βββ utils.py # Utility functions (load, visualize, rgb2gray)
βββ Canny_Edge_Detector.ipynb # Main demonstration notebook
βββ image_alignment_task.ipynb # Extended image processing examples
βββ face_images/ # Sample images directory
βββ README.md # This file
βββ .git/ # Git repository
The CannyEdgeDetector class accepts the following parameters:
- sigma (float, default=1): Standard deviation for Gaussian kernel
- kernel_size (int, default=5): Size of the Gaussian kernel (must be odd)
- weak_pixel (int, default=75): Intensity value for weak edges
- strong_pixel (int, default=255): Intensity value for strong edges
- low_threshold (float, default=0.05): Lower threshold ratio (0-1)
- high_threshold (float, default=0.15): Higher threshold ratio (0-1)
# Start Jupyter notebook for interactive development
jupyter notebook
# Run specific notebooks
jupyter nbconvert --to notebook --execute Canny_Edge_Detector.ipynb
jupyter nbconvert --to notebook --execute image_alignment_task.ipynbThe project includes demonstration notebooks that serve as functional tests:
# Run the main demonstration
jupyter nbconvert --to notebook --execute Canny_Edge_Detector.ipynb --inplace
# Run image alignment examples
jupyter nbconvert --to notebook --execute image_alignment_task.ipynb --inplaceThis is a pure Python library with no build steps required. Simply import the modules:
import cannyedgedetector
from utils import utilsThe library can be deployed as:
- Python Package: Install via pip from local directory
- Docker Container: Containerize with Python base image
- Cloud Function: Deploy as serverless function for image processing
- Web Service: Wrap in Flask/FastAPI for HTTP API
We welcome contributions! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Merge Request
Important: For any questions, bug reports, feature requests, or security concerns, please open an issue on GitLab: https://gitlab.com/user4302_Projects/coding/python/university/iit/canny-edge-detector/-/issues
This project is licensed under the MIT License - see the LICENSE file for details.
For any questions, bug reports, feature requests, or security concerns, please open an issue on GitLab: https://gitlab.com/user4302_Projects/coding/python/university/iit/canny-edge-detector/-/issues
No email or direct messaging support is available.
- John Canny for the original edge detection algorithm (1986)
- SciPy and NumPy communities for excellent numerical computing tools
- Computer vision researchers and practitioners who continue to advance edge detection techniques