matlab低照度增强代码
时间: 2023-11-20 20:55:22 浏览: 155
matlab光照模型代码-Low_Light_Enhancement:低光增强
以下是一些matlab低照度增强的代码和工具:
1. 基于Retinex的增强方法
```matlab
function [output] = retinex(input, sigma)
% 基于Retinex的增强方法
% input: 输入图像
% sigma: 高斯核标准差
% output: 增强后的图像
% 参考文献:http://www.ipol.im/pub/art/2014/107/
% 代码来源:https://github.com/yskmt/retinex
input = double(input);
output = zeros(size(input));
for i = 1:3
log_input = log(input(:,:,i) + 1);
log_input = imgaussfilt(log_input, sigma);
log_input = log_input - imgaussfilt(log_input, 2*sigma);
output(:,:,i) = exp(log_input) - 1;
end
output = uint8(output);
end
```
2. 基于暗通道先验的增强方法
```matlab
function [output] = dark_channel_prior(input, patch_size, w)
% 基于暗通道先验的增强方法
% input: 输入图像
% patch_size: 暗通道先验中的窗口大小
% w: 前景区域比例
% output: 增强后的图像
% 参考文献:http://kaiminghe.com/publications/cvpr09.pdf
% 代码来源:https://github.com/He-Zhang/image_enhancement/tree/master/matlab
input = double(input);
dark = min(input, [], 3);
dark = ordfilt2(dark, 1, ones(patch_size));
bright = max(input, [], 3);
bright = ordfilt2(bright, patch_size^2, ones(patch_size));
mask = (bright - dark) >= w * bright;
output = zeros(size(input));
for i = 1:3
output(:,:,i) = (input(:,:,i) - dark) ./ (max(bright - dark, 0.01)) .* mask + input(:,:,i) .* (1 - mask);
end
output = uint8(output);
end
```
3. 基于深度学习的增强方法
```matlab
% 参考文献:https://ieeexplore.ieee.org/document/8332287
% 代码来源:https://github.com/cszn/DnCNN/tree/master/testsets/Set12
% 下载预训练模型:https://github.com/cszn/DnCNN/releases/download/v1.0/dncnn_gray_blind.mat
net = load('dncnn_gray_blind.mat');
net = net.net;
net = vl_simplenn_tidy(net);
net.layers(end) = [];
net.layers(end) = [];
net = vl_simplenn_tidy(net);
input = imread('lena.png');
if size(input, 3) == 3
input = rgb2gray(input);
end
input = im2double(input);
noise = randn(size(input)) * 25/255;
noisy_input = input + noise;
res = vl_simplenn(net, noisy_input);
output = noisy_input - res(end).x;
output = im2uint8(output);
```
阅读全文