matlab视觉设计图像去雾代码
时间: 2024-01-07 16:23:20 浏览: 208
用于实现图像去雾的代码,很有效,matlab写的
5星 · 资源好评率100%
根据提供的引用内容,有两种方法可以实现matlab视觉设计图像去雾代码:
方法一:直方图均衡化+Retinex理论图像去雾
```matlab
% 读取图像
img = imread('input.jpg');
% 直方图均衡化
img_eq = histeq(img);
% Retinex理论图像去雾
R = img_eq(:,:,1);
G = img_eq(:,:,2);
B = img_eq(:,:,3);
R_retinex = log(1 + double(R));
G_retinex = log(1 + double(G));
B_retinex = log(1 + double(B));
img_retinex = cat(3, R_retinex, G_retinex, B_retinex);
img_retinex = uint8(img_retinex);
% 显示结果
subplot(1, 2, 1), imshow(img), title('原始图像');
subplot(1, 2, 2), imshow(img_retinex), title('去雾后图像');
```
方法二:暗通道图像去雾
```matlab
% 读取图像
img = imread('input.jpg');
% 计算暗通道图像
R = img(:,:,1);
G = img(:,:,2);
B = img(:,:,3);
dark_channel = min(min(R, G), B);
% 估计大气光
atmospheric_light = max(max(dark_channel));
% 估计透射率
omega = 0.95;
transmission = 1 - omega * dark_channel / atmospheric_light;
% 恢复原始图像
J = img;
J(:,:,1) = (img(:,:,1) - atmospheric_light) ./ transmission + atmospheric_light;
J(:,:,2) = (img(:,:,2) - atmospheric_light) ./ transmission + atmospheric_light;
J(:,:,3) = (img(:,:,3) - atmospheric_light) ./ transmission + atmospheric_light;
% 显示结果
subplot(1, 2, 1), imshow(img), title('原始图像');
subplot(1, 2, 2), imshow(J), title('去雾后图像');
```
阅读全文