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

3 Ansichten (letzte 30 Tage)
Igor am 18 Jan. 2012
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....
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Jan am 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 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Igor am 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.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Blue finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by