def compute_grid_graph_image_features(grid_graph, image, mode,
                                      offsets=None, strides=None,
                                      randomize_strides=False):
    """ Compute edge features from image for the given grid_graph.

    Parameters:
        grid_graph [grid-graph] - the grid graph
        image [np.ndarray] - the image, the features are derived from
        mode [str] - feature accumulation method
        offsets [list[list[int]]] - the offsets which correspond to the affinity channels.
            If none are given, it's assumed that the affinites are for the nearest neighbor transitions.
            (default: None)
        strides [list[int]] - the strides used to subsample edges that are computed from offsets.
            (default: None)
        randomize_strides (default: False) - whether to subsample randomly instead of using regular strides.
            (default: False)
    """
    gndim = len(grid_graph.shape)

    if image.ndim == gndim:
        if offsets is not None:
            raise NotImplementedError
        modes = ("l1", "l2", "min", "max", "sum", "prod", "interpixel")
        if mode not in modes:
            raise ValueError(f"Invalid feature mode {mode}, expect one of {modes}")
        features = grid_graph.imageToEdgeMap(image, mode)
        edges = grid_graph.uvIds()

    elif image.ndim == gndim + 1:
        modes = ("l1", "l2", "cosine")
        if mode not in modes:
            raise ValueError(f"Invalid feature mode {mode}, expect one of {modes}")

        if offsets is None:
            features = grid_graph.imageWithChannelsToEdgeMap(image, mode)
            edges = grid_graph.uvIds()
        else:
            (n_edges,
             edges,
             features) = grid_graph.imageWithChannelsToEdgeMapWithOffsets(image, mode,
                                                                          offsets=offsets,
                                                                          strides=strides,
                                                                          randomize_strides=randomize_strides)
            edges, features = edges[:n_edges], features[:n_edges]

    else:
        msg = f"Invalid image dimension {image.ndim}, expect one of {gndim} or {gndim + 1}"
        raise ValueError(msg)

    return edges, features