finding dominant color in an image

determine the dominant color in a color image by C++

Page 1 of 1

11 Replies - 7998 Views - Last Post: 17 January 2010 - 04:58 PM Rate Topic: -----

#1 gnelkia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-January 10

finding dominant color in an image

Post icon  Posted 13 January 2010 - 10:33 PM

Dear All..

i am new to C++ ..
however i am in rush to complete my project.

may i know is there any idea to finding out the dominant color in an image in RGB value ?

example.

there is an image of banana and some background.
thus, i would like to determine the exact RGB color space which dominant the image.

basically it will be yellow due to the banana.. just i cannot find a way to really extract the exact value of RGB out.


thinking of putting all RGB value in multidimension array from pixel to pixel. however i do not know how to calculate which pixel having most similar "family" in the image.

thank you so much for help ~~ :)

Is This A Good Question/Topic? 0
  • +

Replies To: finding dominant color in an image

#2 ReclusiveManiac  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 18-September 09

Re: finding dominant color in an image

Posted 13 January 2010 - 11:56 PM

Okay I have no idea if this is possible, considering I have not dealt with anything like this before, but I would guess you put it in an array and then check the RGB value of each pixel and create a new counter whenever a new color shows up, and increment a counter if the same one shows up again. Then see which counter is highest and look at the RGB value associated.

Better wait for one of the experts to post though. : )
Was This Post Helpful? 0
  • +
  • -

#3 Jason_Fields  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 14
  • Joined: 06-December 09

Re: finding dominant color in an image

Posted 14 January 2010 - 04:14 PM

Yeah, do what is said above. Although you may want to group different colors in a group. Example: instead of 0xFF0000 (pure red) being different from 0xFF0A0A (a slightly darker red), you might want to put them both in the "red" catagory. Just learn how get the RGB values from an image file.
Was This Post Helpful? 0
  • +
  • -

#4 gnelkia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-January 10

Re: finding dominant color in an image

Posted 14 January 2010 - 08:01 PM

View PostJason_Fields, on 14 Jan, 2010 - 03:14 PM, said:

Yeah, do what is said above. Although you may want to group different colors in a group. Example: instead of 0xFF0000 (pure red) being different from 0xFF0A0A (a slightly darker red), you might want to put them both in the "red" catagory. Just learn how get the RGB values from an image file.



Dear Experts~

basically i have managed to obtain each RGB value for each pixel.
just would like to know which RGB value actually is the dominant color.

if i am going to set a counter for RGB value calculated, does it means i have to set a lot of counter because there will be a lot of different RGB value in an image.


Example:

this is an image:

1 3 4 5 6
2 3 4 6 1
1 4 7 7 1
4 6 7 6 1


under this condition, i have to set a counter when calculating numbers of 1, and another counter for calculating number of 3.. and so on..

i am afraid there will be unknown number of counter which will involved..


Thank You so much~ :)
Was This Post Helpful? 0
  • +
  • -

#5 ReclusiveManiac  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 18-September 09

Re: finding dominant color in an image

Posted 14 January 2010 - 10:43 PM

I would suggest doing what the poster below me said. Make counters for the basic colors: red/green/blue/yellow/black/white/purple/etc... and then make any light red/red/dark red color increment the red counter. Hopefully that makes a little more sense.
Was This Post Helpful? 0
  • +
  • -

#6 gnelkia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-January 10

Re: finding dominant color in an image

Posted 14 January 2010 - 11:17 PM

View PostReclusiveManiac, on 14 Jan, 2010 - 09:43 PM, said:

I would suggest doing what the poster below me said. Make counters for the basic colors: red/green/blue/yellow/black/white/purple/etc... and then make any light red/red/dark red color increment the red counter. Hopefully that makes a little more sense.


yeah~ is a good idea.. thank you so much.

however, i am not only looking for 1 kind of color. but would like to compare between several colors. thus, it means that there will be more than 1 counter involved.

does this make sense and applicable ?

Example:

in the end of the program, i hope could get the result like :

pixels with R = 200 G =100 B = 50 ---> 30
pixels with R = 10 G = 200 B = 100 ---> 20
and so on..

so only i can get the dominant RGB value i needed.

Thank You so much~
Was This Post Helpful? 0
  • +
  • -

#7 ReclusiveManiac  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 98
  • Joined: 18-September 09

Re: finding dominant color in an image

Posted 14 January 2010 - 11:19 PM

Yeah but it won't be exact. It will only tell you how many redish/orangish/yellowish/greenish pixels there are. Not the exact RGB values because that would take to many counters to count every exact one.
Was This Post Helpful? 0
  • +
  • -

#8 gnelkia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-January 10

Re: finding dominant color in an image

Posted 15 January 2010 - 01:10 AM

View PostReclusiveManiac, on 14 Jan, 2010 - 10:19 PM, said:

Yeah but it won't be exact. It will only tell you how many redish/orangish/yellowish/greenish pixels there are. Not the exact RGB values because that would take to many counters to count every exact one.


Hmm.. so it will be unapplicable if i really need the value of it.. because too much counter involved?

thank you thank you.
Was This Post Helpful? 0
  • +
  • -

#9 Jason_Fields  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 14
  • Joined: 06-December 09

Re: finding dominant color in an image

Posted 15 January 2010 - 02:14 PM

well considering there are 16581375 different RGB colors possible, it wouldn't make sense to make a counter for each
Was This Post Helpful? 0
  • +
  • -

#10 gnelkia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-January 10

Re: finding dominant color in an image

Posted 16 January 2010 - 08:47 AM

View PostJason_Fields, on 15 Jan, 2010 - 01:14 PM, said:

well considering there are 16581375 different RGB colors possible, it wouldn't make sense to make a counter for each


i see i see..

thank you so much..

so any suggestion or idea that i should use in order to find the dominant color space of an image ??
Was This Post Helpful? 0
  • +
  • -

#11 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5805
  • View blog
  • Posts: 12,644
  • Joined: 16-October 07

Re: finding dominant color in an image

Posted 16 January 2010 - 09:47 AM

View PostJason_Fields, on 15 Jan, 2010 - 03:14 PM, said:

well considering there are 16581375 different RGB colors possible, it wouldn't make sense to make a counter for each


Sure you could. Why not?

In C++ land, however, it would be better to use a map. Your color is the key, the value is the count. Counting colors is pretty simple.

Unfortunately, just counting colors probably isn't going to get you what you want. Lookup up various histogram techniques, particularly pertaining to Hue, Light, and Saturation.

What you want to do has been done. It's simply a matter of finding it. A number of techniques fall under patent, but there are some that have been around a while. Good luck.
Was This Post Helpful? 0
  • +
  • -

#12 gnelkia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 13-January 10

Re: finding dominant color in an image

Posted 17 January 2010 - 04:58 PM

View Postbaavgai, on 16 Jan, 2010 - 08:47 AM, said:

View PostJason_Fields, on 15 Jan, 2010 - 03:14 PM, said:

well considering there are 16581375 different RGB colors possible, it wouldn't make sense to make a counter for each


Sure you could. Why not?

In C++ land, however, it would be better to use a map. Your color is the key, the value is the count. Counting colors is pretty simple.

Unfortunately, just counting colors probably isn't going to get you what you want. Lookup up various histogram techniques, particularly pertaining to Hue, Light, and Saturation.

What you want to do has been done. It's simply a matter of finding it. A number of techniques fall under patent, but there are some that have been around a while. Good luck.


oh ~ sorry for late reply..

thank you so much for the information.. i will try my best to search around.. hopefully could found some which haven in patent yet.. thank you so much ... :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1