def GetNeighbors(row, col, x, y) :

    """ This function gives 8 connected neighbors of a pixel."""

    neighbors = [ [x-1,y-1], [x-1,y], [x-1, y+1], [x, y-1], [x, y+1], [x+1, y-1], [x+1, y], [x+1, y+1]  ]
    neighbors = [[p,q] for p,q in neighbors if p>=0 and p<row and q >=0 and q<col  ]

    return neighbors