'detect defects which are grayish in color from the image

I need to detect the defects which are more grayish in color. I have tried removing noise from the image, thresholding the image but due to gray color of the defect, it becomes invisible or only the boundary remains. I don't know how to detect the defects , if I apply dilation it gets mixed with the surrounding circles. Images with defects: enter image description here

Images without defect:

enter image description here

My original image with the red pen marked defect is :

enter image description here

I have tried the below code:

//convert to grayscale
    Mat gray_img;
    cv::cvtColor(r_img, gray_img, COLOR_BGR2GRAY);

    
    Mat dst1, dst2, dst;
    cv::blur(gray_img, dst1, Size(3, 3));
    cv::blur(gray_img, dst2, Size(7, 7)); 
    cv::subtract(dst1, dst2, dst);

    //thresholding
    Mat thresh;
    adaptiveThreshold(dst, thresh, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 5, 5);

    Mat inv_thresh;
    bitwise_not(thresh, inv_thresh);

    

My thresholded image is

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source