Convert Bitmap to B&W - C Programming Tips

  • Thread starter Thread starter noblerare
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around methods for converting a colored bitmap image to a black and white (B&W) rendition using C programming techniques. Participants explore various approaches, including basic averaging and more sophisticated weighted methods based on perceived brightness.

Discussion Character

  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • One participant suggests that a simple method to convert a bitmap to B&W is to take the average of the RGB values.
  • Another participant proposes a more advanced method using the formula R*0.299 + G*0.587 + B*0.114 to achieve a better approximation of apparent brightness.
  • A later reply questions the reasoning behind the coefficients used in the advanced method.
  • One participant explains that the coefficients are based on the sensitivity of the human eye and are derived from ITU-R recommendation 601.
  • Another participant seeks clarification on whether averaging the RGB values would indeed yield a B&W image and asks for an explanation of the process.
  • A response clarifies that a color image can be viewed as three layers of grayscale images, and that the conversion involves taking a weighted average of these layers.
  • A participant shares a link to a tutorial that may provide additional insights into converting color images to grayscale.

Areas of Agreement / Disagreement

Participants present multiple methods for converting images to B&W, with some favoring the simple average approach and others advocating for the weighted method. The discussion remains unresolved regarding the best approach, as different perspectives are offered without consensus.

Contextual Notes

There are assumptions regarding the effectiveness of the methods discussed, and the discussion does not resolve the mathematical steps involved in the conversion process.

noblerare
Messages
49
Reaction score
0
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
 
Technology news on Phys.org
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.
 
hamster143 said:
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.

That's interesting. Is there some explanation behind the magic numbers?
 
DavidSnider said:
That's interesting. Is there some explanation behind the magic numbers?

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.
 
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?
 
noblerare said:
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?

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;
 

Similar threads

  • · Replies 21 ·
Replies
21
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
6K
Replies
1
Views
14K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
4K