You're right here: I kept thinking about niimg as strings, things will break if a Nifti1Image is passed as niimg.