title: Converting pixels in grayscale image to black (OpenCV) causes unexpected result?
body: <p>I'm trying to manually mask an image so that only a circular area of the image is visible. I've attempted to accomplish this by specifying the center of the circle and the radius- The distance from the center to each pixel in the image, and if that distance is greater than the radius, I turn that pixel black.</p>
  
  <p>My input image is all white (for testing purposes), and is 6000x4000 px.
  The center is (3224,2032) and radius is 1810 px.</p>
  
  <p>After processing it, I get this poorly masked image</p>
  
  <p><img src="https://i.stack.imgur.com/eJmvR.png" alt=""></p>
  
  <p>Here, the blue circle is the area I expected not to be changed: Expected Result</p>
  
  <p><img src="https://i.stack.imgur.com/uSqnn.png" alt=""></p>
  
  <p>What is going on??</p>
  
  <p>Edit: I switched the indices for xMax and yMax. The change yielded this result</p>
  
  <p><img src="https://i.stack.imgur.com/hl1a7.png" alt=""></p>
  
  <pre><code>import cv2
  def mask (img, Xcenter, Ycenter, radius):
      radius2 = float(radius**2.00)
      Xcenter = float(Xcenter)
      Ycenter = float(Ycenter)
      img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  
      imgSize = img.shape
      xMax = imgSize[0]
      yMax = imgSize[1]
  
      print("Drawing mask...")
  
      for y in range(1,yMax):
          for x in range(1,xMax):
              dist2 = int(((x - Xcenter)**2 + (y - Ycenter)**2))
              try:
                  if dist2 &gt;= radius2:
                      img[x, y] = 0
              except IndexError:
                  pass
                  #print ("Index error: X = ", x, " Y = ", y)
                  #char = input("Press enter to continue")
      cv2.imwrite("maskedImg.tif", img)
      print("Completed mask.")
      return img
  </code></pre>