dominant color for an RGB image

93 views (last 30 days)
mariem farhat
mariem farhat on 26 Feb 2013
Commented: Shiv srikakolum on 24 Nov 2021
I want to extract the dominant color of an RGB image.
How can I proceed to do that?

Sign in to comment.

Answers (3)

Sean de Wolski
Sean de Wolski on 27 Feb 2013
colors = 'RGB';
I = imread('peppers.png');
[~,idx] = max(sum(sum(I,1),2),[],3);
dominant = colors(idx)

Image Analyst
Image Analyst on 26 Feb 2013
How about this:
dominantRedValue = mean2(rgbImage(:, :, 1));
dominantGreenValue = mean2(rgbImage(:, :, 2));
dominantBlueValue = mean2(rgbImage(:, :, 3));
Will that work for you?
Image Analyst
Image Analyst on 27 Feb 2013
Even looking at hue, it's not so easy, as you can see from this screenshot:
That's looking down the value axis from the top. Here's another view from a different perspective:
As you can see whether there is more "green" or "white" pixels depend on where you put the "dividing line" between green and white. It's sort of a continuum so you have to make some kind of criteria. Basically you have to do color classification but to do that you have to decide how many colors you want. Here's one where I chose 48 color classes:
but there are still classes in the "in between" greenish/whitish region and you'll have to decide what to call those. But after that you can find out how many pixels are in each class, then maybe boil it down to two classes and see which has more pixels in it.

Sign in to comment.

mariem farhat
mariem farhat on 27 Feb 2013
Sorry, I haven't posted the image. Here the link of the image:
Jan on 25 Apr 2017
The imageshack link is dead now. Please post the image directly instead of hosting it on any external server.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!