-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 79c13b1
Showing
44 changed files
with
1,006 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Instructions for running the code for Low Light Image Enhancement (LIME): | ||
|
||
1. 'lime_main_module.m' is the main file. To run LIME, steps are: | ||
a. Load an image from this folder | ||
b. Use the table mentioned below for selecting optimum values of mu, rho, ds, ss for this image | ||
c. In MATLAB command line, write [Ti,Tout,img_out,Iout] = lime_main_module(img_in,mu,rho,ds,ss,flag); | ||
Here, flag is kept 1 to view the results. Ti and Tout are initial and refined illumination maps, img_out and Iout are enhanced and denoised results. | ||
|
||
Table I | ||
name mu rho ds ss | ||
building 0.01 1.188 10 1.5 | ||
cars 0.045 1.134 5 0.75 | ||
lamp 0.8 1.07 0.1 1 | ||
land 0.5 1.09 0.3 4 | ||
moon 0.01 1.2 1 0.5 | ||
paint 0.3 1.15 1 0.5 | ||
robot 0.01 1.25 10 1 | ||
table 0.002 1.035 100 1 | ||
wires 0.01 1.165 1 0.6 | ||
|
||
2. 'lime_loop.m' is the file for tuning the parameters for the solver, i. e. alpha, mu, rho. | ||
|
||
3. 'lime_bf_loop.m' is the file for tuning the parameters for the bilateral filter, i. e. ds, ss. | ||
|
||
4. 'histeq_all.m' is the file for generating the results of applying histogram equalization, on the raw image, in five different ways. | ||
|
||
5. 'denoise_bm3d.m' is the file for denoising the enhanced result using BM3D. | ||
The code for BM3D in file 'BM3D.m' as well as other files related to it have been downloaded and used only for the purpose of comparison with bilateral filtering. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function [Td] = Tdenom(m,n,mu) | ||
%gives denominator of updation equation for T sub problem | ||
|
||
%[m,n] is the size of extended dx and dy | ||
%mu is a parameter for the solver | ||
|
||
%Td is the required denominator | ||
|
||
dxe = zeros(m,n); %extended dx | ||
dye = zeros(m,n); %extended dy | ||
%acc. to horizontal and vertical gradient convolution kernels dx and dy | ||
dxe(2,2) = -1; | ||
dxe(2,3) = 1; | ||
dye(2,2) = -1; | ||
dye(3,2) = 1; | ||
|
||
dxf=fftshift(fft2(dxe)); | ||
dxc=dxf.''; %conjugate | ||
dx_mod=dxc.*dxf; | ||
|
||
dyf=fftshift(fft2(dye)); | ||
dyc=dyf.''; | ||
dy_mod=dyc.*dyf; | ||
|
||
Td=2+mu*(dx_mod+dy_mod); | ||
|
||
end |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function [img_out] = denoise_bm3d(img_in,Topt,noise_std) | ||
%for denoising using BM3D | ||
|
||
%img_in is the enhanced image | ||
%Topt is the refined illumination map | ||
%noise_std is the standard deviation of noise corresponding to image values in range [0,255] | ||
|
||
img_yuv=rgb2yuv(img_in); %colorspace conversion | ||
|
||
[psnr,img_bm3d_y]=BM3D(1,img_yuv(:,:,1),noise_std,'np',1); | ||
|
||
%recomposing | ||
img_yuv_new(:,:,1)=img_bm3d_y; | ||
img_yuv_new(:,:,2)=img_yuv(:,:,2); | ||
img_yuv_new(:,:,3)=img_yuv(:,:,3); | ||
|
||
img_bm3d_rgb=yuv2rgb(img_yuv_new); %colorspace conversion, denoised result | ||
|
||
img_out=img_in.*Topt+img_bm3d_rgb.*(1-Topt); %recomposed result | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function [out] = gamma_corr(a,gamma) | ||
%applying gamma correction | ||
|
||
%a is input image | ||
%gamma is the parameter for gamma correction | ||
|
||
%out is the resultant image | ||
|
||
out=a.^gamma; | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function [img_out] = hist_sep(img_in) | ||
%applying histogram equalization on R,G,B channels separately | ||
|
||
%recomposing | ||
img_out(:,:,1)=histeq(img_in(:,:,1)); | ||
img_out(:,:,2)=histeq(img_in(:,:,2)); | ||
img_out(:,:,3)=histeq(img_in(:,:,3)); | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function [img_hist_trans, img_hist_sep, img_hist_hsv, img_hist_yuv, img_hist_ycbcr] = histeq_all(img_in, flag) | ||
%histogram equalization for low light image enhancement | ||
|
||
%img_in is the raw image | ||
%flag is set to 1 for displaying the outputs | ||
|
||
%output vector contains the results of five methods of histogram equalization | ||
|
||
img_test=im2double(img_in); | ||
|
||
img_hist_trans=histeq(img_test); %same as hist_trans | ||
img_hist_sep=hist_sep(img_test); | ||
img_hist_hsv=histeq_hsv(img_test); | ||
img_hist_yuv=histeq_yuv(img_test); | ||
img_hist_ycbcr=histeq_ycbcr(img_test); | ||
|
||
if flag==1 | ||
subplot(2,3,1);imshow(img_test); | ||
subplot(2,3,2);imshow(img_hist_trans); | ||
subplot(2,3,3);imshow(img_hist_sep); | ||
subplot(2,3,4);imshow(img_hist_hsv); | ||
subplot(2,3,5);imshow(img_hist_yuv); | ||
subplot(2,3,6);imshow(img_hist_ycbcr); | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function [img_out] = histeq_hsv(img_in) | ||
%applying histogram equalization on v channel | ||
|
||
imghsv=rgb2hsv(img_in); %colorspace conversion | ||
|
||
imgeq=histeq(imghsv(:,:,3)); | ||
|
||
%recomposing | ||
imgnew(:,:,3)=imgeq; | ||
imgnew(:,:,2)=imghsv(:,:,2); | ||
imgnew(:,:,1)=imghsv(:,:,1); | ||
|
||
img_out=hsv2rgb(imgnew); %colorspace conversion | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function [img_out] = histeq_ycbcr(img_in) | ||
%applying histogram equalization on y channel | ||
|
||
imghsv=rgb2ycbcr(img_in); %colorspace conversion | ||
|
||
imgeq=histeq(imghsv(:,:,1)); | ||
|
||
%recomposing | ||
imgnew(:,:,1)=imgeq; | ||
imgnew(:,:,2)=imghsv(:,:,2); | ||
imgnew(:,:,3)=imghsv(:,:,3); | ||
|
||
img_out=ycbcr2rgb(imgnew); %colorspace conversion | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function [img_out] = histeq_yuv(img_in) | ||
%applying histogram equalization on y channel | ||
|
||
imghsv=rgb2yuv(im2double(img_in)); %colorspace conversion | ||
|
||
imgeq=histeq(imghsv(:,:,1)); | ||
|
||
%recomposing | ||
imgnew(:,:,1)=imgeq; | ||
imgnew(:,:,2)=imghsv(:,:,2); | ||
imgnew(:,:,3)=imghsv(:,:,3); | ||
|
||
img_out=yuv2rgb(imgnew); %colorspace conversion | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function [test_mask] = initial_map(test_norm) | ||
%obtaining initial illumination map | ||
|
||
%test_norm is input image | ||
|
||
%test_mask is the initial illumination map for test_norm | ||
|
||
y=size(test_norm); %size will be MxNx3 for RGB image | ||
a=zeros(y(1),y(2)); %for single-channel illumination map | ||
|
||
for i=1:1:y(1) | ||
for j=1:1:y(2) | ||
b=[test_norm(i,j,1),test_norm(i,j,2),test_norm(i,j,3)]; %R,G,B values at a location | ||
if max(b)==0 | ||
a(i,j)=0.000001; %avoid division by 0 | ||
else | ||
a(i,j)=max(b); | ||
end | ||
end | ||
end | ||
test_mask=a; | ||
|
||
end |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
function [output,ini_map] = lime(input_image,alpha,mu,rho,gamma) | ||
%obtaining illumination map | ||
|
||
%input_image is raw image | ||
%alpha, mu, rho are constant parameters for the solver | ||
%gamma is parameter for gamma correction | ||
|
||
%output is three-channel refined illumination map | ||
%ini_map is single-channel initial illumination map | ||
|
||
B_norm = im2double(input_image); | ||
ini_map = initial_map(B_norm); | ||
%single-channel refined illumination map | ||
[ref_map] = lime_trial(ini_map, alpha, mu, rho); | ||
|
||
abs_ref_map = abs(ref_map); | ||
T_gamma = gamma_corr(abs_ref_map, gamma); | ||
|
||
%mapping ref_map to three channels | ||
Topt(:,:,1) = T_gamma; | ||
Topt(:,:,2) = T_gamma; | ||
Topt(:,:,3) = T_gamma; | ||
output = Topt; | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function [Iout] = lime_bf_loop(img_in,mu,rho,ds0,ss0,flag,itr) | ||
%for tuning the parameters of bilateral filter | ||
|
||
%img_in is the raw image | ||
%mu and rho are parameters for the solver | ||
%ds0 and ss0 are seed points for degree of smooothness and spatial sigma | ||
%flag controls which parameter is tuned | ||
%itr is no. of iterations or changes in the ds or ss | ||
|
||
%Iout contains final enhanced result for all iterations | ||
|
||
[m,n,p]=size(img_in); | ||
Iout=zeros(m,n,p,itr); | ||
|
||
[Tout,Ti]=lime(img_in,0.08,mu,rho,0.8); | ||
img_out=im2double(img_in)./Tout; | ||
|
||
ds=ds0; | ||
ss=ss0; | ||
|
||
for i=1:1:itr | ||
Iout(:,:,:,i)=imbilatfilt(img_out,ds,ss); | ||
if flag==1 | ||
ds=ds*10; %change updation rule as required | ||
else | ||
ss=ss+0.5; %change updation rule as required | ||
end | ||
if i<=itr | ||
subplot(2,3,i); imshow(Iout(:,:,:,i)); | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function [Tout] = lime_loop(img_in,mu0,rho0,flag,itr) | ||
%for tuning the parameters of the solver | ||
|
||
%img_in is the raw image | ||
%mu0 and rho0 are seed points for mu and rho | ||
%flag controls which parameter is tuned | ||
%itr is no. of iterations or changes in the parameter | ||
|
||
%Tout contains the illumination maps for all iterations | ||
|
||
[m,n,p]=size(img_in); | ||
Tout=zeros(m,n,p,itr); | ||
|
||
alpha=0.008; %same for all images | ||
mu=mu0; | ||
rho=rho0; | ||
|
||
for i=1:1:itr | ||
[Tout(:,:,:,i),Ti]=lime(img_in,alpha,mu,rho,0.8); %obtaining illumination maps for set of values | ||
if flag==1 | ||
mu=mu+0.01; %change updation rule as required | ||
elseif flag==2 | ||
rho=rho+0.005; %change updation rule as required | ||
else | ||
alpha=alpha*10; %change updation rule as required | ||
end | ||
if i<=10 | ||
img_out=im2double(img_in)./Tout(:,:,:,i); %enhanced result | ||
subplot(2,5,i); imshow(img_out); | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function [Ti,Tout,img_out,Iout] = lime_main_module(img_in,mu,rho,ds,ss,flag) | ||
%main module incluidng all operations for LIME | ||
|
||
%img_in is raw image | ||
%alpha, mu, rho are constant parameters for the solver | ||
%ds is degree of smoothing and ss is spatial smoothing for bilateral filter | ||
%flag kept 1 for displaying outputs | ||
|
||
%Ti is initial illumination map | ||
%Tout is refined Ti | ||
%img_out is enhanced image | ||
%I_out is img_out after denoising | ||
|
||
alpha=0.08; %same value for all images | ||
gamma=0.8; %parameter for gamma correction | ||
|
||
[Tout,Ti]=lime(img_in,alpha,mu,rho,gamma); | ||
img_out=im2double(img_in)./Tout; | ||
|
||
Iout=imbilatfilt(img_out,ds,ss); | ||
|
||
if flag==1 | ||
subplot(2,3,1);imshow(img_in); | ||
subplot(2,3,2);colormap('hot');imagesc(Ti(:,:,1));colorbar; %heat map | ||
subplot(2,3,3);colormap('hot');imagesc(Tout(:,:,1));colorbar; | ||
subplot(2,3,4);imshow(img_out); | ||
subplot(2,3,5);imshow(Iout); | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function [Topt] = lime_trial(Ti,alpha,mu0,rho) | ||
%solver for the optimization problem | ||
|
||
%Ti is initial illumination map | ||
%alpha, mu0, rho are constant parameters for the solver | ||
|
||
%Topt is refined illumination map | ||
|
||
[m,n]=size(Ti); | ||
k0=50; %no. of iterations | ||
Z=zeros(2*m,n); G=Z; k=0; mu=mu0; %initialization | ||
%W=Z+1; %weight matrix using first strategy | ||
W=make_weight_matrix(Ti,5); %weight matrix using second strategy | ||
|
||
while k<k0 | ||
U=Z/mu; A=alpha*W/mu; | ||
T=updateT(Ti,mu,G,U); %acc. to T sub-problem | ||
delT=multiplyd(T); %gradient of T | ||
G=shrinkage(A,(delT+U)); %acc. to G sub-problem | ||
B=delT-G; | ||
Z=mu*(B+U); %Z and mu sub-problem | ||
mu=mu*rho; | ||
k=k+1; | ||
end | ||
Topt=T; | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
function [W] = make_weight_matrix(Ti,ker_size) | ||
%making the weight matrix using second strategy | ||
|
||
%Ti is the initial illumination map | ||
%ker_size is the size of the Gaussian kernel | ||
|
||
%W is the required weight matrix | ||
|
||
[m,n]=size(Ti); | ||
p=m*n; | ||
|
||
%obtaining gradient of Ti | ||
delTi=multiplyd(Ti); | ||
dtvec=reshape(delTi,[2*p,1]); | ||
|
||
%separating parts used for W_x and W_y | ||
dtx=dtvec(1:p); | ||
dty=dtvec(p+1:2*p); | ||
|
||
%obtaining W_x and W_y | ||
w_gauss = fspecial ('gaussian', [ker_size,1], 2); | ||
convl_x = conv(dtx, w_gauss, 'same'); | ||
convl_y = conv(dty, w_gauss, 'same'); | ||
W_x = 1./(abs(convl_x)+0.0001); | ||
W_y = 1./(abs(convl_y)+0.0001); | ||
|
||
%concatenating W_x and W_y to get W | ||
W_vec = vertcat(W_x, W_y); | ||
W = reshape (W_vec, [2*m,n]); | ||
|
||
end |
Oops, something went wrong.