Nibabel as closest to canonicla

Hi everyone,

I’m working with neuroimaging data using the NiBabel library in Python and I came across the as_closest_to_canonical function. I’ve read the documentation, but I’m still not entirely sure what this function does exactly.

Could someone please explain clearly and in detail what as_closest_to_canonical does? In what situations should I use it, and what changes does it make to the images?

It rotates the data array so that the image is in RAS orientation. That is, as you increase index along the first dimension of the data array, you are moving from left to right; along the second, from posterior to anterior; and from the third, from inferior to superior.

It does no resampling, and if the image is oblique (the image affine indicates the data array is rotated relative to the cardinal axes) that obliquity is preserved. The first dimension will move most along the L-R axis, even if it moves somewhat in the other axes as well. That’s what it means by “closest”.

1 Like