How To Sharpen an image in OpenCV

后端 未结 3 1754
悲&欢浪女
悲&欢浪女 2021-01-06 13:40

A basic Google search finds this SO question and what appears to be an excellent answer. When I try, however, it has absolutely no effect on sharpening my blurred image.

3条回答
  •  青春惊慌失措
    2021-01-06 13:52

    In order to make it work for a proper image you can check out both the following approches. I did the coding using OpenCV 3.0.0:

    import cv2
    
    x = 'Columbia river.jpg'
    img = cv2.imread(x, 1)
    cv2.imshow("Original",img)
    

    #---Approach 1---
    #---Sharpening filter----
    kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
    im = cv2.filter2D(img, -1, kernel)
    cv2.imshow("Sharpening",im)
    

    #---Approach 2---
    aw = cv2.addWeighted(img, 4, cv2.blur(img, (30, 30)), -4, 128)
    cv2.imshow("Add_weighted", aw)
    

提交回复
热议问题