how can we do "8-coarse division of RGB color space" for dominant color extraction?
Show older comments
this is basically for quantized color.
Answers (2)
Image Analyst
on 31 Dec 2012
0 votes
7 Comments
preet
on 31 Dec 2012
Walter Roberson
on 31 Dec 2012
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
on 31 Dec 2012
What is "coarse division" ?
Image Analyst
on 31 Dec 2012
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.
preet
on 31 Dec 2012
Edited: Image Analyst
on 31 Dec 2012
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.
10 Comments
preet
on 31 Dec 2012
Walter Roberson
on 31 Dec 2012
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.
Walter Roberson
on 31 Dec 2012
Are you using
imagesc(quadrant_num)
or alternately
imshow(quadrant_num, [])
to see the different bin numbers as different colors ?
Image Analyst
on 31 Dec 2012
Yes, that's the nature of quantization. Your image will look posterized.
preet
on 31 Dec 2012
Image Analyst
on 31 Dec 2012
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
Walter Roberson
on 31 Dec 2012
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
preet
on 1 Jan 2013
Walter Roberson
on 1 Jan 2013
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.
Categories
Find more on Color in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!