Thread: Hi, how to convert a grayscale image into 8 bit image?

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    3

    Smile Hi, how to convert a grayscale image into 8 bit image?

    Hi,

    anyone can tell me how to convert a grayscale image into 8 bit image? I am trying to use CvFindContour function base on OpenCV, the CvFindContour only supports 8 bit unsigned image. Thanks for your help!


    Regards,
    Alexander

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    If you're using Windows, good ole MSPaint will do it for you.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Um....greyscale is an 8-bit image.

    Even though the pixels might be RGB's greyscale means the red=green=blue. So if you just iterate through the data and extract the red's from the DWORD you have your image.

    To create the palette just iterate through and count how many diff colors there are. Just in case you were wondering, there will be exactly 256 colors. It's your job to find them, write the values into the palette data, and then write the file.

    This will extract the values from a DWORD on a 32-bit ARGB.
    #define RED_FROM_ARGB32(color) (BYTE) ( ( (color) & (0xFF0000) )>>(16) )
    #define GREEN_FROM_ARGB32(color) (BYTE) ( ( (color) & (0xFF00) )>> (8) )
    #define BLUE_FROM_ARGB(color) (BYTE) ( (color) & (0xFF) )

    And this will make an ARGB
    #define ARGB(r,g,b,alpha) (DWORD) ( ( (alpha)<<(24)) + ((r)<<(16)) + ((g)<<(8)) + (b) )

    This will make an ARGB into a greyscale value.

    int value=(int)((red+green+blue)/3);
    ARGB(value,value,value,0);
    Last edited by VirtualAce; 03-15-2005 at 09:05 AM.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    3
    Sorry, friends, I made a mistake. My picture is opened from my E:\pictures file and it is .bmp format. After using threshod base on OpenCV , I try to use CvFindContour but it says it only support " 8uc1 image ". Do not know why.

    Regards,
    Alexander

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Yahoo's sign-in seal technology
    By George2 in forum Tech Board
    Replies: 12
    Last Post: 09-21-2006, 07:29 AM
  2. how to convert a bitmap image to a jpg image file using C++?
    By nomer in forum Windows Programming
    Replies: 4
    Last Post: 06-04-2006, 07:40 PM
  3. Convert Pdf to Image format!
    By Dilmerv in forum C# Programming
    Replies: 4
    Last Post: 05-22-2006, 10:31 PM
  4. Converting 24bits RGB to 8 bit Grayscale
    By FearOfTheDark in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-29-2003, 06:17 AM
  5. binary numbers
    By watshamacalit in forum C Programming
    Replies: 4
    Last Post: 01-14-2003, 11:06 PM