参考文献:
"Bilateral Filter Based Compositing for Variable Exposure Photography" by Shanmuganathan Raman and Subhasis Chaudhuri in Eurographics 2009 Short papers program
算法流程:
- Gamma变换计算归一化的图像队列,范围[0, 1]
- 计算图像队列中的最大最小值
- 计算双边滤波的sigma_s和sigma_r
- 对图像队列中的所有图像计算其亮度图像L
- 对亮度图像L进行双边滤波得到L_filtered
- 计算权重和:
- 通过高频图像,计算单个图像的权重:weight = abs(L - L_filtered) + C
- 计算所有图像的权重和total
- 通过单个图像的权重比计算混合图像:imgOut = img(i) * weight / total
C = 70.0 / 255.0; %As reported in Raman and Chaudhuri
%number of images in the imageStack
[r, c, col, n] = size(imageStack);
K1 = 1.0; %As reported in Raman and Chaudhuri
K2 = 1.0 / 10.0; %As reported in Raman and Chaudhuri
sigma_s = K1 * min([r, c]);
imageStackMin = min(imageStack(:));
imageStackMax = max(imageStack(:));
sigma_r = K2 * (imageStackMax - imageStackMin);
%Computation of weights for each image
total = zeros(r, c);
weight = zeros(r, c, n);
for i=1:n
L = lum(imageStack(:,:,:,i));
L_filtered = bilateralFilter(L, [], imageStackMin, imageStackMax, sigma_s, sigma_r);
weight(:,:,i) = C + abs(L - L_filtered);
total = total + weight(:,:,i);
end
%merging
imgOut = zeros(r, c, col);
for i=1:n
for j=1:col
tmp = imageStack(:,:,j,i) .* weight(:,:,i) ./ total;
imgOut(:,:,j) = imgOut(:,:,j) + RemoveSpecials(tmp);
end
end
%Clamping
imgOut = ClampImg(imgOut, 0.0, 1.0);