How to remove outer line of a binary images?
12:50 13 Jun 2023

I am trying to find the optic disc in fundus images by using extracting the vessels and marking their center pixel.

This is what my code looks like:

 # Read the image and resize it to 800x800 pixels to reduce the computation time and memory usage
    img = load_image(file)
    blur = cv2.bilateralFilter(img, 9, 75, 75)
    median = cv2.medianBlur(blur, 5)
    # Extract the vessels from the image using the sato filter and normalize the image
    vessels = sato(median, sigmas=range(1, 10, 2), black_ridges=False)
    vessels = (vessels - np.min(vessels)) / (np.max(vessels) - np.min(vessels))
    vessels = vessels * 255
    vessels = vessels.astype(np.uint8)
    _, binary = cv2.threshold(vessels, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    skeleton = morphology.skeletonize(binary)
    g, nodes = graph.pixel_graph(skeleton, connectivity=2)
    px, distances = graph.central_pixel(g, nodes=nodes, shape=skeleton.shape, partition_size=100)

Here is how original image looks like: Original Image And the skeleton Skeletonized Image

Obviously the outer part of the image is artifact and it completely messes the calculation to find the center of the vessels.

I was wondering how can I solve this issue.

The blue areas needs to be gone

python numpy opencv image-segmentation medical