暗通道去雾python
时间: 2023-10-02 09:09:04 浏览: 134
python实现暗通道去雾算法的示例
5星 · 资源好评率100%
暗通道先验算法(Dark Channel Prior)是一种用于图像去雾的算法。在Python中,可以使用以下代码实现该算法:
```python
import numpy as np
import cv2
def dark_channel_prior(image, patch_size=15):
# 计算暗通道图像
min_channel = np.min(image, axis=2)
dark_channel = cv2.erode(min_channel, np.ones((patch_size, patch_size), dtype=np.uint8))
return dark_channel
def get_atmospheric_light(image, dark_channel, top_percent=0.001):
# 获取全球大气光值
flat_dark_channel = dark_channel.flatten()
num_pixels = len(flat_dark_channel)
top_pixels = int(num_pixels * top_percent)
indices = np.argpartition(flat_dark_channel, -top_pixels)[-top_pixels:]
atmospheric_light = np.max(image.reshape(-1, 3)[indices], axis=0)
return atmospheric_light
def get_transmission(image, atmospheric_light, omega=0.95, patch_size=15):
# 估计透射率图像
normalized_image = image.astype(np.float64) / atmospheric_light.astype(np.float64)
dark_channel = dark_channel_prior(normalized_image, patch_size)
transmission = 1 - omega * dark_channel
return transmission
def dehaze(image, transmission, atmospheric_light, t0=0.1):
# 对图像进行去雾
阅读全文