Compute if the two given value's pixels have connectivity

    Compute if the two given value's pixels of raster have connectivity between
    the [i.j]pixel and its 8-neighborhood. If they have connectivity,
    then put its neighborhood to List idx and go in a recursion. If the  [i,
    j]pixel and its neighborhood don't have connectivity, do nothing.

    Args:
        raster: A rasterfile stored pixels initial values.
        i: The pixel's x coord.
        j: The pixel's y coord.
        idx: A List stored pixels which have the same ID(means same that
        these pixels have connectivity)

def pixels_connectivity_compute(raster, i, j, idx):
    """Compute if the two given value's pixels have connectivity

    Compute if the two given value's pixels of raster have connectivity between
    the [i.j]pixel and its 8-neighborhood. If they have connectivity,
    then put its neighborhood to List idx and go in a recursion. If the  [i,
    j]pixel and its neighborhood don't have connectivity, do nothing.

    Args:
        raster: A rasterfile stored pixels initial values.
        i: The pixel's x coord.
        j: The pixel's y coord.
        idx: A List stored pixels which have the same ID(means same that
        these pixels have connectivity)
    """
    nrows, ncols = raster.shape
    value = raster[i][j]
    for di in [-1, 0, 1]:
        for dj in [-1, 0, 1]:
            if 0 <= i + di < nrows and 0 <= j + dj < ncols:
                if raster[i + di][j + dj] == value and not (di == dj and di == 0):
                    if [i + di, j + dj] not in idx:
                        idx.append([i + di, j + dj])
                        pixels_connectivity_compute(raster, i + di, j + dj, idx)