4

I have fundus images which are pictures of the retina which have already been processed, and I am looking at and am trying to remove the smaller blood vessels using morphological erosion. This appears to have worked in several of the papers I have read but the details of the exact operators are not included.

I have tried various approaches, morphological opening, morphological erosion then closing, I did a little bit of hit or miss. All of my work was done using the openCV2 python library.

This is the original image. original

def erode(image):
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,2))
    erosion = cv2.morphologyEx(image, cv2.MORPH_OPEN, kernel, iterations=1)
    erosion = cv2.erode(erosion, kernel, iterations=1)
    return erosion

After morphological erosion and opening:

After processing

I am hoping to get more blood vessels removed while still retaining the thicker ones, does anyone have any good ideas for me to try? Or perhaps I am approaching the morphology incorrectly?

nathancy
  • 42,661
  • 14
  • 115
  • 137
  • 1
    How do you define “noise”? Erosion does one specific mathematical operation, it does not create. It does leave behind some pixels you don’t want, which you could remove. – Cris Luengo Aug 31 '19 at 14:17
  • 1
    For example you could remove small connected components after the erosion and before the matching dilation. This would be a type of opening, likely better behaved in this case than the structural opening you’ve tried. – Cris Luengo Aug 31 '19 at 14:23
  • After erosion to the limit you can tolerate, use contours to find and remove the small remainders. – fmw42 Aug 31 '19 at 18:35
  • I probably should have worded it better, what I meant is it causes noise by leaving pixels I do not want. @CrisLuengo , how would I remove those smaller connected components? And fmw42 do you have any resources about how this would be done as its the first time ive heard this suggestion. – Number CRUSHER Sep 01 '19 at 01:05
  • Use an area opening to remove the small connected components. – Cris Luengo Sep 03 '19 at 21:36

2 Answers2

2

enter image description here

I think you have the right approach but just need to apply additional filtering. After eroding, you can find contours and filter using contour area. If the area is smaller than some threshold area, you can color in the contour to effectively remove the smaller vessels. The kernel size, iterations in cv2.morphologyEx(), and threshold area can be tuned to remove more or less of the blood vessels. But be careful to not increase the kernel dimensions too much as there is a trade off: The larger the kernel, the more detail is removed

import cv2

image = cv2.imread('1.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 120, 255, cv2.THRESH_BINARY)[1]
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
opening = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel, iterations=1)

cnts = cv2.findContours(opening, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    area = cv2.contourArea(c)
    if area < 100:
        cv2.drawContours(opening, [c], -1, (0,0,0), -1)

cv2.imshow('thresh', thresh)
cv2.imshow('opening', opening)
cv2.waitKey()
nathancy
  • 42,661
  • 14
  • 115
  • 137
1

Try increasing the number of erosion iterations, so that the smaller vessels get completely removed. Then perform morphological dilations by the same number of iterations, so that the remaining large vessels are resized back to (approximately) their original size.

jfaccioni
  • 7,099
  • 1
  • 9
  • 25
  • 1
    This is an opening. OP said they tried that and didn’t like the results. – Cris Luengo Aug 31 '19 at 14:19
  • An opening is an erosion immediately followed by a dilation. What I suggested is to repeatedly erode N times, and only then dilate N times. This is different since smaller particles will get completely eroded and won't appear on the final image after dilation. – jfaccioni Aug 31 '19 at 14:37
  • 1
    N erosions is the same as one erosion with a larger structuring element. – Cris Luengo Aug 31 '19 at 14:44
  • Thank you for the timely response jfaccioni but ive tried this and it results in a very skewed image as it does have the behaviour that cris has explained. A large morphological erosion will ruin the structure of the image, and this is not something we can fix with a dilation. – Number CRUSHER Sep 01 '19 at 01:08