1
votes

I am new to opencv and I am currently working on 'Diabetic Retinopathy Detection' (a kaggle competition was launched 3 years ago; more details here : https://www.kaggle.com/c/diabetic-retinopathy-detection/data). Currently, I am trying to achieve similar results on image processing as depicted in the image below (source: http://blog.kaggle.com/2015/09/09/diabetic-retinopathy-winners-interview-1st-place-ben-graham/): enter image description here

Now I have tried different approaches including histogram equalization and Contrast Limited Adaptive Histogram Equalization (CLAHE). CLAHE gives the best results so far, but nothing compared to the images above. I got some ideas from here : (How to remove the local average color from an image with OpenCV) but couldn't reproduce the results. If someone can guide me how it can be done with opencv or any other python vision library, it would be great. Sample images can be downloaded from kaggle site (link mentioned above). Thanks.

Here is my code so far:

def equalize_hist(input_path):
    img = cv.imread(input_path)
    for c in range(0, 2):
        img[:,:,c] = cv.equalizeHist(img[:,:,c])

    cv.imshow('Histogram equalized', img)
    cv.waitKey(0)
    cv.destroyAllWindows()

def clahe_rgb(input_path):
    bgr = cv.imread(input_path)
    lab = cv.cvtColor(bgr, cv.COLOR_BGR2LAB)
    lab_planes = cv.split(lab)
    gridsize = 5
    clahe = cv.createCLAHE(clipLimit=2.0,tileGridSize=(gridsize,gridsize))
    lab_planes[0] = clahe.apply(lab_planes[0])
    lab = cv.merge(lab_planes)
    bgr2 = cv.cvtColor(lab, cv.COLOR_LAB2BGR)
    cv.imshow('CLAHE RGB', bgr2)
    cv.waitKey(0)
    cv.destroyAllWindows()


def clahe_greyscale(input_path):
    img = cv.imread(input_path)
    gray_image = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    clahe = cv.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
    cl1 = clahe.apply(gray_image)    
    cv.imshow('CLAHE Grayscale', cl1)
    cv.waitKey(0)
    cv.destroyAllWindows()
1
You should edit your code into the question.balmy
Hi. I have posted my code above.Muhammad Irfan Ali

1 Answers

2
votes

The code you show is doing a local histogram equalization, whereas the highlighted text you posted talks about removing the average color from each pixel.

Removing the average color could be done like this:

# Blur the image
blurred = cv2.blur(img, ksize=(15, 15))

# Take the difference with the original image
# Weight with a factor of 4x to increase contrast
dst = cv2.addWeighted(img, 4, blurred, -4, 128)

You can adjust the kernel size of the blur code (above it's 15) to find something that works for your use case.

You may need to downscale the images to a common size before doing this, to get comparable results (as also noted in the blog post you cite).