title: Convert picture to B&W with specific rules
body: <p>I am trying to analyze a picture. I am basically doing that in 2 steps:</p>
  
  <ol>
  <li>converting it into a greyscale picture</li>
  <li>taking areas in the picture and look if they are more likely white or black</li>
  </ol>
  
  <p>My program works quite well in most cases but not all. That is mainly because I never really understood, how to convert the picture into black and white. I mainly copied code I found and made it work with trial and error(that's why I ended up, with greyscale and not b/w, since I didn't find, how to make every non-white pixel in the greyscale to black)</p>
  
  <p>I am using PIL for my picture operations and my main functions for the picture operating look like this(convert() is used once and avgcol() is used for every part of the converted picture, I want to analyze)</p>
  
  <pre><code>def convert():
      global im   
      matrix = (1.412453, 0.357580, 0.180423, 0,
             0.212671, 0.715160, 0.072169, 0,
             0.019334, 0.119193, 0.950227, 0 )
      im = im.convert("L", matrix)
  
  def avgcol(im):
      p_colors=im.getcolors()
      cnt_pix=(im.size[0])*(im.size[1])
      avgpix=0
      for i in range(len(p_colors)):
          avgpix=avgpix+p_colors[i][0]*p_colors[i][1]
      return round(avgpix/cnt_pix  , 1)
  </code></pre>
  
  <p>I do not really know, what the matrix does(didn't find a site, which explains the single values).
  My specific problem right now, is that I'd like to convert pixels with too much green into white pixels, but I am pretty sure, that if that is solved, something else pops out, so some basic explaining, how something like that is done, would be great.
  But I am thankful for any pointer in the right direction. 
  And please no solution with for-looping every pixel. The pictures are pretty big and the program should be fast.</p>