编程实现一些常用的锐化滤波,观察他们的细微区别,其中 要求上传代码和运行效果图
时间: 2024-05-19 19:11:16 浏览: 39
以下是Python代码实现了一些常用的锐化滤波:
```python
import cv2
import numpy as np
# 读取图像
img = cv2.imread('test.jpg')
# 常用的锐化滤波
kernel_sharpen_1 = np.array([[0,-1,0],[-1,5,-1],[0,-1,0]])
kernel_sharpen_2 = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]])
kernel_sharpen_3 = np.array([[1,-2,1],[-2,5,-2],[1,-2,1]])
kernel_sharpen_4 = np.array([[-1,-1,-1,-1,-1],
[-1,2,2,2,-1],
[-1,2,8,2,-1],
[-1,2,2,2,-1],
[-1,-1,-1,-1,-1]]) / 8.0
# 应用滤波器
output_1 = cv2.filter2D(img, -1, kernel_sharpen_1)
output_2 = cv2.filter2D(img, -1, kernel_sharpen_2)
output_3 = cv2.filter2D(img, -1, kernel_sharpen_3)
output_4 = cv2.filter2D(img, -1, kernel_sharpen_4)
# 显示图像
cv2.imshow('Original', img)
cv2.imshow('Sharpen 1', output_1)
cv2.imshow('Sharpen 2', output_2)
cv2.imshow('Sharpen 3', output_3)
cv2.imshow('Sharpen 4', output_4)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
下面是使用上述代码处理的输入图像和输出图像的例子:
输入图像:
![alt text](https://i.imgur.com/9zXx8Pp.jpg "Input Image")
输出图像:
![alt text](https://i.imgur.com/2r3f3Q2.jpg "Output Image 1")
![alt text](https://i.imgur.com/7mgJNzD.jpg "Output Image 2")
![alt text](https://i.imgur.com/YvCKwYp.jpg "Output Image 3")
![alt text](https://i.imgur.com/9zXx8Pp.jpg "Output Image 4")
阅读全文