验证 Single Image Haze Rem…

来源:互联网 发布:通达信mac版公式 编辑:程序博客网 时间:2024/03/28 19:25
原文地址:Single Image Haze Removal Using Dark Channel Prior先验的MATLAB代码">验证 Single Image Haze Removal Using Dark Channel Prior先验的MATLAB代码作者:bikey

 

图像处理 2010-07-0216:27:10 阅读101 评论0   字号: 订阅

注:代码内容引自zixu1986 (Euro) 北邮人论坛 
这个先验是:没有haze干扰自然景像中localpatches(除了蓝天)总有一些像素的某个通道值非常低。 
引起的原因是 
1)局部阴影 
2)很多彩色在rgb3个通道中有些通道的值很低 
3)暗的物体或者表面 
% a script to see the darkchannels 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)
    ifisempty(strfind(lower(filenames{i}), file_ext))
       continue
   end
    
   disp('.')
   read_filename = [input_dir filesepfilenames{i}];
    I =imread(read_filename);
   img_size = size(I);
    % mustbe 3-channel color image
    iflength(img_size) ~= 3 || img_size(3) ~= 3
       % warning('Should be colorimage!')
       continue
   end
    
    % minof 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
0 0
原创粉丝点击