A formula of color: how does MATLAB link indexed value of color with RGB format?

2 views (last 30 days)
As known, MATLAB can plot graphics with colorbar and chosen colormap and also read/write images in RGB-scheme. And two color model are used, indexed (defined by double type C in range 0..1) and RGB.
How easy to define analytically function F:C->(R,G,B), i.e. r=r(c),g=g(c),b=b(c)?
With natural aasumptions: F(0)=(0,0,0),F(1)=(1,1,1) and F(?)=(1,0,0),.. F(?)=(0,1,1)
It would be helpful for intellectual colormaps....

Accepted Answer

Jan
Jan on 18 Jan 2012
As far as I know, you cannot map colors to a single parameter using an analytical function. The RGB colorspace uses 3 componnts, which cannot be projected onto a line.
The standard method is a lookup table using colormap.
Java can use a 24 bit value as a RGB color applying something like this
RGB = uint8(floor(rand(40, 20, 3) * 256));
Ind = RGB(:, 1) + 256 * RGB(:,2) + 65535 * RGB(:, 3);
Usually the alpha channel is added also and the colors are stored with 32 bits.
What do you want to achieve?
  1 Comment
Igor
Igor on 18 Jan 2012
I think that simplest way to define this "like as" analytic function (thank you for code) is:
fist byte of C -- R-value
second -- G
third -- B
fourth (power) -- transparency
And the goal is achieved.
But it's interesting to imagine such function F as math formula.

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!