Return img with data reordered to be closest to canonical
Canonical order is the ordering of the output axes.
Parameters:
img : spatialimage
enforce_diag : {False, True}, optional
If True, before transforming image, check if the resulting image
affine will be close to diagonal, and if not, raise an error
Returns:
canonical_img : spatialimage
Version of img where the underlying array may have been
reordered and / or flipped so that axes 0,1,2 are those axes in
the input data that are, respectively, closest to the output axis
orientation. We modify the affine accordingly. If img is
already has the correct data ordering, we just return img
unmodified.