-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.m
145 lines (110 loc) · 2.98 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
% clc
clear all
close all
im=imread('test images\3.jpg'); %test 3,4,5,8,9
figure,
imshow(im), title('Original Image')
im=double(im);
R=im(:,:,1);
G=im(:,:,2);
B=im(:,:,3);
[row,col,dim]=size(im);
L=max(R,max(G,B));
imshow(L,[]), title('Image Lightness')
%illumination estimation
r=7;
n=0;
SE = strel('disk',r,n);
Ilm = imclose(L,SE);
Ilm=Ilm/255;
figure,
imshow(Ilm,[]), title('Morphologically Closing Operation')
guidedimg=rgb2hsv(im);
g=guidedimg(:,:,3);
I = imguidedfilter(Ilm,g);
figure
imshow(I,[]),title('Iluminance')
%reflectance
rf1=R./I;
rf2=G./I;
rf3=B./I;
rel(:,:,1)=rf1;
rel(:,:,2)=rf2;
rel(:,:,3)=rf3;
figure;
imshow(uint8(rel),[]), title('Reflectance')
%inputs
I1=I;
Imean=mean(I(:));
lambda=10+(1-Imean)/Imean;
I2=2/pi*atan(lambda*I);
% mm=5;
% nn=5;
%I3=blkproc(I,[mm nn], @histeq);
I3 = adapthisteq(I);
%weights
alpha=2;
phi=250;
[imhue imsat imlum]=rgb2hsv(im);
Wb1=exp(-((I1-0.5).^2)/(2*.25*.25));
Wb2=exp(-((I2-0.5).^2)/(2*.25*.25));
Wb3=exp(-((I3-0.5).^2)/(2*.25*.25));
Wc1=I1.*(1+cos(alpha*imhue+phi).*imsat);
Wc2=I2.*(1+cos(alpha*imhue+phi).*imsat);
Wc3=I3.*(1+cos(alpha*imhue+phi).*imsat);
W1=Wb1.*Wc1;
W2=Wb2.*Wc2;
W3=Wb3.*Wc3;
%Normalize the weights
W1=W1./(W1+W2+W3);
W2=W2./(W1+W2+W3);
W3=W3./(W1+W2+W3);
figure,
subplot(3,4,1),imshow(I1,[])
subplot(3,4,2),imshow(I2,[])
subplot(3,4,3),imshow(I3,[])
subplot(3,4,4),imshow(Wb1,[])
subplot(3,4,5),imshow(Wb2,[])
subplot(3,4,6),imshow(Wb3,[])
subplot(3,4,7),imshow(Wc1,[])
subplot(3,4,8),imshow(Wc2,[])
subplot(3,4,9),imshow(Wc3,[])
subplot(3,4,10),imshow(W1,[])
subplot(3,4,11),imshow(W2,[])
subplot(3,4,12),imshow(W3,[])
Ifinal1=I1.*W1+I2.*W2+I3.*W3;
figure;
imshow(Ifinal1);title('Adjusted Illuminace ')
%generate pyramid
level=2;
Lap_pyr_image1=genPyr(I1,'laplace',level);
Gauss_pyr_weight1=genPyr(W1,'gauss',level);
Lap_pyr_image2=genPyr(I2,'laplace',level);
Gauss_pyr_weight2=genPyr(W2,'gauss',level);
Lap_pyr_image3=genPyr(I3,'laplace',level);
Gauss_pyr_weight3=genPyr(W3,'gauss',level);
%Upsampling
for j=1:level
Lap_pyr_image1{j}=imresize(Lap_pyr_image1{j},[row,col]);
Gauss_pyr_weight1{j}=imresize(Gauss_pyr_weight1{j},[row,col]);
Lap_pyr_image2{j}=imresize(Lap_pyr_image2{j},[row,col]);
Gauss_pyr_weight2{j}=imresize(Gauss_pyr_weight2{j},[row,col]);
Lap_pyr_image3{j}=imresize(Lap_pyr_image3{j},[row,col]);
Gauss_pyr_weight3{j}=imresize(Gauss_pyr_weight3{j},[row,col]);
end
Ifinal2=0;
for j=1:level
Ifinal2=Ifinal2 + Lap_pyr_image1{j}.*Gauss_pyr_weight1{j} + Lap_pyr_image2{j}.*Gauss_pyr_weight2{j} + Lap_pyr_image3{j}.*Gauss_pyr_weight3{j};
end
figure;
imshow(Ifinal2), title('Adjusted Illuminance with pyramid')
enhanced1=rf1.*Ifinal2;
enhanced2=rf2.*Ifinal2;
enhanced3=rf3.*Ifinal2;
enhanced_color(:,:,1)=enhanced1;
enhanced_color(:,:,2)=enhanced2;
enhanced_color(:,:,3)=enhanced3;
enhanced_color_out=uint8(255*enhanced_color/max(enhanced_color(:)));
figure;
imshow(enhanced_color_out), title('Enhanced Image')
piqe(uint8(enhanced_color_out))