Hot pixel-filtering

How to filter hot pixels as implemented in the IMC Segmentation Pipeline

def filter_hot_pixels(img, thres):
    kernel = np.ones((1, 3, 3), dtype=np.uint8)
    kernel[0, 1, 1] = 0
    max_neighbor_img = maximum_filter(img, footprint=kernel, mode='mirror')
    return np.where(img - max_neighbor_img > thres, max_neighbor_img, img)