function [shat fbp xlac] = mmdect_im_setup(yi, ftab, sg, ig, dtype, varargin)
%|function [shat fbp xlac] = mmdect_im_setup(yi, ftab, sg, ig, dtype, [options])
%|
%|sinogram domain dual material decomposition  
%|FBP reconstruction from decomposed sinogram
%|LAC at energies 
%|
%| in
%| yi           DECT sinogram data
%| ftab         strum 
%| sg           CT system object
%| ig           image geometry object 
%| dtype        dual material type
%| option
%| 'energy'     energies for LAC
%|
%| out 
%| shat         decomposed dual material sinogram
%| fbp          dual material FBP reconstruction 
%| xlac         LAC at two energies
%| 
%| Copyright 2015-04-15, Yong Long, UM-SJTU JI
%|

if nargin < 5, help(mfilename), error(mfilename), end

f.energies = [70 140]; % default energies
f = vararg_pair(f, varargin);

% sinogram domain dual material decomposition
shat = ftab.inv2.fun(yi);

% FBP reconstruction
f.fbp = fbp2(sg, ig);
fbp = fbp2(shat, f.fbp, 'window', 'hanning,0.8');

% LAC at two energies
mas = xray_read_mac(dtype);
mac = mas.mac(f.energies);

xlac(:,:,1) = fbp(:,:,1) * mac(1,1) + fbp(:,:,2) * mac(1,2);
xlac(:,:,2) = fbp(:,:,1) * mac(2,1) + fbp(:,:,2) * mac(2,2);





