Thread: simple quantizing

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    1

    simple quantizing

    I'm trying to do scaled quantizing on a 8 bit image.
    I get input int:bits, which is 1-8 and the intensity of every pixel, 0-255.
    I need to scale and quantize it.

    Example:
    bits = 1 // = 2 colors
    pixlesin[0] = 129
    // will make the out to 255
    pixlesout[0] = 255 // while 129 is closer to 255 than 0

    bits = 2 // = 4 colors
    pixlesin[1] = 24
    // will make the out to 0
    pixlesout[1] = 0 // while 24 is closer to 0 than 85,170,255

    and so on...
    how can i make a nice formula for this? (without if and switch..)

  2. #2
    Registered User fischerandom's Avatar
    Join Date
    Aug 2005
    Location
    Stockholm
    Posts
    71
    Code:
    unsigned char   out, mask;
    
    #define BITS     8
    mask = ~0 << ( BITS -bits );
    out = pixlesin[ n ] & mask;
    I haven't tested this, so it may be wrong but this may give you an idéa at least.
    Bobby Fischer Live Radio Interviews http://home.att.ne.jp/moon/fischer/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM