def set_patches(patches, pixels, patch_centers, offset, offset_index):
    """
    Set the values of a group of patches into the correct regions of a copy
    of this image. Given an array of patches and a set of patch centers,
    the patches' values are copied in the regions of the image that are
    centred on the coordinates of the given centers.

    The patches argument can have any of the two formats that are returned
    from the `extract_patches()` and `extract_patches_around_landmarks()`
    methods. Specifically it can be:

        1. ``(n_center, n_offset, self.n_channels, patch_shape)`` `ndarray`
        2. `list` of ``n_center * n_offset`` :map:`Image` objects

    Currently only 2D images are supported.

    Parameters
    ----------
    patches : `ndarray` or `list`
        The values of the patches.
        A ``(n_center, n_offset, self.n_channels, patch_shape)`` `ndarray`
    pixels : ``(n_channels, height, width)`` `ndarray``
        Pixel array to replace the patches within
    patch_centers : :map:`PointCloud`
        The centers to set the patches around.
    offset : `list` or `tuple` or ``(1, 2)`` `ndarray`
        The offset to apply on the patch centers within the image.
    offset_index : `int`
        The offset index within the provided `patches` argument, thus the
        index of the second dimension from which to sample.

    Raises
    ------
    ValueError
        If pixels array is not 2D
    """
    if pixels.ndim != 3:
        raise ValueError('Only 2D images are supported but found {}'.format
            (pixels.shape))
    patch_shape = patches.shape[-2:]
    l_r, l_c = int(patch_shape[0] // 2), int(patch_shape[1] // 2)
    h_r, h_c = int(l_r + patch_shape[0] % 2), int(l_c + patch_shape[1] % 2)
    for patches_with_offsets, point in zip(patches, patch_centers):
        patch = patches_with_offsets[offset_index]
        p = point + offset[0]
        p_r = int(p[0])
        p_c = int(p[1])
        pixels[:, p_r - l_r:p_r + h_r, p_c - l_c:p_c + h_c] = patch
