Refactored resample_img, raising appropriate exceptions when necessary