CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: color counting

  1. #1
    Join Date
    Jun 2007
    Posts
    7

    color counting

    I know this is probably out of your scope, but since you've been so helpful...

    I was wondering if I can just count the number of colors in a window.

    it's a matlab project and my best bet is to find the more colorful as appose to a more homogeneous surrounding...

    the images vary, so I can't just pick a color (or sum a no. of detections...)

    any ideas??

  2. #2
    Join Date
    Dec 2001
    Location
    Greece, Athens
    Posts
    1,015

    Re: color counting

    Can you give some more details? "my best bet is to find the more colorful as appose to a more homogeneous surrounding": I am not sure I get this question. Do you simply want to count how many different colors are used in an image? If yes, you can compute the histogram of each image and then count the non-zero histogram bins. Or you can extract a statistic out of the histogram, like the standard deviation, in order to have a measurement of the colors' variation.
    Theodore
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak

  3. #3
    Join Date
    Jun 2007
    Posts
    7

    Re: color counting

    here are 2 of the examples.


    there are 64 of those...

    if you have a better idea please share.

    I was thinking of dividing the image check the no. of colors in each segment and according to it erase data...

    a sort of quad tree and then process
    Attached Images Attached Images
    Last edited by mwg; June 28th, 2007 at 08:19 AM.

  4. #4
    Join Date
    Dec 2001
    Location
    Greece, Athens
    Posts
    1,015

    Re: color counting

    Quote Originally Posted by mwg
    I was thinking of dividing the image check the no. of colors in each segment and according to it erase data...

    a sort of quad tree and then process
    I am not sure I get your idea (erase what data?). And if you want simply to count the colors used in an image, what's wrong in using a color histogram and count the NON-ZERO histogram bins (or better the beans whose values are above a specific dynamic threshold???)
    Theodore
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak

  5. #5
    Join Date
    Jun 2007
    Posts
    7

    Re: color counting

    when I said erase data I meant sort of a filter to get only the part that interests me (colorful).

    "And if you want simply to count the colors used in an image, what's wrong in using a color histogram and count the NON-ZERO histogram bins (or better the beans whose values are above a specific dynamic threshold???)"

    Nothing. I just want to do it with a window over the image (blocks of matrix) rather than the entire image. devide to section, count colors and filter.

    could be I'm just complicating things...
    kinda new to this..

    <:-|

  6. #6
    Join Date
    Oct 2006
    Posts
    616

    Re: color counting

    Can you describe your FINAL goal ?

    What do you want to achieve ?

    Given an input image like the one you attached, what is the sort of output you are looking for ?
    - A processed image ?
    - The number of colors in the image ?
    - Something else ?

    It's hard to try and help you find a solution without understanding what you want to achieve.

    BTW, if you goal is just to count the number of different colors in the image, trying to seperate the image into blocks and such is way too complicated than the straight forward solution yiannakop suggested.

    Best of luck,

    Zachm

  7. #7
    Join Date
    Jun 2007
    Posts
    7

    Re: color counting

    Hello zachm,

    My final goal is to detect the colored ball (magenta with green & yellow) in a picture. to do this I got 30 pictures to get the data from and test on.

    these are the 2 less complex. the pictures are taken from a variaty of distance, lighting conditions etc. and the ball is in a variety of backgrounds- bushes, desk, chairs, wastebin etc. etc.

    my approach is to focus on the colorful area which interests me, then do an edge detection, hough etc. I need to detect JUST the colored ball- i.e. that it's a ball and the one I want.
    since giving it a range of colors gives me a wide detection I want to focus on an area where there's a large variety of colors- regardless of which they are.
    I tried the block process with an IF command (just for magenta and yellow) and couldn't really get it to work (something I wrote wrong I guess).

    I am not interested in counting the no. of colors in an image, because the whole idea was to be able to "zoom" on an area in the image through the fact that it contains more colors than other sections of the image.

    hope I explained it better now.....

  8. #8
    Join Date
    Jun 2007
    Posts
    7

    Re: color counting

    ok, so after a few filtering and detection I can find the ball, or actually I should say BALLS. and I've got them labeled (bwlabel).

    in order to distinguish which is the colored I want to go to the original picture, converted to grayscale, and check what is the STD (which should be high if it's colorful).

    I know std2 will give it for the whole picture, but how can I do that to my chosen area??

  9. #9
    Join Date
    Dec 2001
    Location
    Greece, Athens
    Posts
    1,015

    Re: color counting

    Quote Originally Posted by mwg
    ok, so after a few filtering and detection I can find the ball, or actually I should say BALLS. and I've got them labeled (bwlabel).

    in order to distinguish which is the colored I want to go to the original picture, converted to grayscale, and check what is the STD (which should be high if it's colorful).

    I know std2 will give it for the whole picture, but how can I do that to my chosen area??
    Ok, if i get it right bwlabel is a MxN matrix (MxN is also the image size) with binary values (1 specifies that it is a pixels of interest).
    First of all, if you haven't done it already, you should label your regions of interest separately. For example if you have 3 balls, bwlabel should contain 0 (for background pixels), 1 (for the first region), 2 (for the 2nd) etc.

    Afterwards, in order to calculate the STD value of each region you should simply do the following in matlab:

    Code:
    STD1 = std(Image(find(bwlabel==1)));
    STD2 = std(Image(find(bwlabel==2)));
    STD3 = std(Image(find(bwlabel==3)));
    .....
    where Image is your initial image (grayscale).
    In the sequel, you can do whatever you want with the calculated STD values of each object.

    Regards,
    Theodore
    Theodore
    Personal Web Page (some audio segmentation tools): www.di.uoa.gr/~tyiannak

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured