Hi
Is any code in BCB6 for converting pictures pixels values from RGB scale to Grey scale??? Is it possible that in BCB6 with code?
i used code
Image1->Picture->Canvas->GetPixels[x][y];
so i took RGB values with code i think....
Hi
Is any code in BCB6 for converting pictures pixels values from RGB scale to Grey scale??? Is it possible that in BCB6 with code?
i used code
Image1->Picture->Canvas->GetPixels[x][y];
so i took RGB values with code i think....
The quick and dirty way is to convert RGB to HSV and take the saturation component:
Let MAX be the maximum of (R,G,B) and MIN be the minimum.
Let C be the channel depth (e.g. 256 for 24-bit color).
S = 0 if MAX == 0.
S = 1 - (MIN / MAX) otherwise.
Z = S * C
Replace the pixel with one having RGB values of (Z, Z, Z).
Here's some more info on the subject, such as how to do higher-quality conversions: http://www.cambridgeincolour.com/tut...lack-white.htm
System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.
Useful resources:
comp.lang.c FAQ | C++ FQA Lite
An even quicker and dirtier way is to take a weighted average of red, green and blue. This is the same as converting to HSV, except that you don't bother to calculate hue and value.
I'm not sure about the weighing factors, though I think they are G*0.6, R*0.4, B*0.15.
Even quicker is to take an unweighted average, but that does not fit the way the human eye perceives brightness.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
What I wrote above is wrong. Desaturation is really just an unweighted average: (R + G + B) / 3. So sue me, I was tired.
That's the Y componenet of the NTSC YIQ, so it'll end up looking pretty much like what a B&W TV would show. If you want to get technical it's R*0.299 + G*0.587 + B*0.114.Originally Posted by CornedBee
Last edited by zx-1; 10-05-2006 at 08:57 AM.
System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.
Useful resources:
comp.lang.c FAQ | C++ FQA Lite