% Copyright (c) 2017 Indian Institute of Science, Bangalore, India.
% 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.
% 
% The following papers are to be cited in the bibliography whenever
% the software is used as:
% Hisham Rahman, Rajiv Soundararajan, and R. Venkatesh Babu,
% "Evaluating Multiexposure Fusion Using Image Information",
% Signal Processing Letters, in print, DOI: 10.1109/LSP.2017.2752233.
% 
% The attached code computes a single quality score given a test image
% and set of over/under-exposed reference images.
% 
% For questions and/or comments please email
% Hisham Rahman (hishamrahman@gmail.com).
%
% imgTest: HxW Gray-scale image in double-precision[0,255]
% imgRef: HxWxN Gray-scale over/under-exposed images in double-prec [0,255]

function qScore = mef_qa_imgInfo(imgTest, imgRef)
    % Compute the mean-weight map from ref images.
    % (Does not depend on test image)
    % Also return a steerable pyramid representation of ref images.
    [meanWghtArray, imgRefPyr] = compute_weights_StPyr(imgRef);
    nLev = size(meanWghtArray,1);
    
    % Get the q-map mixing weights for each level.
    % (Does not depend on test image)
    pyrW = cell(1,nLev);
    
    for lev=1:nLev
        W = fusion_max_VIF_weights_StPyr(imgRefPyr{lev}); % max.I(Di,Di') weights.
        pyrW{lev} = W(6:end-5, 6:end-5,:); %Discard the 11x11 window boundary as ms-ssim using 11x11 boundary.
    end
    
    % Compute the quality score.
    qScore = ssim_mixing_StPyr(imgTest, imgRef, pyrW, meanWghtArray);
end
