Copy header information to another image

Let’s say I have two nibabel nifti images im1 and im2. I would like to copy the header information of im1 to im2. Doing im2.header = im1.header gives an error. Is there another way?

In nibabel, it’s generally better to create new images than modify loaded images in-place.

new_img = im2.__class__(im2.dataobj[:], im1.affine, im1.header)
new_img.to_filename(...)
1 Like

MANAGED BY INCF