MATLAB Answers


how can we do "8-coarse division of RGB color space" for dominant color extraction?

Asked by preet
on 31 Dec 2012

this is basically for quantized color.


2 Answers

Answer by Image Analyst
on 31 Dec 2012

Try rgb2ind() or this kmeans example


on 31 Dec 2012

its divide the rgb color space into 8 this

my problem in this pdf page 5.

It looks like the FAQ applies here:, though it looks somewhat interesting so if I can find the time today or tomorrow maybe I can read the paper.

on 31 Dec 2012

i appreciate if u do for me... happy new year..

Answer by Walter Roberson
on 31 Dec 2012

dImage = im2double(YourImage);
binned_image = round(dImage);
quadrant_num = binned_image(:,:,1) * 4 + binned_image(:,:,2) * 2 + binned_image(:,:,1);

quadrant 0 would be (low red, low blue, low green), quadrant 1 would be (low red, low blue, high green), quadrant 2 would be (low red, high blue, low green), and so on up to quadrant 7 as (high red, high blue, high green)

You might want to add 1 to the quadrant number, if you want to use it as an index.


The paper says,

The color space is equally divided into 8 coarse partitions according to the quantity of each color component.

So you do not want to do something like rgb2ind() does, as rbg2ind() does not divide the color-space equally. The code I gave does divide the color-space equally, and the value I return for each point is an index like rgb2ind() would return, with the minor exception that for technical reasons, rgb2ind() would correspond to taking uint8() of quadrant_num

on 1 Jan 2013

i said i need the result like rgb2ind()..

Okay, here it is:

dImage = im2double(YourImage);
binned_image = round(dImage);
quadrant_num = uint8( binned_image(:,:,1) * 4 + binned_image(:,:,2) * 2 +   binned_image(:,:,1) );

quadrant_num will now be exactly like rgb2ind() in that it will return a 2D array of uint8() values, each of which is an "ind". Keep in mind that exactly like rgb2ind(), the value 0 represents the first color in the color map, and 1 represents the second color, and so on.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!