Repository navigation
Expand file tree
/
Copy pathILP+HSV Modified.m
More file actions
285 lines (240 loc) · 7.48 KB
/
Copy pathILP+HSV Modified.m
File metadata and controls
285 lines (240 loc) · 7.48 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
%HDR image generation using a single image using Inverted Local Patterns
img=imread('girl.jpg');%input image
%{
LAB = rgb2lab(I);
L = LAB(:,:,1)/100;
L = adapthisteq(L,'NumTiles',[8 8],'ClipLimit',0.005);
LAB(:,:,1) = L*100;
img = lab2rgb(LAB);
%}
img2=imresize(img,[256,256]);%resize image to 256x256 resolution
img3=imresize(img,[256,256]);%resize image to 256x256 resolution
img_ori=img2;
img2=rgb2ycbcr(img2);
[x,y,z]=size(img2);
img_grey=img2(:,:,1);%convert RGB image to grayscale image
img_Cb = img2(:,:,2);%Cb part of YCbCr of image
img_Cr = img2(:,:,3);%Cr part of YCbCr of image
for i=1:1:x
for j=1:1:y
img_grey(i,j)=double((double(img_grey(i,j)-16)*255)/219);
end
end
%mean intensity of the image
meanIntensity = mean(mean(img2(:,:,1)));
%Modifying the Cb and Cr values
for i=1:1:x
for j=1:1:y
if img2(i,j,1)>meanIntensity
%img2(i,j,2) = img2(i,j,2)*1;
%img2(i,j,3) = img2(i,j,3)*1;
img2(i,j,2) = double(double(img2(i,j,2))*double((double(img2(i,j,1)/meanIntensity))^0.5));
img2(i,j,3) = double(double(img2(i,j,3))*double((double(img2(i,j,1)/meanIntensity))^0.5));
%log(img2(i,j,2)) = double(double(log(img2(i,j,2)))*double((double((log(img2(i,j,1))/meanIntensity))^0.5)));
% log(img2(i,j,2)) = double(double(log(img2(i,j,2)))*double((double((log(img2(i,j,1))/meanIntensity))^0.5)));
%img2(i,j,3) = double(double(img2(i,j,3))*double((double((img2(i,j,1)/meanIntensity))^0.5)));
end
end
end
%{
for i=1:1:x
for j=1:1:y
if img_grey(i,j)>meanIntensity
img2_a(i,j,2) = img2(i,j,2)*2;
img2_a(i,j,3) = img2(i,j,3)*2;
%log(img2(i,j,2)) = double(double(log(img2(i,j,2)))*double((double((log(img2(i,j,1))/meanIntensity))^0.5)));
% log(img2(i,j,2)) = double(double(log(img2(i,j,2)))*double((double((log(img2(i,j,1))/meanIntensity))^0.5)));
%img2(i,j,3) = double(double(img2(i,j,3))*double((double((img2(i,j,1)/meanIntensity))^0.5)));
end
end
end
for i=1:1:x
for j=1:1:y
if img_grey(i,j)>meanIntensity
img2_b(i,j,2) = img2(i,j,2)*3;
img2_b(i,j,3) = img2(i,j,3)*3;
%log(img2(i,j,2)) = double(double(log(img2(i,j,2)))*double((double((log(img2(i,j,1))/meanIntensity))^0.5)));
% log(img2(i,j,2)) = double(double(log(img2(i,j,2)))*double((double((log(img2(i,j,1))/meanIntensity))^0.5)));
%img2(i,j,3) = double(double(img2(i,j,3))*double((double((img2(i,j,1)/meanIntensity))^0.5)));
end
end
end
for i=1:1:x
for j=1:1:y
if img_grey(i,j)>meanIntensity
img2_c(i,j,2) = img2(i,j,2)*4;
img2_c(i,j,3) = img2(i,j,3)*4;
%log(img2(i,j,2)) = double(double(log(img2(i,j,2)))*double((double((log(img2(i,j,1))/meanIntensity))^0.5)));
% log(img2(i,j,2)) = double(double(log(img2(i,j,2)))*double((double((log(img2(i,j,1))/meanIntensity))^0.5)));
%img2(i,j,3) = double(double(img2(i,j,3))*double((double((img2(i,j,1)/meanIntensity))^0.5)));
end
end
end
for i=1:1:x
for j=1:1:y
if img_grey(i,j)>meanIntensity
img2(i,j,2) = (img2_a(i,j,2)+img2_b(i,j,2)+img2_c(i,j,2))/9;
img2(i,j,3) = (img2_a(i,j,3)+img2_b(i,j,3)+img2_c(i,j,3))/9;
%log(img2(i,j,2)) = double(double(log(img2(i,j,2)))*double((double((log(img2(i,j,1))/meanIntensity))^0.5)));
% log(img2(i,j,2)) = double(double(log(img2(i,j,2)))*double((double((log(img2(i,j,1))/meanIntensity))^0.5)));
%img2(i,j,3) = double(double(img2(i,j,3))*double((double((img2(i,j,1)/meanIntensity))^0.5)));
end
end
end
%}
[hist,o]=imhist(img_grey);%hist represents luminicance histogram
HB=0;%HB value of original image
for i=1:1:256
HB=HB+abs(hist(i)-255);
end
% here we set some thresholds th1,th2,th3,th4 and thdark
th1=16;
th2=51;
th3=206;
th4=241;
thdark=0;
%Now we calculate values of 'low' and 'high'.
%These will determine whether original image is dark,bright,extreme or normal.
low=0;
high=0;
for i=1:1:th1-1
low=low+hist(i)*2;
end
for i=th1:1:th2-1
low=low+hist(i);
end
for i=th3:1:th4-1
high=high+hist(i);
end
for i=th4:1:256
high=high+hist(i)*2;
end
if low>(high*2)
thdark=128; %dark image
elseif high>(low*2)
thdark=0; %bright image
elseif (high/low)<=2 && (high/low)>=0.5
thdark=50; %extreme image
% else
% return; %original image is already HDR
end
%Here we apply a 3x3 low pass on img_max
img_low = imfilter(img_grey,fspecial('average',[3 3]));
%Now we apply inverse operation on img_low
%After the inverse operation, bright regions become dark and dark regions
%become bright
img_inv=size([256,256]);
for i=1:1:x
for j=1:1:y
p=double(255-img_low(i,j));
p=p*p;
img_inv(i,j)=double(p/255);
end
end
%Dark enhancement
%Here we brighten the darker regions of the original image
%If pixel value is less than thdark,then we increase its brightness
%Otherwise it remains same
img_dark=size([256,256]);
for i=1:1:x
for j=1:1:y
if img_grey(i,j)<thdark
temp=double(img_grey(i,j))+double(double(thdark-img_grey(i,j))*0.05);
img_dark(i,j)=temp;
else
img_dark(i,j)=img_grey(i,j);
end
end
end
%Mixing operation
%Here we mix the results of inverse operation and dark enhancement
%We use a parameter k which depends on type of image.
%More the darkness,more the value of k and vice-versa.
k=1.82*(1e-8)*low+0.009;
img_mix=size([256,256]);
for i=1:1:x
for j=1:1:y
temp=img_dark(i,j)*img_inv(i,j);
temp=temp*k;
img_mix(i,j)=temp;
end
end
%Brightness enhancement
%Here we increase brightness of img_mix to get our HDR image
thb=29.17;
img_hdr=img_mix;
for i=1:1:x
for j=1:1:y
if img_dark(i,j)>=thb
p=double(img_dark(i,j)-thb);%%%
p=p*p;
p=p*0.005;%%%
img_hdr(i,j)=img_mix(i,j)+p;
else
img_hdr(i,j)=img_mix(i,j);
end
end
end
a=max(img_hdr);
for i=1:1:x
for j=1:1:y
if img_hdr(i,j)==max(a)
disp(i)
disp(j)
end
end
end
img2(:,:,1)=img_hdr;
[hist_hdr,o1]=imhist(img2(:,:,1));
img_new=ycbcr2rgb(img2);
img_des0=imread('000003_in_prediction_prediction_reinhard.jpg');%Proposed image
img_des=imresize(img_des0,[256,256]);
[hist_hdr2,o2]=imhist(img_des);%hist_hdr2 represents luminicance histogram of Proposed image
figure;
imshow(img_ori)
%figure;
%imshow(img_grey)
% figure;
% imshow(img_low)
%figure;
%imshow(img_inv)
%figure;
%imshow(img_dark)
%figure;
%imshow(img_mix)
% figure;
% imshow(img_hdr)
%figure;
%imshow(img_des0)
%figure;
%imshow(img_des1)
%figure;
%imshow(img_des2)
%figure;
%imshow(img_des3)
figure;
imshow(img_new)
% figure;
% imshow(img2(:,:,1))
% figure;
% imhist(img_hdr)
%figure;
%plot(hist_hdr)
%ylim([0,2000]);
%figure;
%imshow(img_des)
%figure;
%imhist(img_des)
% ylim([0,max(hist_hdr)]);
%figure;
%plot(hist)
%ylim([0,max(hist)]);
%figure;
%plot(hist_hdr2)
%ylim([0,max(hist_hdr2)]);
%figure;
%plot(hist_dark)
%ylim([0,max(hist_dark)]);
%figure;
%plot(hist_mix)
%ylim([0,max(hist_mix)]);