title: Problems with using a rough greyscale algorithm?
body: <p>So I'm designing a few programs for editing photos in <code>python</code> using <code>PIL</code> and one of them was converting an image to greyscale (I'm avoiding the use of any functions from <code>PIL</code>).</p>
  
  <p>The algorithm I've employed is simple: for each pixel (colour-depth is 24), I've calculated the average of the <code>R</code>, <code>G</code> and <code>B</code> values and set the RGB values to this average.</p>
  
  <p>My program was producing greyscale images which seemed accurate, but I was wondering if I'd employed the correct algorithm, and I came across <a href="https://stackoverflow.com/a/12201744/7908770">this answer</a> to a question, where it seems that the 'correct' algorithm is to calculate <code>0.299 R + 0.587 G + 0.114 B</code>.</p>
  
  <p>I decided to compare my program to this algorithm. I generated a greyscale image using my program and another one (using the same input) from <a href="https://pinetools.com/grayscale-image" rel="noreferrer">a website online</a> (the top Google result for <code>'image to grayscale'</code>.</p>
  
  <p>To my naked eye, it seemed that they were exactly the same, and if there was any variation, I couldn't see it. However, I decided to use <a href="https://online-image-comparison.com/" rel="noreferrer">this website</a> (top Google result for <code>'compare two images online'</code>) to compare my greyscale images. It turned out that deep in the pixels, they had slight variations, but none which were perceivable to the human eye at a first glance (differences can be spotted, but usually only when the images are laid upon each other or switched between within milliseconds).</p>
  
  <p><strong>My Questions (the first is the main question)</strong>: </p>
  
  <ol>
  <li><strong>Are there any disadvantages to using my 'rough' greyscale algorithm?</strong></li>
  <li><strong>Does anyone have any input images where my greyscale algorithm would produce a visibly different image to the one that would be 'correct' ?</strong></li>
  <li><strong>Are there any colours/RBG combinations for which my algorithm won't work as well?</strong></li>
  </ol>
  
  <p>My key piece of code (if needed):</p>
  
  <pre><code>def greyScale(pixelTuple):
      return tuple([round(sum(pixelTuple) / 3)] * 3)
  </code></pre>
  
  <p>The 'correct' algorithm (which seems to heavily weight green):</p>
  
  <pre><code>def greyScale(pixelTuple):
      return tuple([round(0.299 * pixelTuple[0] + 0.587 * pixelTuple[1] + 0.114 * pixelTuple[2])] * 3)
  </code></pre>
  
  <p>My input image:
  <a href="https://i.stack.imgur.com/7rtQk.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/7rtQk.jpg" alt="My input image"></a></p>
  
  <p>The greyscale image my algorithm produces:
  <a href="https://i.stack.imgur.com/FvYYq.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/FvYYq.jpg" alt="The greyscale image my algorithm produces"></a></p>
  
  <p>The greyscale image which is 'correct':
  <a href="https://i.stack.imgur.com/jECAG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jECAG.png" alt="The greyscale image which is &#39;correct&#39;"></a></p>
  
  <p>When the greyscale images are compared online (highlighted red are the differences, using a fuzz of 10%):
  <a href="https://i.stack.imgur.com/kgCMN.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/kgCMN.jpg" alt="When the greyscale images are compared online (highlighted red are the differences, using a fuzz of 10%)"></a></p>
  
  <p>Despite the variations in pixels highlighted above, the greyscale images above appear as nearly the exact same (at least, to me).</p>
  
  <p>Also, regarding my first question, if anyone's interested, <a href="http://www.tannerhelland.com/3643/grayscale-image-algorithm-vb6/" rel="noreferrer">this site</a> has done some analysis on different algorithms for conversions to greyscale and also has some custom algorithms.</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>In response to @Szulat's answer, my algorithm <strong>actually</strong> produces this image instead (ignore the bad cropping, the original image had three circles but I only needed the first one):</p>
  
  <p><a href="https://i.stack.imgur.com/GIFDX.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GIFDX.png" alt="This is what my algorithm **actually** produces"></a></p>
  
  <p>In case people are wondering what the reason for converting to greyscale is (as it seems that the algorithm depends on the purpose), I'm just making some simple photo editing tools in <code>python</code> so that I can have a mini-Photoshop and don't need to rely on the Internet to apply filters and effects.</p>
  
  <p><strong>Reason for Bounty</strong>: Different answers here are covering different things, which are all relevant and helpful. This makes it quite difficult to choose which answer to accept. I've started a bounty because I like a few answers listed here, but also because it'd be nice to have a single answer which covers everything I need for this question.</p>