www.pudn.com > Dark-Channel-Prior-Codes.rar > darktest_2.m, change:2014-01-11,size:1109b


function darktest_2(filename) 
%暗影去雾算法 
%filename------文件名或文件绝对路径 
%用法:darktest('7.png') 
 
 
close all 
clc 
 
if nargin<1 
    filename='7.png'; 
end 
 
w0=0.85;   %0.65  乘积因子用来保留一些雾,1时完全去雾     
t0=0.1; 
 
I=imread(filename); 
figure; 
set(gcf,'outerposition',get(0,'screensize'));%全屏 
subplot(221) 
imshow(I); 
title('原始图像'); 
          
 
%下面取得暗影通道图像 
dark_I=min(I,[],3); 
 
subplot(223);imshow(dark_I); 
title('dark channnel的图形'); 
 
Max_dark_channel=double(max(dark_I(:)));  %天空亮度 
dark_channel=double(dark_I); 
t=1-w0*(dark_channel/Max_dark_channel);   %取得透谢分布率图 
 
subplot(224) 
T=uint8(t*255); 
imshow(T); 
title('透射率t的图形'); 
 
t=max(t,t0); 
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
I1=double(I); 
J(:,:,1) = uint8((I1(:,:,1) - (1-t)*Max_dark_channel)./t); 
J(:,:,2) = uint8((I1(:,:,2) - (1-t)*Max_dark_channel)./t); 
J(:,:,3) = uint8((I1(:,:,3) - (1-t)*Max_dark_channel)./t); 
subplot(222) 
 
imshow(J); 
title('去雾后的图像'); 
imwrite(J,'temp.tiff','tiff') 
pause(10); 
close; 
 
end