Dark Channel Prior的Matlab代码

验证 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
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值