├── Readme.md ├── demo.m ├── images ├── Horse │ ├── 1.png │ ├── 2.png │ └── 3.png ├── Horse_SPDMEF.jpg └── Horse_Shutao.jpg ├── mef_ms_ssim_d.m └── support functions ├── generate_intermediate.m ├── load_images.m ├── mef_ssim_d.m └── reorderByLum.m /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # Perceptual Evaluation for Multi-Exposure Image Fusion of Dynamic Scenes 3 | This is the implementation for [Perceptual Evaluation for Multi-Exposure Image Fusion of Dynamic Scenes](http://sim.jxufe.cn/JDMKL/pdf/19_TIP_MEF-SSIMd.pdf), [Yuming Fang](http://sim.jxufe.cn/JDMKL/ymfang.html), Hanwei Zhu, [Kede Ma](https://kedema.org/), [Zhou Wang](https://ece.uwaterloo.ca/~z70wang/), [Shutao Li](http://scholar.google.com/citations?user=PlBq8n8AAAAJ&hl=zh-CN), *IEEE Transactions on Image Processing* (TIP), vol. 29, no. 1, pp. 1127-1138, Dec. 2020. 4 | 5 | ## Abstract 6 | A common approach to high dynamic range (HDR) imaging is to capture multiple images of different exposures followed by multi-exposure image fusion (MEF) in either radiance or intensity domain. A predominant problem of this approach is 7 | the introduction of the ghosting artifacts in dynamic scenes with camera and object motion. While many MEF methods (often referred to as deghosting algorithms) have been proposed for reduced ghosting artifacts and improved visual quality, little work has been dedicated to perceptual evaluation of their deghosting 8 | results. Here we first construct a database that contains 20 multi-exposure sequences of dynamic scenes and their corresponding fused images by nine MEF algorithms. We then carry out a subjective experiment to evaluate fused image quality, and find that none of existing objective quality models for MEF provides 9 | accurate quality predictions. Motivated by this, we develop an objective quality model for MEF of dynamic scenes. Specifically, we divide the test image into static and dynamic regions, measure structural similarity between the image and the corresponding sequence in the two regions separately, and combine quality 10 | measurements of the two regions into an overall quality score. Experimental results show that the proposed method significantly outperforms the state-of-the-art. In addition, we demonstrate the promise of the proposed model in parameter tuning of MEF methods. 11 | 12 | ## Prerequisites 13 | 14 | - MATLAB 15 | 16 | ## Dataset 17 | 18 | The MEF image quality database can be obtained at: [DeghostingIQADatabase](http://sim.jxufe.cn/JDMKL/code/DeghostingIQADatabase.rar). The dataset contains: 19 | 20 | - 20 multi-exposure image sequences of dynamic natural scenes 21 | - 9 MEF methods generate 180 fused images 22 | - Mean opinion scores of the fused images 23 | 24 | 25 | ## Test 26 | 27 | Here, to test the source image sequnce 'horse' with two fused images, and show the quality maps. 28 | ``` 29 | run demo.m 30 | ``` 31 | 32 | ## Reference 33 | - Y. Fang, H. Zhu, K. Ma, and Z. Wang, “Perceptual quality assessment of HDR deghosting algorithms,” in *IEEE International Conference on Image Processing*, 2017, pp. 3165–3169. 34 | - K. Ma, K. Zeng, and Z. Wang, “Perceptual quality assessment for multi-exposure image fusion,” *IEEE Transactions on Image Processing*, vol. 24, no. 11, pp. 3345–3356, Nov. 2015. 35 | 36 | ## Citation 37 | ``` 38 | @article{Fang2019, 39 | title={Perceptual Evaluation for Multi-Exposure Image Fusion of Dynamic Scenes}, 40 | author={Fang, Yuming and Zhu, Hanwei and Ma, Kede and Wang, Zhou and Li, Shutao}, 41 | journal={IEEE Transactions on Image Processing}, 42 | volume={29}, 43 | number={1}, 44 | pages={1127--1138}, 45 | month={Dec.}, 46 | year={2020} 47 | } 48 | -------------------------------------------------------------------------------- /demo.m: -------------------------------------------------------------------------------- 1 | clc,clear,close all; 2 | 3 | %% change direction 4 | prev_dir = pwd; file_dir = fileparts(mfilename('fullpath')); cd(file_dir); 5 | addpath(genpath(pwd)); 6 | 7 | %% model calculation 8 | Q = zeros(2,1); % test two fused images 9 | imgSeqColor = uint8(load_images('./images/horse',1)); 10 | imgSeqColor = uint8(reorderByLum(imgSeqColor)); 11 | [s1, s2, s3, s4] = size(imgSeqColor); 12 | imgSeq = zeros(s1, s2, s4); 13 | for i = 1:s4 14 | imgSeq(:, :, i) = rgb2gray( squeeze( imgSeqColor(:,:,:,i) ) ); % color to gray conversion 15 | end 16 | 17 | fI1 = imread('./images/Horse_Shutao.jpg'); 18 | fI1 = double(rgb2gray(fI1)); 19 | [Q(1), QMap1] = mef_ms_ssim_d(imgSeq, fI1); 20 | 21 | fI2= imread('./images/Horse_SPDMEF.jpg'); 22 | fI2 = double(rgb2gray(fI2)); 23 | [Q(2), QMap2] = mef_ms_ssim_d(imgSeq, fI2); 24 | 25 | figure; 26 | subplot(2,2,1), imshow(fI1/255), title('Li12'); 27 | subplot(2,2,2), imshow(QMap1), title('quality map'); 28 | subplot(2,2,3), imshow(fI2/255), title('SPD-MEF'); 29 | subplot(2,2,4), imshow(QMap2), title('quality map'); 30 | -------------------------------------------------------------------------------- /images/Horse/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h4nwei/MEF-SSIMd/a6c197b4a35a0585208058d5d277ed14b13e190a/images/Horse/1.png -------------------------------------------------------------------------------- /images/Horse/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h4nwei/MEF-SSIMd/a6c197b4a35a0585208058d5d277ed14b13e190a/images/Horse/2.png -------------------------------------------------------------------------------- /images/Horse/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h4nwei/MEF-SSIMd/a6c197b4a35a0585208058d5d277ed14b13e190a/images/Horse/3.png -------------------------------------------------------------------------------- /images/Horse_SPDMEF.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h4nwei/MEF-SSIMd/a6c197b4a35a0585208058d5d277ed14b13e190a/images/Horse_SPDMEF.jpg -------------------------------------------------------------------------------- /images/Horse_Shutao.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/h4nwei/MEF-SSIMd/a6c197b4a35a0585208058d5d277ed14b13e190a/images/Horse_Shutao.jpg -------------------------------------------------------------------------------- /mef_ms_ssim_d.m: -------------------------------------------------------------------------------- 1 | function [Q, qMap] = mef_ms_ssim_d(imgSeq, fI, varargin) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % Multi-exposure fused (MEF) for dynamic scene image quality model Version 1.0 % 4 | % Copyright(c) 2019 Yuming Fang, Hanwei Zhu, Kede Ma, Zhou Wang, and Shutao Li % 5 | % All Rights Reserved. % 6 | % % 7 | % ------------------------------------------------------------------------------% 8 | % Permission to use, copy, or modify this software and its documentation % 9 | % for educational and research purposes only and without fee is hereby % 10 | % granted, provided that this copyright notice and the original authors' % 11 | % names appear on all copies and supporting documentation. This program % 12 | % shall not be used, rewritten, or adapted as the basis of a commercial % 13 | % software or hardware product without first obtaining permission of the % 14 | % authors. The authors make no representations about the suitability of % 15 | % this software for any purpose. It is provided "as is" without express % 16 | % or implied warranty. % 17 | % ---------------------------------------------------------------------- % 18 | % This is an implementation of an objective image quality assessment model % 19 | % for MEF of dynamic scene using their corresponding input source % 20 | % sequences as reference % 21 | % % 22 | % Please refer to the following paper: % 23 | % % 24 | % Y. Fang, H. Zhu, K. Ma, Z. Wang, and S. Li, "Perceptual Evaluation for % 25 | % Multi-Exposure Image Fusion of Dynamic Scenes" submitted to IEEE % 26 | % Transactions on Image Processing % 27 | % % 28 | % % 29 | % Kindly report any suggestions or corrections to h4nwei.zhu@gmail.com, % 30 | % fa0001ng@e.ntu.edu.sg, k29ma@uwaterloo.ca, or zhouwang@ieee.org % 31 | % % 32 | % % 33 | % ---------------------------------------------------------------------- % 34 | % MEF-SSIMd % 35 | % input: (1) imgSeq: image sequences at multiple exposure levels [0-255]. % 36 | % (2) fI: the MEF image being evaluated in [0-255] grayscale. % 37 | % optional input: % 38 | % (3) C: constant in the SSIM index formula (see the above % 39 | % reference). defualt value: K = (0.03*255)^2 % 40 | % (4) p: the exponent parameter. default value p = 4; % 41 | % (5) structureThres: the structure consistent threshold. % 42 | % defualt value: structureThres = 0.5 % 43 | % (6) window: local window for statistics. default widnow is % 44 | % Gaussian given by window = fspecial('gaussian', 11, 1.5); % 45 | % % 46 | % % 47 | % % 48 | % output: (1) oQ: The overlll quality score of the MEF image. % 49 | % (2) Q: The quality scores in each scale. % 50 | % (3) qMap: The quality maps of the MEF image in each scale. % 51 | % % 52 | %Basic Usage: % 53 | % Given the test MEF image and its corresponding source sequence % 54 | % % 55 | % [Q, qMap] = mef_ms_ssim_d(imgSeq, fI); % 56 | % % 57 | % % 58 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 59 | % input params parsing 60 | params = inputParser; 61 | 62 | default_C = (0.03*255)^2; 63 | default_p = 4; 64 | default_structureThres = 0.5; 65 | default_window = fspecial('gaussian', 11, 1.5); 66 | 67 | addRequired(params,'imgSeq'); 68 | addRequired(params,'fI'); 69 | addParameter(params, 'C', default_C, @isnumeric); 70 | addParameter(params, 'p', default_p, @isnumeric); 71 | addParameter(params, 'structureThres', default_structureThres, @isnumeric); 72 | addParameter(params, 'window', default_window, @isnumeric); 73 | 74 | parse(params, imgSeq, fI, varargin{:}); 75 | 76 | % initialization 77 | C = params.Results.C; 78 | p = params.Results.p; 79 | structureThres = params.Results.structureThres; 80 | window = params.Results.window; 81 | 82 | 83 | imgSeq = double(imgSeq); 84 | fI = double(fI); 85 | 86 | % MEF-SSIMd 87 | [Q, qMap] = mef_ssim_d(imgSeq, fI, C, p, window, structureThres); 88 | -------------------------------------------------------------------------------- /support functions/generate_intermediate.m: -------------------------------------------------------------------------------- 1 | function [out_params] = generate_intermediate(imgSeqExd, C, p, window, structureThres, refIdx) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % The function extract the reference patch index, mu, sigma square, input % 4 | % sequence mu, and input sequence sigma square % 5 | % input: 1. imgSeq: image sequences at multiple exposure levels [0-255] % 6 | % 2. fI: the MEF image being evaluated in [0-255] grayscale. % 7 | % 3. C % 8 | % 4. p % 9 | % 5. window: sliding window (default 8x8 average window) % 10 | % 6. SturctureThres % 11 | % 7. refIdx: % 12 | % % 13 | % output struct: % 14 | % 1. ed: signal strength % 15 | % 2. lmu: local mean intensity % 16 | % 3. patchIndex: patch index of the patch with the maximum euclidean length % 17 | % 4. sMap: the third term in SSIM among each exposed image % 18 | % 5. maxEd: desired signal strength % 19 | % 5. indexMap: region segmentation map % 20 | % 6. indM: index matrix for the main loop % 21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 22 | 23 | imgSeqExd = double(imgSeqExd); 24 | [s1, s2, numExd] = size(imgSeqExd); 25 | s3 = (numExd + 1) / 2; % exposure number 26 | wSize = size(window,1); 27 | xIdxMax = s1-wSize+1; 28 | yIdxMax = s2-wSize+1; 29 | gMu = zeros(xIdxMax, yIdxMax, numExd); % global mean intensity 30 | for i = 1 : numExd 31 | img = imgSeqExd(:,:,i); 32 | gMu(:,:,i) = ones(xIdxMax, yIdxMax) * mean(img(:)); %global mean intensity 33 | end 34 | 35 | lMu = zeros(xIdxMax, yIdxMax, numExd); % local mean intensity 36 | lMuSq = zeros(xIdxMax, yIdxMax, numExd); 37 | sigmaSq = zeros(xIdxMax, yIdxMax, numExd); % signal strength from variance 38 | for i = 1 : numExd 39 | lMu(:,:,i) = filter2(window, imgSeqExd(:, :, i), 'valid'); 40 | lMuSq(:,:,i) = lMu(:,:,i) .* lMu(:,:,i); % mean square 41 | sigmaSq(:,:,i) = filter2(window, imgSeqExd(:, :, i).*imgSeqExd(:, :, i), 'valid') - lMuSq(:,:,i); 42 | end 43 | 44 | sigma = sqrt( max( sigmaSq, 0 ) ); 45 | ed = sigma*wSize + 0.001; % signal strength 46 | 47 | % computing structural consistency map 48 | count = 0; 49 | numIndex = s3*(s3-1)/2; 50 | sMap = zeros(xIdxMax, yIdxMax, s3, s3); 51 | sRefMap = zeros(xIdxMax, yIdxMax, numIndex); 52 | for i = 1 : s3 53 | for j = i+1 : s3 54 | count=count+1; 55 | crossMu = lMu(:,:,i) .* lMu(:,:,j); 56 | crossSigma = conv2(imgSeqExd(:, :, i).*imgSeqExd(:, :, j), window, 'valid') - crossMu; 57 | sMap(:,:,i,j) = ( crossSigma + C) ./ (sigma(:,:,i).* sigma(:,:,j) + C); % the third term in SSIM 58 | sRefMap(:,:,count) = sMap(:,:,i,j); % the third term in SSIM 59 | end 60 | end 61 | 62 | sRefMap(sRefMap < structureThres) = 0; 63 | sRefMap(sRefMap >= structureThres) = 1; 64 | indexMap=zeros(xIdxMax,yIdxMax); 65 | 66 | se = strel('disk',wSize); 67 | for k = 1 : numIndex 68 | sRefMap(:,:,k) = imopen(sRefMap(:,:,k),se); 69 | end 70 | 71 | for k=1:numIndex 72 | indexMap=indexMap+sRefMap(:,:,k); 73 | end 74 | indexMap(indexMap < numIndex) = 0; 75 | indexMap(indexMap >= numIndex) = 1;%final binary map 76 | clear sMap; 77 | clear sRefMap; 78 | cMap = repmat(indexMap,[1, 1, s3]); 79 | cMap(:,:,refIdx) = ones(xIdxMax, yIdxMax); % add reference 80 | cMapExd = zeros(xIdxMax, yIdxMax, numExd); 81 | cMapExd(:, :, 1:s3) = cMap; 82 | clear cMap; 83 | count = 0; 84 | for i = 1 : s3 85 | if i ~= refIdx 86 | count = count + 1; 87 | cMapExd(:, :, count+s3) = 1 - cMapExd(:,:,i); 88 | end 89 | end 90 | 91 | % computing index matrix for the main loop 92 | indM = zeros(xIdxMax, yIdxMax, s3); 93 | indM(:,:,refIdx) = refIdx; 94 | for i = 1 : s3 95 | if i < refIdx 96 | indM(:,:,i) = cMapExd(:, :, i) * i + cMapExd(:, :, i+s3) * (i+s3); 97 | elseif i > refIdx 98 | indM(:,:,i) = cMapExd(:, :, i) * i + cMapExd(:, :, i+s3-1) * (i+s3-1); 99 | end 100 | end 101 | 102 | 103 | 104 | sMap = ed.^p; % signal structure weighting map 105 | sMap = sMap .* cMapExd + 0.001; 106 | normalizer = sum(sMap,3); 107 | sMap = sMap ./ repmat(normalizer,[1, 1, numExd]); 108 | 109 | maxEd = ed .* cMapExd; % desired signal strength 110 | [maxEd, patchIndex] = max(maxEd, [], 3); 111 | 112 | out_params.ed = ed; 113 | out_params.lMu = lMu; 114 | out_params.patchIndex = patchIndex; 115 | out_params.sMap = sMap; 116 | out_params.maxEd = maxEd; 117 | out_params.indexMap = indexMap; 118 | out_params.indM = indM; 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /support functions/load_images.m: -------------------------------------------------------------------------------- 1 | % This procedure loads a sequence of images 2 | % 3 | % Arguments: 4 | % 'path', refers to a directory which contains a sequence of JPEG or PPM 5 | % images 6 | % 'reduce' is an optional parameter that controls downsampling, e.g., reduce = .5 7 | % downsamples all images by a factor of 2. 8 | % 9 | % tom.mertens@gmail.com, August 2007 10 | % 11 | 12 | function I = load_images(path, reduce) 13 | 14 | if ~exist('reduce') 15 | reduce = 1; 16 | end 17 | 18 | if (reduce > 1 || reduce <= 0) 19 | error('reduce must fulfill: 0 < reduce <= 1'); 20 | end 21 | 22 | % find all JPEG or PPM files in directory 23 | files = dir([path '/*.tif']); 24 | N = length(files); 25 | if (N == 0) 26 | files = dir([path '/*.jpg']); 27 | N = length(files); 28 | if (N == 0) 29 | files = dir([path '/*.JPG']); 30 | N = length(files); 31 | if (N == 0) 32 | files = dir([path '/*.bmp']); 33 | N = length(files); 34 | if (N == 0) 35 | files = dir([path '/*.png']); 36 | N = length(files); 37 | if (N == 0) 38 | error('no files found'); 39 | end 40 | end 41 | end 42 | end 43 | end 44 | 45 | % allocate memory 46 | sz = size(imread([path '/' files(1).name])); 47 | r = floor(sz(1)*reduce); 48 | c = floor(sz(2)*reduce); 49 | I = zeros(r,c,3,N); 50 | 51 | % read all files 52 | for i = 1:N 53 | 54 | % load image 55 | filename = [path '/' files(i).name]; 56 | im =double(imread(filename)); 57 | if (size(im,1) ~= sz(1) || size(im,2) ~= sz(2)) 58 | error('images must all have the same size'); 59 | end 60 | 61 | % optional downsampling step 62 | if (reduce < 1) 63 | im = imresize(im,[r c],'bicubic'); 64 | end 65 | if size(im,3)==1 66 | I(:,:,:,i) = cat(3,im,im,im); 67 | else 68 | I(:,:,:,i) = im; 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /support functions/mef_ssim_d.m: -------------------------------------------------------------------------------- 1 | function [Q, qMap] = mef_ssim_d(imgSeq, fI, C, p, window, structureThres) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % The function calculate the MEF-SSIMd index quality score and quality map % 4 | % input: 1. imgSeq: image sequences at multiple exposure levels [0-255] % 5 | % 2. fI: the MEF image being evaluated in [0-255] grayscale. % 6 | % 3. C % 7 | % 4. p % 8 | % 5. window: sliding window (default 11x11 average window) % 9 | % 6. SturctureThres % 10 | % % 11 | % output: % 12 | % 1. Q: MEF-SSIMd index quality score % 13 | % 2. qMap: MEF-SSIMd index quality map % 14 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 15 | 16 | imgSeq = double(imgSeq); 17 | fI = double(fI); 18 | 19 | [s1, s2, s3] = size(imgSeq); 20 | wSize = size(window,1); 21 | sWindow = ones(wSize) / wSize^2; 22 | xIdxMax = s1-wSize+1; 23 | yIdxMax = s2-wSize+1; 24 | stMap = zeros(xIdxMax, yIdxMax); %static region quality map 25 | dyMap = zeros(xIdxMax, yIdxMax, s3);%dynamic region quality map 26 | for refIdx=1:s3 27 | %iterative generate pseudo sequence 28 | numExd = 2*s3-1; 29 | imgSeqExd = uint8(zeros(s1, s2, numExd)); 30 | imgSeqExd(:,:,1:s3) = uint8(imgSeq); 31 | count = 0; 32 | for i = 1 : s3 33 | if i ~= refIdx 34 | count = count + 1; 35 | temp = imhistmatch(uint8(imgSeqExd(:,:,refIdx)), uint8(imgSeqExd(:,:,i)), 256); 36 | temp( temp<0 ) = 0; 37 | temp( temp>255 ) = 255; 38 | imgSeqExd(:,:,count+s3) = temp; 39 | end 40 | end 41 | 42 | %compute binary and ideal reference patch 43 | [out_params] = generate_intermediate(imgSeqExd, C, p, sWindow, structureThres, refIdx); 44 | lMu = out_params.lMu; 45 | ed = out_params.ed; 46 | sMap = out_params.sMap; 47 | maxEd = out_params.maxEd; 48 | indexMap = out_params.indexMap; 49 | indM = out_params.indM; 50 | 51 | % main loop 52 | stepSize = 1; 53 | xIdx = 1 : stepSize : xIdxMax; 54 | xIdx = [xIdx xIdx(end)+1 : xIdxMax]; 55 | yIdx = 1 : stepSize : yIdxMax; 56 | yIdx = [yIdx yIdx(end)+1 : yIdxMax]; 57 | 58 | offset = wSize-1; 59 | for row = 1 : length(xIdx) 60 | for col = 1 : length(yIdx) 61 | i = xIdx(row); 62 | j = yIdx(col); 63 | if indexMap(i, j)==1 && refIdx==1 64 | blocks = imgSeqExd(i:i+offset, j:j+offset, indM(i,j,:)); 65 | blocks = double(blocks); 66 | rBlock = zeros(wSize, wSize); 67 | for k = 1 : s3 68 | rBlock = rBlock + sMap(i, j, k) * (blocks(:,:,k) - lMu(i, j, k) ) / ed(i, j, k); 69 | end 70 | if norm(rBlock(:)) > 0 71 | rBlock = rBlock / norm(rBlock(:)) * maxEd(i, j); 72 | end 73 | fBlock = fI(i:i+offset, j:j+offset); 74 | rVec = rBlock(:); 75 | fVec = fBlock(:); 76 | mu1 = sum( window(:) .* rVec ); 77 | mu2 = sum( window(:) .* fVec ); 78 | sigma1Sq = sum( window(:) .* (rVec - mu1).^2 ); 79 | sigma2Sq = sum( window(:) .* (fVec - mu2).^2 ); 80 | sigma12 = sum( window(:) .* (rVec - mu1) .* (fVec - mu2) ); 81 | stMap(i,j) = ( 2 * sigma12 + C ) ./ ( sigma1Sq + sigma2Sq + C ); 82 | elseif indexMap(i, j)==0 83 | blocks = imgSeqExd(i:i+offset, j:j+offset, indM(i,j,:)); 84 | blocks = double(blocks); 85 | rBlock = zeros(wSize, wSize); 86 | for k = 1 : s3 87 | rBlock = rBlock + sMap(i, j, k) * (blocks(:,:,k) - lMu(i, j, k) ) / ed(i, j, k); 88 | end 89 | if norm(rBlock(:)) > 0 90 | rBlock = rBlock / norm(rBlock(:)) * maxEd(i, j); 91 | end 92 | fBlock = fI(i:i+offset, j:j+offset); 93 | rVec = rBlock(:); 94 | fVec = fBlock(:); 95 | mu1 = sum( window(:) .* rVec ); 96 | mu2 = sum( window(:) .* fVec ); 97 | sigma1Sq = sum( window(:) .* (rVec - mu1).^2 ); 98 | sigma2Sq = sum( window(:) .* (fVec - mu2).^2 ); 99 | sigma12 = sum( window(:) .* (rVec - mu1) .* (fVec - mu2) ); 100 | dyMap(i,j,refIdx) = ( 2 * sigma12 + C ) ./ ( sigma1Sq + sigma2Sq + C ); 101 | end 102 | end 103 | end 104 | end 105 | staticNum = sum(indexMap(:)==1); 106 | dynamicNum = size(indexMap, 1) * size(indexMap, 2) - staticNum; 107 | Qs = sum(sum(stMap/staticNum)); 108 | 109 | if dynamicNum~=0 110 | QdExd = zeros(s3, 1); 111 | for i = 1 :s3 112 | QdExd(i) = sum(sum(dyMap(:,:,i)/dynamicNum)); 113 | end 114 | [Qd,index]=max(QdExd); 115 | 116 | qMap=dyMap(:,:,index) + stMap; 117 | Q = (Qs + Qd) / 2; 118 | else 119 | Q = Qs; 120 | qMap = stMap; 121 | end 122 | 123 | 124 | -------------------------------------------------------------------------------- /support functions/reorderByLum.m: -------------------------------------------------------------------------------- 1 | function imgSeq_reordered = reorderByLum(imgSeq) 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 | % The function reorder each exposed image according to the expose time % 4 | % input: 1. imgSeq: input image sequences at multiple exposure levels [0-255] % 5 | % % 6 | % output struct: % 7 | % 1. imgSeq_reorder: reordered image sequence at multiple exposure levels [0-255] % 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | imgSeq = double(imgSeq); 10 | m = squeeze(sum(sum(sum(imgSeq, 1), 2), 3)); 11 | [~, idx] = sort(m); 12 | imgSeq_reordered = imgSeq(:, :, :, idx); --------------------------------------------------------------------------------