Thread: Classify No of different values

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    224

    Smile Classify No of different values

    Hi,

    What is the most efficient way for me to:

    Here is the Background info,
    I'm getting the hue info of every pixel in a BMP using a standard nested for loop to access the i,j pixel.
    What I want to do:
    Find out how many different Hue's I have (Obviously in the range of 0 and 360) and keep the value of the hue for the different hues in the image.

    Thats it.

    Additionally, I realise that I could have a very large range of hues since it is in float format. Thus, I would like to be able to classify hue's within 5 degrees as the same.

    :S

    Anyone have any ideas how I might do this???


    Thanks

  2. #2
    Registered User
    Join Date
    Nov 2006
    Posts
    224
    After further thought,

    It would be nice to group visually similar colours, such as the 256 most unique colours. How would I go about this?

    Any Ideas?

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    I'm assuming you've got some hue function which returns the hue in degrees - since you mentioned 360.

    Create an array of 256 entries... initialized to zeros. Then for each hue pixel add one to the particular array element indicated by a hue. Degrees * 256 / 360 to get the index. This will give you counts of each of course.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    224

    Cool

    Thanks for your reply.

    If I take up your idea...

    Degrees * 256 / 360 = index

    Lets say I have only 3 different colours from all of the pixels in an image.
    [eg, 25% of pixels, index = 113; 25% of pixels, index = 200, 50% of pixels, index = 225]

    From having only 3 different colours, the grey scaling would best be set as:
    R,G,B = 0, for one colour, 128 for another and 255 for the last.

    How would I be able to find out how many different colours there are in the image and then from that be able to then set an evenly distributed grey scale for each individual pixel????

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    224
    How can I translate my hue value so that, for example, I can start with purple at zero degrees and end at blue (360)????

    Because normally, it would being with red (0 degrees) and end with red (360 deg)

    http://dba.med.sc.edu/price/irf/Adob...es/hsl_top.JPG

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Add an offset such that 0 = purple, then use mod to bring it back to 0..359 [I presume the actual range is 0..359, not 0..360?]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    A quick search found the following: how to convert different color space models:
    Converting between RGB and CMY, YIQ, YUV

    You want "Calculate HSL from RGB" - there is a code example. Hue is in degrees.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  2. Need help with project
    By chrisa777 in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2006, 05:01 PM
  3. Computing Large Values
    By swbluto in forum C++ Programming
    Replies: 8
    Last Post: 04-07-2005, 03:04 AM
  4. Replies: 1
    Last Post: 02-03-2005, 03:33 AM
  5. ascii values for keys
    By acid45 in forum C Programming
    Replies: 2
    Last Post: 05-12-2003, 07:13 AM