% 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).

% Get the quality map fusion weights.
% imgRefSb in rxcxN  image subband[0, 255] double-precision.
% N = number of source images.
function wghtMax = fusion_max_VIF_weights_StPyr(imgRefSb)

    % create empty pyramid
    r = size(imgRefSb, 1);
    c = size(imgRefSb, 2);
    N = size(imgRefSb, 3);
    
    % Run one source subband to get output dimensions.
    [Test] = selfinfoQMapFunc_PW(imgRefSb(:, :, 1));
    [Wh,Ww] = size(Test);
    wghtMap = zeros(Wh, Ww, N);
    % Run subbands of all images.
    for i = 1:N
        [wghtMap(:, :, i)] = selfinfoQMapFunc_PW(imgRefSb(:, :, i));
    end
    wghtMax = zeros(Wh,Ww,N); % Compute max. matrix
    for i = 1:Wh
        for j = 1:Ww
            [~, idx] = max(squeeze(wghtMap(i, j, :)));
            wghtMax(i,j,idx) = 1;
        end
    end
end