title: OpenCV: find small dark(black) dots inside a circle
body: <p>I am trying to detect the circles that are black dots or have black dots in them(the ones that I pointed with arrow in the following image). 
  <a href="https://i.stack.imgur.com/rMDzj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rMDzj.png" alt="enter image description here"></a></p>
  
  <p>My current approach is to use HoughCircles function in OpenCV in order to detect the circles with a radius greater than 2 pixels. My question for the community is: let's say I detect these circles(as shown bellow), how can I separate the circles that I pointed with <strong>arrows</strong> from the rest. The circles pointed with arrow are the circles of my interest, the ones that have black/dark color in them. The pink highlights are the ones that HoughCircles detected. Also, I added the arrows myself in order to show the circle of my interest.</p>
  
  <p><a href="https://i.stack.imgur.com/OE4KM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OE4KM.png" alt="enter image description here"></a></p>
  
  <p>Here is the python code that I've been using. Here is the <a href="https://www.dropbox.com/sh/xtvxvup2gt7fwp6/AACR2QS7v5YREo6zfeYKacG9a?dl=0" rel="nofollow noreferrer">link</a> to the image in case you want to try it.</p>
  
  <pre><code>import sys
  import cv2 as cv
  import numpy as np
  import math
  filename = '72471_125_df.jpg'
  src = cv.imread("72471_125_df.jpg", cv.IMREAD_COLOR)
  gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
  gray = cv.medianBlur(gray, 3)
  # Inverse ratio of the accumulator resolution to the image resolution. For example, if dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has half as big width and height.
  accum_size = 1
  # Minimum distance between the centers of the detected circles.
  minDist = 30
  #First method-specific parameter. In case of CV_HOUGH_GRADIENT , it is the higher threshold of the two passed to the Canny() edge detector (the lower one is twice smaller).
  param1 = 50
  # Second method-specific parameter. In case of CV_HOUGH_GRADIENT , it is the accumulator threshold for the circle centers at the detection stage. The smaller it is, the more false circles may be detected. Circles, corresponding to the larger accumulator values, will be returned first.
  param2 = 5
  #
  minRadius = 1
  # 
  maxRadius = 10
  circles = cv.HoughCircles(gray, cv.HOUGH_GRADIENT, accum_size, minDist,
                             param1=param1, param2=param2,
                             minRadius=minRadius, maxRadius=maxRadius)
  circles = circles.reshape(1,circles.shape[1], circles.shape[2])
  if circles is not None:
      circles = np.uint16(np.around(circles))
      for ind, i in enumerate(circles[0, :]):
          center = (i[0], i[1])
          radius = 15
          cv.circle(src, center, radius, (255, 0, 255), 3)
  
  cv.imwrite("modif_"+filename,src)
  </code></pre>
  
  <p>Note that, I did use the configuration in which <code>minRadius = 2</code> and <code>maxRadius = 5</code> however it did not give me the circles with black/dark dots in them. For some reason it returns other circles as well. Also, I did try the thresholding approaches, however it was not robust under all lighting conditions. Please refer to this <a href="https://www.dropbox.com/sh/xtvxvup2gt7fwp6/AACR2QS7v5YREo6zfeYKacG9a?dl=0" rel="nofollow noreferrer">link</a> in order to observe images of different lighting conditions.</p>