查看: 1295|回复: 1

如何用opencv锐化图像

[复制链接]

4

主题

34

帖子

88

积分

注册会员

Rank: 2

积分
88
发表于 2018-10-12 11:57:45 | 显示全部楼层 |阅读模式
如何用opencv锐化图像
看过很多opencv对图像的处理,但是我要怎么才能对图像进行锐化处理呢


回复

使用道具 举报

6

主题

21

帖子

65

积分

注册会员

Rank: 2

积分
65
发表于 2018-10-12 11:58:52 | 显示全部楼层
锐化的作用是加强图像的边沿和轮廓,通常也成为高通滤波器:
模板一般设计为中心处的值为正,外围的值为负(总系数之和为0)
  1. import cv2
  2. import numpy as np

  3. img=cv2.imread("messi5.jpg")

  4. # 1
  5. blur=cv2.GaussianBlur(img,(0,0),3)
  6. image=cv2.addWeighted(img,1.5,blur,-0.5,0)
  7. # 2
  8. kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
  9. image = cv2.filter2D(img, -1, kernel)
  10. # 3
  11. image=cv2.bilateralFilter(img,9,75,75)
  12. # 4
  13. sigma = 1; threshold = 5; amount = 1
  14. blurred=cv2.GaussianBlur(img,(0,0),1,None,1)
  15. lowContrastMask = abs(img - blurred) < threshold
  16. sharpened = img*(1+amount) + blurred*(-amount)
  17. image=cv2.bitwise_or(sharpened.astype(np.uint8),lowContrastMask.astype(np.uint8))

  18. cv2.namedWindow("dst",cv2.WINDOW_FREERATIO)
  19. cv2.imshow("dst",image)
  20. cv2.waitKey(0)
  21. cv2.destroyAllWindows()
复制代码

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表