Canny Edge Detection Algorithm Implementation

  • Share this:

Code introduction


This function uses the Canny edge detection algorithm to detect edges from the given image and saves the result to the specified output path.


Technology Stack : scikit-image (skimage), NumPy, imageio

Code Type : Image processing

Code Difficulty : Intermediate


                
                    
import numpy as np
from skimage import filters, io, color

def edge_detect_image(input_image_path, output_image_path):
    # Load the image
    image = io.imread(input_image_path)
    
    # Convert the image to grayscale
    gray_image = color.rgb2gray(image)
    
    # Apply the Canny edge detector
    edges = filters.canny(gray_image)
    
    # Save the result as an image
    io.imsave(output_image_path, edges)