opencv 除雾 python
时间: 2023-10-08 21:10:31 浏览: 121
要使用OpenCV进行除雾操作的Python代码,您可以参考以下代码示例:
```python
import cv2
import numpy as np
def preprocess(filename, i):
image = cv2.imread(filename)
image_gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
# 直方图均衡增强
image_equal = cv2.equalizeHist(image_gray)
r,g,b = cv2.split(image)
r1 = cv2.equalizeHist(r)
g1 = cv2.equalizeHist(g)
b1 = cv2.equalizeHist(b)
image_equal_clo = cv2.merge([r1, g1, b1])
# 拉普拉斯算法增强
kernel = np.array([
[0, -1, 0],
[-1, 5, -1],
[0, -1, 0]
])
image_lap = cv2.filter2D(image, cv2.CV_8UC3, kernel)
# 对数算法增强
image_log = np.uint8(np.log(np.array(image) + 1))
cv2.normalize(image_log, image_log,0, 255, cv2.NORM_MINMAX)
cv2.convertScaleAbs(image_log, image_log)
# 伽马变换
fgamma = 2
image_gamma = np.uint8(np.power((np.array(image) / 255.0), fgamma) * 255.0)
cv2.normalize(image_gamma, image_gamma, 0, 255, cv2.NORM_MINMAX)
cv2.convertScaleAbs(image_gamma, image_gamma)
```
这段代码展示了使用OpenCV进行图像增强的几种常用算法,包括直方图均衡化、拉普拉斯、对数和伽马变换。您可以根据需要选择其中的算法来进行除雾操作。
请注意,您需要将图像文件的路径传递给`preprocess`函数,并根据需要对代码进行适当的修改和调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Adaptive-model-for-haze-removal](https://download.csdn.net/download/weixin_42160398/18342364)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [图像增强算法(直方图均衡化、拉普拉斯、Log、伽马变换)](https://blog.csdn.net/weixin_30836759/article/details/97217954)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文