I have an image that contains noisy objects and I want to distinguish them with cv2. Here is the image: https://i.stack.imgur.com/rJr2g.jpg. My code should detect the three white dots from the image. So the output should be something like this: https://i.stack.imgur.com/NfjFm.png. However, the two noisy dots are so close to each other that the code sees them as one large object: https://i.stack.imgur.com/5G0oz.jpg.

Here is my code:

import cv2
import tkinter.filedialog as fd

def process(image):
    bil = cv2.bilateralFilter(image, 20, 75, 175, cv2.BORDER_REFLECT)
    grey = cv2.cvtColor(bil, cv2.COLOR_BGR2GRAY)
    bw = cv2.threshold(grey, 0, 255, cv2.THRESH_BINARY|cv2.THRESH_OTSU)[1]
    return bw

def main():
    filepath = fd.askopenfilename()
    image = cv2.imread(filepath)
    final = process(image)
    cv2.imshow("Image", final)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

main()

I haven’t been able to solve this problem. I came across something called CLAHE, and I tried to make a function but this does not work correctly:

def use_clahe(image):
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    clahe = cv2.createCLAHE(clipLimit=5)
    apply_clahe = clahe.apply(gray)
    dots = apply_clahe + 30
    bw = cv2.threshold(dots, 0, 255, cv2.THRESH_BINARY|cv2.THRESH_OTSU)[1]
    return bw

This creates an image that contains a lot of noise and the dots are labeled black. However, I want them to be white and the background should be completely black. How could I fix this?