def get_n_neighborhood_start_stop_indices_3D(volume_shape, point, n):
    """
    Compute the start and stop indices along the 3 dimensions for the n-neighborhood of the point within the 3D volume.

    Note that this returns an index range where the end is *non-inclusive*! So for a point at x,y,z with 0-neighborhood (only the point itself), you will get x,x+1,y,y+1,z,z+1 as return values.

    Parameters
    ----------
    volume_shape: 3-tuple of int
        The shape of the volume (e.g., whole 3D image)

    point: 1D array of length 3
        The x, y, and z coordinates of the query point. Must lie within the volume. This is the point around which the neighborhood will be computed.

    n: int >= 0
        The neighborhood size (in every direction, the neighborhood is always square). For 0, only the index of the point itself will be returned. For 1, the 26 neighbors in distance 1 plus the index of the point itself (so 27 indices) will be returned. If the point is close to the border of the volume, only the valid subset will be returned of course. For n=2 you get (up to) 125 indices.

    Returns
    -------
    xstart: int
            The x start index, inclusive.

    xend: int
            The x end index, exclusive.

    ystart: int
            The y start index, inclusive.

    yend: int
            The y end index, exclusive.

    zstart: int
            The z start index, inclusive.

    zend: int
            The z end index, exclusive.

    Examples
    --------
    >>> volume = np.zeros((3, 3, 3))
    >>> point = [2, 2, 2]
    >>> xstart, xend, ystart, yend, zstart, zend = st.get_n_neighborhood_start_stop_indices_3D(volume.shape, point, 1)    # 1-neighborhood
    """
    vx = volume_shape[0]
    vy = volume_shape[1]
    vz = volume_shape[2]

    # now set valid ones to 1
    xstart = max(0, point[0]-n)
    xend = min(point[0]+1+n, vx)
    ystart = max(0, point[1]-n)
    yend = min(point[1]+1+n, vy)
    zstart= max(0, point[2]-n)
    zend = min(point[2]+1+n, vz)
    return xstart, xend, ystart, yend, zstart, zend