Skip to content

noobsiecoder/edge-detection-filters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Edge Detection Filters

This Python project focuses on implementing edge detection algorithms without using OpenCV library. It includes the Sobel and Canny edge detection technique.

Links

  1. Canny Edge Detection: Explained and Compared with OpenCV in Python
  2. Seeing the World in Edges: An Insider’s Look at Sobel Detection

Implementation

  1. Sobel Filter
  • The Sobel filter is a gradient-based edge detection algorithm. It computes the gradient magnitude of an image, which highlights edges where the intensity changes rapidly.
  • The Sobel operator applies two 3x3 convolution kernels to the image, one for detecting horizontal changes and the other for vertical changes.
  • The algorithm to perform Sobel Filter is shown below
    1. Convert the color image to grayscale by taking its mean from the values of the RGB channel in the image (assuming it is a color image)
    2. Apply a 3x3 convolution filter horizontally and vertically to the grayscale intensity values
    3. Calculate the gradient magnitude := sqrt( (hrz ** 2) + (vrt ** 2))
    4. Choose an appropriate value for thresholding, higher the value, lowers the chances of finding an edge (dull)
  1. Canny Edge Detection
  • The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images.
  • It was developed by John F. Canny in 1986. Canny also produced a computational theory of edge detection explaining why the technique works.
  • The process of applying Canny edge detection on an image:
    1. Convert the color image to grayscale
    2. Apply Gaussian filter (kernel) to smooth the image in order to remove the noise
    3. Find the intensity gradients (magnitude and orientation) of the image
    4. Perform non-max supression by using the gradient magnitude in the gradient direction (check if the pixel is a local maxima)
    5. Find potential edges by categorizing edges: weak, strong and no-edges
    6. Track edges by hysteresis and connect the weak edges to strong edges in the image

Result

  1. Sobel Edge Detector comparison b/w sobel and custom impl

  2. Canny Edge Detector comparison b/w canny and custom impl

Requirements

  • Python 3.x
  • Numpy
  • Matplotlib
  • SciPy

Installation

  • Ensure you have Python installed on your system. If not, download and install it from here.
  • Install the required dependencies:
    pip3 install -r requirements.txt

Usage/Examples

  1. Clone or download this repository to your local machine.
  2. Run the following command to execute the edge detection script:
    # edge_detection_file<str> := [sobel | canny]
    # img_file(s)<str| list> := [img_01, .., img_03]
    python3 src/<edge_detection_file>.py samples/<img_file(s)>.png

Contributing

Contributions are always welcome! Feel free to submit pull requests or open issues for any improvements or additional features you'd like to see.

License

This project is licensed under the MIT License - see the LICENSE file for details.

References

About

Sobel and Canny edge detection implemented in Python3.x

Topics

Resources

License

Stars

Watchers

Forks

Languages