Optimization based image registration in the presence of moving objects