clear all;%clear the values
clc;%clear the command window
tic
strhead = 'G:\研二所有论文相关\研二上的一篇Retinex去雾论文\图片处理结果\好的对比结果\图1\原图1';%the name of file
strtail = '.jpg' ;% the format of the file
str = strcat(strhead,strtail);
img = im2double(imread(str));%read the image and convert to double.
N = 15;%the size of filter
sigma = [100 , 0.3];%the parameters of bilateral filter
retimg = bialteral(img , N , sigma );%get the illumination image
subplot(1,3,1);imshow(img);title('the original image');
subplot(1,3,2);imshow(retimg);title('the illumination image');
%% s-l
img_copy = rgb2hsv(img);
img_copy3 = log(img_copy(:,:,3));
retimg_copy = rgb2hsv(retimg);
retimg_copy3 = log(retimg_copy(:,:,3));%only to v layer
r_img = img_copy3 - retimg_copy3;
r_img = exp(r_img);
N = 4;
sigma = [100,0.3];
retinex_img(:,:,3) = bialteral2(r_img,N,sigma);%get reflect image
dim = size(img);
for i = 1:dim(1)
for j = 1:dim(2)
img_copy(i,j,3) = img_copy(i,j,3)^(1/3);
end
end
retinex_img(:,:,3) = retinex_img(:,:,3).*(img_copy(:,:,3));
retinex_img(:,:,1) = img_copy(:,:,1);
retinex_img(:,:,2) = img_copy(:,:,2);
retinex_img = hsv2rgb(retinex_img);
%% Gamma-correction
% dim = size(img);
% for i = 1:dim(1)
% for j = 1:dim(2)
% for c=1:3
% img(i,j,c) = img(i,j,c)^(1/3);
% end
% end
% end
% retinex_img(:,:,1) = retinex_img(:,:,1).*(img(:,:,1));
% retinex_img(:,:,2) = retinex_img(:,:,2).*(img(:,:,2));
% retinex_img(:,:,3) = retinex_img(:,:,3).*(img(:,:,3));
subplot(1,3,3);imshow(retinex_img);title('the retinex image');
% string=strcat(strhead,'_retinex.bmp');
% imwrite(retinex_img,string,'bmp');
t=toc