Image Processing - Implementing Sobel Filter

后端 未结 8 1805
梦毁少年i
梦毁少年i 2020-12-13 02:46

I\'ve got a task to implement Sobel filter which is, as you know, an image processing filter for edge detection. But unfortunately, I\'ve got no experience in image processi

8条回答
  •  粉色の甜心
    2020-12-13 03:22

    Of course, you could use OpenCV for this:

    import cv2
    import numpy as np
    
    img = cv2.imread(INPUT_IMAGE)
    img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY).astype(float)
    
    edge_x = cv2.Sobel(img,cv2.CV_64F,1,0,ksize=3)
    edge_y = cv2.Sobel(img,cv2.CV_64F,0,1,ksize=3)    
    edge = np.sqrt(edge_x**2 + edge_y**2)    # image can be normalized to 
                                             # fit into 0..255 color space
    cv2.imwrite(OUTPUT_IMAGE, edge)
    

    Input / Output:

提交回复
热议问题