[Neuroimaging] Affine Matrix AttributeError

Matthew Brett matthew.brett at gmail.com
Tue Oct 13 22:12:02 CEST 2015


On Tue, Oct 13, 2015 at 1:08 PM, Ángel Torrado Carvajal
<angel.torrado at urjc.es> wrote:
> Dear all,
> I am trying to execute my (already working) code, and I am getting an error:
> Traceback (most recent call last):
>   File "PatchBasedSegmentation.py", line 158, in <module>
>     output_img = nb.Nifti1Image(output_matrix_0, input_img.affine,
> input_img.header)
> AttributeError: 'Nifti1Image' object has no attribute 'affine'
> where:
> input_img = nb.load(input_path + input_vol)
> What's the problem? From the documentation a 'Nifti1Image' object HAS
> attribute 'affine'. Actually, it is working in my laptop. How can I fix it
> in this computer?

I think you've got an older version of nibabel - pre 2.0.  We
introduced the `.affine` property in 2.0.  If you want code compatible
with older and newer nibabel, use `img.get_affine()` instead,



More information about the Neuroimaging mailing list