def get_affine(img):
    """ Return affine from nibabel image

    Parameters
    ----------
    img : ``SpatialImage`` instance
        Instance of nibabel ``SpatialImage`` class

    Returns
    -------
    affine : object
        affine object from `img`
    """
    try:
        return img.affine
    except AttributeError:
        return img.get_affine()