msr图像增强代码python
时间: 2023-11-09 07:02:00 浏览: 104
图像增强代码
4星 · 用户满意度95%
以下是使用MSRCP算法进行图像增强的Python代码:
```python
import cv2
import numpy as np
def MSRCP(img, scales=[15, 101, 301], sigma=[5, 15, 25], chroma=True):
img = img.astype(np.float32)
if chroma:
img_yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
img_yuv[:, :, 0] = cv2.equalizeHist(img_yuv[:, :, 0].astype(np.uint8))
img = cv2.cvtColor(img_yuv, cv2.COLOR_YUV2BGR)
else:
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.equalizeHist(img.astype(np.uint8))
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
for i in range(len(scales)):
for j in range(len(sigma)):
img_blur = cv2.GaussianBlur(img, (scales[i], scales[i]), sigma[j])
img_detail = img - img_blur
img_detail = cv2.normalize(img_detail, None, 0, 255, cv2.NORM_MINMAX)
img_detail = np.uint8(img_detail)
img = cv2.add(img, img_detail)
return np.uint8(np.clip(img, 0, 255))
# 示例
img = cv2.imread('example.jpg')
img_enhanced = MSRCP(img)
cv2.imshow('Enhanced Image', img_enhanced)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
阅读全文