Get grey values from pic

This is a discussion on Get grey values from pic within the C++ Programming forums, part of the General Programming Boards category; Hi Is any code in BCB6 for converting pictures pixels values from RGB scale to Grey scale??? Is it possible ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    43

    Get grey values from pic

    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....

  2. #2
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    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

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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

  4. #4
    Registered User
    Join Date
    Oct 2004
    Posts
    151
    What I wrote above is wrong. Desaturation is really just an unweighted average: (R + G + B) / 3. So sue me, I was tired.

    Quote Originally Posted by CornedBee
    I'm not sure about the weighing factors, though I think they are G*0.6, R*0.4, B*0.15.
    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.
    Last edited by zx-1; 10-05-2006 at 09:57 AM.
    System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.

    Useful resources:
    comp.lang.c FAQ | C++ FQA Lite

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  2. Take pixels values from pic with specifiec order
    By Leite33 in forum Windows Programming
    Replies: 6
    Last Post: 11-04-2006, 01:48 PM
  3. Get pixel values from pic
    By Leite33 in forum Windows Programming
    Replies: 4
    Last Post: 09-12-2006, 02:13 PM
  4. Get pixel values from pic
    By Leite33 in forum C++ Programming
    Replies: 0
    Last Post: 09-12-2006, 07:26 AM
  5. Need help with project
    By chrisa777 in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2006, 06:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21