图像增强算法代码python
时间: 2023-09-24 21:05:13 浏览: 142
深度学习的低光图像增强_python_代码_下载
5星 · 资源好评率100%
以下是几个常用的图像增强算法的Python代码示例:
1. 色彩调整(亮度、对比度、饱和度):
```python
import cv2
def adjust_brightness(image, value):
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
v = cv2.add(v, value)
v = np.clip(v, 0, 255)
hsv = cv2.merge((h, s, v))
adjusted = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
return adjusted
def adjust_contrast(image, value):
alpha = float(131 + value) / 131
adjusted = cv2.addWeighted(image, alpha, image, 0, 0)
return adjusted
def adjust_saturation(image, value):
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv)
s = cv2.add(s, value)
s = np.clip(s, 0, 255)
hsv = cv2.merge((h, s, v))
adjusted = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
return adjusted
```
2. 图像锐化增强(使用卷积核):
```python
import cv2
import numpy as np
def sharpen_image(image):
kernel = np.array([[-1,-1,-1], [-1,9,-1], [-1,-1,-1]])
阅读全文