-
Notifications
You must be signed in to change notification settings - Fork 2
/
weight_cal_base.m
175 lines (137 loc) · 4.31 KB
/
weight_cal_base.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
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
% ========================================================================
% Fast Multi-Scale Structural Patch Decomposition for Multi-Exposure Image Fusion, TIP,2020
% algorithm Version 1.0
% Copyright(c) 2020, Hui Li, Kede Ma, Yongwei Yong and Lei Zhang
% All Rights Reserved.
% ----------------------------------------------------------------------
% Permission to use, copy, or modify this software and its documentation
% for educational and research purposes only and without fee is hereby
% granted, provided that this copyright notice and the original authors'
% names appear on all copies and supporting documentation. This program
% shall not be used, rewritten, or adapted as the basis of a commercial
% software or hardware product without first obtaining permission of the
% authors. The authors make no representations about the suitability of
% this software for any purpose. It is provided "as is" without express
% or implied warranty.
%----------------------------------------------------------------------
% Please refer to the following paper:
% H. Li et al., "Fast Multi-Scale Structural Patch Decomposition for Multi-Exposure Image Fusion, 2020" In press
% IEEE Transactions on Image Processing
% Please kindly report any suggestions or corrections to xiaohui102788@126.com
%----------------------------------------------------------------------
function W= weight_cal_base(I,m,brightness)
r = size(I,1);
c = size(I,2);
N = size(I,3);
W = ones(r,c,N);
%compute the measures and combines them into a weight map
contrast_parm = m(1);
sat_parm = m(2);
wexp_parm = m(3);
fangcha_parm = m(4);
gradient_parm=m(5);
wexp2_parm=m(6);
mask_parm=m(7);
if (contrast_parm > 0)
W = W.*contrast(I).^contrast_parm;
end
if (sat_parm > 0)
W = W.*saturation(I).^sat_parm;
end
if (wexp_parm > 0)
W = W.*well_exposedness(I).^wexp_parm;
end
if (fangcha_parm > 0)
W = W.*fangcha(I).^fangcha_parm;
end
if (gradient_parm > 0)
W = W.*gradient(I).^gradient_parm;
end
if (wexp2_parm > 0)
W = W.*well_exposedness2(I,brightness).^wexp2_parm;
end
if (mask_parm > 0)
W = W.*mask(I).^mask_parm;
end
%normalize weights: make sure that weights sum to one for each pixel
W = W + 1e-12; %avoids division by zero
W = W./repmat(sum(W,3),[1 1 N]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% contrast measure
function C = contrast(I)
h = [0 1 0; 1 -4 1; 0 1 0]; % laplacian filter
N = size(I,3);
C = zeros(size(I,1),size(I,2),N);
for i = 1:N
% mono = rgb2gray(I(:,:,:,i));
mono = I(:,:,i);
C(:,:,i) = abs(imfilter(mono,h,'replicate'));
end
% std measure
function C = fangcha(I)
countWindowt = ones(11, 11);
countWindow=countWindowt./sum(countWindowt(:));
N = size(I,3);
C = zeros(size(I,1),size(I,2),N);
for i = 1:N
% img = rgb2gray(I(:,:,:,i));
img=I(:,:,i);
i_mean2=filter2(countWindow,img,'same');
i_var2=filter2(countWindow,img.*img,'same')-i_mean2.*i_mean2;
C(:,:,i)=sqrt(max(i_var2,0));
end
% gradient measure
function C = gradient(I)
N = size(I,3);
C = zeros(size(I,1),size(I,2),N);
for i = 1:N
% img = rgb2gray(I(:,:,:,i));
img=I(:,:,i);
C(:,:,i) = imgradient(img);
end
% saturation measure
function C = saturation(I)
N = size(I,3);
C = zeros(size(I,1),size(I,2),N);
for i = 1:N
% saturation is computed as the standard deviation of the color channels
R = I(:,:,1,i);
G = I(:,:,2,i);
B = I(:,:,3,i);
mu = (R + G + B)/3;
C(:,:,i) = sqrt(((R - mu).^2 + (G - mu).^2 + (B - mu).^2)/3);
end
% well-exposedness measure
function C = well_exposedness(I)
sig = .2;
N = size(I,3);
C = zeros(size(I,1),size(I,2),N);
for i = 1:N
R = exp(-.5*(I(:,:,1,i) - .5).^2/sig.^2);
G = exp(-.5*(I(:,:,2,i) - .5).^2/sig.^2);
B = exp(-.5*(I(:,:,3,i) - .5).^2/sig.^2);
C(:,:,i) = R.*G.*B;
end
function C = well_exposedness2(I,brightness)
% sig = .2;
N = size(I,3);
C = zeros(size(I,1),size(I,2),N);
for i = 1:N
% img = rgb2gray(I(:,:,:,i));
img=I(:,:,i);
% img((img>=0.95)|(img<=0))=1;
M=ones(size(I,1),size(I,2))*mean(img(:));
C(:,:,i)=meanfun(img,M,brightness);
end
function C = mask(I)
% sig = .2;
N = size(I,3);
C = zeros(size(I,1),size(I,2),N);
Ct=ones(size(I,1),size(I,2));
% C((imgs_gray>=0.8)|(imgs_gray<=0.2))=0;
for i = 1:N
% img = rgb2gray(I(:,:,:,i));
img=I(:,:,i);
Ct((img>=0.95)|(img<=0.05))=0;
C(:,:,i)=Ct;
end