如何使用OpenCV来锐化图像

来源:互联网 发布:个人发卡网源码授权 编辑:程序博客网 时间:2024/05/29 19:52

参考:
https://stackoverflow.com/questions/4993082/how-to-sharpen-an-image-in-opencv


import cv2import numpy as npimg=cv2.imread("messi5.jpg")# 1blur=cv2.GaussianBlur(img,(0,0),3)image=cv2.addWeighted(img,1.5,blur,-0.5,0)# 2kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])image = cv2.filter2D(img, -1, kernel)# 3image=cv2.bilateralFilter(img,9,75,75)# 4sigma = 1; threshold = 5; amount = 1blurred=cv2.GaussianBlur(img,(0,0),1,None,1)lowContrastMask = abs(img - blurred) < thresholdsharpened = img*(1+amount) + blurred*(-amount)image=cv2.bitwise_or(sharpened.astype(np.uint8),lowContrastMask.astype(np.uint8))cv2.namedWindow("dst",cv2.WINDOW_FREERATIO)cv2.imshow("dst",image)cv2.waitKey(0)cv2.destroyAllWindows()