title: Numpy doesn't count pixels in image correctly
body: <p>I'm trying to count black and white pixels in an image with Numpy and OpenCV. However, the final count doesn't match the real value. By using the following image (4x4):</p>
  <p><a href="https://i.stack.imgur.com/VzJlOb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VzJlOb.png" alt="enter image description here" /></a></p>
  <p>In the following code:</p>
  <pre><code># importing libraries
  import cv2
  import numpy as np
  from math import *
  
  path = &quot;pictures/test.png&quot;
  
  # reading the image data from desired directory
  img = cv2.imread(path)
  cv2.imshow('Image', img)
  
  height, width, color = img.shape
  
  # counting the number of pixels
  number_of_white_pix = np.sum(img == 255)
  number_of_black_pix = np.sum(img == 0)
  
  
  def phase():
      white = number_of_white_pix
      black = number_of_black_pix
      phaseper = white/(white+black)
      print(white)
      print(black)
      return phaseper
  
  print(phase())
  </code></pre>
  <p>I get the following output:</p>
  <pre><code>9
  36
  0.2
  
  Process finished with exit code 0
  </code></pre>
  <p>Which means it counted 9 white pixels and 36 black pixels, which is clearly wrong, as it can be seen from the image that the correct number is 3 white and 13 pixels (for a total of 4x4 = 16 pixels). Since the code is not giving any errors and doesn't seem to be wrong, I do not know what is going on.</p>