def get_img_space(wsp, img):
    """
    Find out what image space an image is in
    
    Note that this only compares the voxel->world transformation matrix to the
    reference image for each space. It is quite possible for two images to be in
    the same space but not be registered to one another. In this case, 
    the returned space may not be accurate when determining whether a registration
    is required.

    :param wsp: Workspace object
    :param img: Image
    :return: Name of image space for ``img``, e.g. ``native``, ``struc``
    """ 
    img_space = None
    for space in ('native', 'calib', 'struc', 'std', 'custom'):
        ref = getattr(wsp.reg, "%sref" % space)
        if ref is not None and img.sameSpace(ref):
            img_space = space
            break

    if img_space is None:
        raise RuntimeError("Could not determine space for image: %s" % str(img))
    return img_space