验证 Single Image Haze Removal Using Dark Channel Prior先验的MATLAB代码
注:代码内容引自zixu1986 (Euro) 北邮人论坛
这个先验是:没有haze干扰自然景像中local patches(除了蓝天)总有一些像素的某个通道值非常低。
引起的原因是
1)局部阴影
2)很多彩色在rgb3个通道中有些通道的值很低
3)暗的物体或者表面
% a script to see the dark channels of each image
input_dir = 'banff';
block_size = 25;
file_ext = '.jpg';
% getting the filenames of the images
files = dir(input_dir);
filenames = {files.name};
for i = 1:length(filenames)
if isempty(strfind(lower(filenames{i}), file_ext))
continue
end
disp('.')
read_filename = [input_dir filesep filenames{i}];
I = imread(read_filename);
img_size = size(I);
% must be 3-channel color image
if length(img_size) ~= 3 || img_size(3) ~= 3
% warning('Should be color image!')
continue
end
% min of each channel
tmp = [];
for j = 1:3
tmp(:,:,j) = uint8(colfilt(I(:,:,j), [block_size block_size], 'sliding', @min));
end
dark_channel = uint8(min(tmp,[],3));
k = strfind(lower(filenames{i}), file_ext);
orig_name = filenames{i};
orig_name = orig_name(1:k-1);
save_filename = [input_dir filesep orig_name 'dc' int2str(block_size) file_ext];
imwrite(dark_channel, save_filename);
end