Background position computation with efficient margins