def get_pixel_neighbors(height, width):
    """
    Estimate the 4 neighbors of every pixel in an image
    :param height: image height
    :param width: image width
    :return: pixel index - neighbor index lists
    """

    pix_id = []
    neighbor_id = []
    for i in range(height):
        for j in range(width):

            n = []
            if i == 0:
                n = n + [(i + 1) * width + j]
            elif i == height - 1:
                n = n + [(i - 1) * width + j]
            else:
                n = n + [(i + 1) * width + j, (i - 1) * width + j]

            if j == 0:
                n = n + [i * width + j + 1]
            elif j == width - 1:
                n = n + [i * width + j - 1]
            else:
                n = n + [i * width + j + 1, i * width + j - 1]

            for k in n:
                pix_id.append(i*width+j)
                neighbor_id.append(k)

    return pix_id, neighbor_id