function [reconImg, reconDistortion, reconValidRange] = exp_getRecon(img, frames, tsel, blockx, blocky, b, deltapsReals)
% Created by Yuandong Tian, Oct. 5, 2009
% Email: yuandong@andrew.cmu.edu
% distortion and image recovery using coefficients on the bases. 

[m, n, nFrame] = size(frames);

gf = fspecial('gaussian', [11, 11], 4);

[warpsX, warpsY] = getWarpFromStitch([m, n], blockx, blocky, b, deltapsReals);
warpsXf = imfilter(warpsX, gf, 'same');
warpsYf = imfilter(warpsY, gf, 'same');

reconImg = reconMean(frames(:, :, tsel), warpsXf, warpsYf);

if nargout >= 2
    % reconDistortion
    warp.Xs = warpsXf;
    warp.Ys = warpsYf;

    reconDistortion = simulate(img, warp);
    reconValidRange = [blockx(1), blocky(1), blockx(end)-1, blocky(end)-1];
end;