title: How to efficiently loop over an image pixel by pixel in python OpenCV?
body: <p>What I want to do is to loop over an image pixel by pixel using each pixel value to draw a circle in another corresponding image.
  <a href="https://i.stack.imgur.com/KQrLS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KQrLS.png" alt="enter image description here" /></a>
  My approach is as follows:</p>
  <pre><code>it = np.nditer(pixels, flags=['multi_index'])
  while not it.finished:
      y, x = it.multi_index
      color = it[0]
      it.iternext()
      center = (x*20 + 10, y*20 + 10) # corresponding circle center
      cv2.circle(circles, center, int(8 * color/255), 255, -1)
  </code></pre>
  <p>Looping this way is somewhat slow. I tried adding the @njit decorator of numba, but apparently it has problems with opencv.</p>
  <p>Input images are 32x32 pixels
  They map to output images that are 32x32 circles
  each circle is drawn inside a 20x20 pixels square
  That is, the output image is 640x640 pixels</p>
  <p>A single image takes around 100ms to be transformed to circles, and I was hoping to lower that to 30ms or lower</p>
  <p>Any recommendations?</p>