title: Why would cv2.COLOR_RGB2GRAY and cv2.COLOR_BGR2GRAY give different results?
body: <p>I always thought that converting an image from colored to grayscale is simple: intensity of each pixel would be an average of intensities of each color channel. But I noticed that <code>cv2.COLOR_RGB2GRAY</code> and <code>cv2.COLOR_BGR2GRAY</code> give different results. When I was experimenting with them I also found that it would also be  different from the average of intensities of each color channel.</p>
  <p>P.S. I was completely baffled when I found that</p>
  <pre><code>img_read_as_color[:,:,0]/3+img_read_as_color[:,:,1]/3+img_read_as_color[:,:,2]/3 == (img_read_as_color[:,:,0]+img_read_as_color[:,:,1]+img_read_as_color[:,:,2])/3
  </code></pre>
  <p>but when shown as immage</p>
  <pre><code>(img_read_as_color[:,:,0]+img_read_as_color[:,:,1]+img_read_as_color[:,:,2])/3
  </code></pre>
  <p>would look like</p>
  <pre><code>img_read_as_color[:,:,0]+img_read_as_color[:,:,1]+img_read_as_color[:,:,2]
  </code></pre>
  <p>Can someone explain to me why this is happening?</p>
  <p>My full code:</p>
  <pre><code>import matplotlib.pyplot as plt
  import cv2
  
  sample = r'G:\Python\knight-mare\screenshots\2020-07-12-02-40-44.jpg'
  img_read_as_grayscale = cv2.imread(sample, cv2.IMREAD_GRAYSCALE)
  img_read_as_color = cv2.imread(sample, cv2.IMREAD_COLOR)
  img_RGB_to_grayscale = cv2.cvtColor(img_read_as_color, cv2.COLOR_RGB2GRAY)
  img_BGR_to_grayscale = cv2.cvtColor(img_read_as_color, cv2.COLOR_BGR2GRAY)
  plt.imshow(img_read_as_grayscale)
  plt.title('img_read_as_grayscale')
  plt.show()
  plt.imshow(img_read_as_color)
  plt.title('img_read_as_color')
  plt.show()
  plt.imshow(img_RGB_to_grayscale)
  plt.title('img_RGB_to_grayscale')
  plt.show()
  plt.imshow(img_BGR_to_grayscale)
  plt.title('img_BGR_to_grayscale')
  plt.show()
  
  channel_avg_div_separately = img_read_as_color[:,:,0]/3+img_read_as_color[:,:,1]/3+img_read_as_color[:,:,2]/3
  channel_avg_div_together = (img_read_as_color[:,:,0]+img_read_as_color[:,:,1]+img_read_as_color[:,:,2])/3
  channel_sum = img_read_as_color[:,:,0]+img_read_as_color[:,:,1]+img_read_as_color[:,:,2]
  plt.imshow(channel_avg_div_separately)
  plt.title('channel_avg_div_separately')
  plt.show()
  plt.imshow(channel_avg_div_together)
  plt.title('channel_avg_div_together')
  plt.show()
  plt.imshow(channel_sum)
  plt.title('channel_sum')
  plt.show()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/cyYbA.png" rel="noreferrer"><img src="https://i.stack.imgur.com/cyYbA.png" alt="image read as grayscale" /></a><a href="https://i.stack.imgur.com/qziHD.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qziHD.png" alt="image read as colored" /></a><a href="https://i.stack.imgur.com/jlWRg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jlWRg.png" alt="image read as colored transformed by RGB2GRAY" /></a><a href="https://i.stack.imgur.com/B4lC8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/B4lC8.png" alt="image read as colored transformed by BGR2GRAY" /></a><a href="https://i.stack.imgur.com/Rkkyy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Rkkyy.png" alt="image read as colored, each channel divided by 3 than added together" /></a><a href="https://i.stack.imgur.com/ixHBB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ixHBB.png" alt="image read as colored, all channels added together, then divided by 3 " /></a><a href="https://i.stack.imgur.com/owYOg.png" rel="noreferrer"><img src="https://i.stack.imgur.com/owYOg.png" alt="image read as colored, just adding channels" /></a></p>