Skip to content
eiichiromomma edited this page Aug 17, 2014 · 1 revision

(R) colorspace

色ベクトルを容易に扱えるパッケージ

概要

ベースとなるのがcolor-classでcolor型の色ベクトルを表す。

color-class             Class "color"

色ベクトルの作成は

HSV                     Create HSV Colors
LAB                     Create LAB Colors
LUV                     Create LUV Colors
RGB                     Create RGB Colors
XYZ                     Create XYZ Colors

を使い、RGBの場合は

色ベクトル <- RGB(Rの値,Gの値,Bの値)

となる。 関数に渡すのがベクトルであれば、出力も色ベクトルのベクトルとなる。

 # Create a random set of colors
 rgb = RGB(R = runif(20), G = runif(20), B = runif(20))

ではrgbが20個の色ベクトルのベクトルになる。

空間の変換は

as(色ベクトル,"HSV"or"LAB"or"LUV"or"RGB"or"XYZ")

で可能。

plot(as(rgb,"LUV"))

で色ベクトルがLuvに変換されてプロットされる。

値の取り出しには

coords                  Extract the numerical coordinates of a color

を使わなければならない。

> rgb[1]
             R          G         B
[1,] 0.3169619 0.09889077 0.8286697
> rgb[1]$R
NULL

名前を指定してもNULLになる。

> rgb[1,1]
             R          G         B
[1,] 0.3169619 0.09889077 0.8286697

要素で指定しても全部出てくる

> coords(rgb)[1,1]
[1] 0.3169619

coordsを使うと数値の行列に変換されるので要素で指定できる。

必要に応じて記述するかも

hcl                     Create R Colours from Hue, Chroma and Luminance
hex                     Convert Colors To Hexadecimal Strings
hex2RGB                 Convert Hexadecimal Color Specifications To RGB Objects
mixcolor                Compute the convex combination of two colors
polarLAB                Create polarLAB Colors
polarLUV                Create polarLUV Colors
readRGB                 Read RGB Color Descriptions
readhex                 Read Hexadecimal Color Descriptions
writehex                Write Hexadecimal Color Descriptions
Clone this wiki locally