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

Answers (2)

Try rgb2ind() or this kmeans example

7 Comments

can u tell me how to divide RGB color space in 8 coarse in malab?
It is not possible to do "8-coarse division" (whatever that is, I don't know), without "using any method". Making mystical passes over it and saying "Abaracadabara, you are now 8-coarse divided" would still be using some method.
Walter Roberson
tell me the function ( method )in matlab for coarse division
its divide the rgb color space into 8 blocks.like this
my problem in this pdf page 5.
It looks like the FAQ applies here: http://matlab.wikia.com/wiki/FAQ#Can_you_program_up_the_algorithm_in_this_article_for_me_and_explain_it_to_me.3F, though it looks somewhat interesting so if I can find the time today or tomorrow maybe I can read the paper.
i appreciate if u do for me... happy new year..

Sign in to comment.

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.

10 Comments

why did u multiply 4 and 2 with red and green component.... quadrant_num = binned_image(:,:,1) * 4 + binned_image(:,:,2) * 2 + binned_image(:,:,3);
Each plane, R, G, B, will have value 0 or 1 in binned_image. To convert that to figure out which of the 8 areas is being referred to, the easiest way is to interpret the 3 values together as a set of three bits in a binary number, and we might as well us the bit order R then G then B. You could, if you really wanted, write this as
(left-shift Red bit-contribution by one place, OR in Green bit-contribution), left shift the result by one place, OR in the Blue bit-contribution
but if you work that through you will find that that corresponds to multiplying the Red bit-contribution by 4, multiplying the Green bit-contribution by 2, multiplying the Blue bit-contribution by 1, and adding those values all together. Which is what I did.
when i try to do this then my image data loss.it similarly like quantization of binary image
Are you using
imagesc(quadrant_num)
or alternately
imshow(quadrant_num, [])
to see the different bin numbers as different colors ?
Yes, that's the nature of quantization. Your image will look posterized.
Walter Roberson it should be like to use rgb2ind() function but its not?
Correct. The rgb2ind() does not reveal the algorithm that it uses in the help, but it's most likely not what Walter did. You can get an overview of several common/popular methods in this Wikipedia article: http://en.wikipedia.org/wiki/Color_quantization
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
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.

Sign in to comment.

Asked:

on 31 Dec 2012

Community Treasure Hunt

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

Start Hunting!