Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Make a Bitmap B&W

  1. Nov 1, 2009 #1
    Hi,

    I was recently introduced to image manipulations and bit processing in my C programming class. I am pretty interested in the many creative ways an image can be encrypted and manipulated.

    I was wondering, does anyone know of a way to change a given bitmap into a black and white rendition of the original colored image?

    What do we do to the bytes?

    Thanks!

    Samuel
     
  2. jcsd
  3. Nov 1, 2009 #2
    The easy way is to take an average.

    The more advanced way is to weigh them as R*0.299 + G*0.587 + B*0.114, this would result in a better approximation of apparent brightness.
     
  4. Nov 2, 2009 #3

    DavidSnider

    User Avatar
    Gold Member

    That's interesting. Is there some explanation behind the magic numbers?
     
  5. Nov 2, 2009 #4
    I don't know all the details, but these are the standard coefficients used to convert RGB to YUV, and presumably they are based on sensitivity of the human eye to different bandwidths. These numbers are present in ITU-R recommendation 601 (dating to 1982) and they are most likely older than that, possibly as old as color television.
     
  6. Nov 3, 2009 #5
    So are you saying that if I take the average of the RGB values in each pixel and assign the average to each RGB value, that I would get a B&W rendition of the original image?

    How exactly does that work?
     
  7. Nov 3, 2009 #6

    DavidSnider

    User Avatar
    Gold Member

    Try thinking of it this way: A color picture is 3 layers of greyscale images that specify the red green and blue components. All you are doing is taking a weighted average of the layers.

    Average = Original.R*0.299 + Original.G*0.587 + Original.B*0.114;
    New.R = Average ; New.G = Average ; New.B = Average;
     
  8. Nov 4, 2009 #7
    Last edited by a moderator: Apr 24, 2017
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook