def get_dataobj(img):
    """ Return data object for nibabel image

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

    Returns
    -------
    dataobj : object
        ``ArrayProxy`` or ndarray object containing data for `img`
    """
    try:
        return img.dataobj
    except AttributeError:
        return img._data