Library: | graphic |
See also: | rgb2hls rgb2lab lab2rgb |
Quantlet: | hls2rgb | |
Description: | converts an HLS colour vector into an RGB vector. |
Usage: | RGB=hls2rgb(HLS) | |
Input: | ||
HLS | (n x 3) array of HLS colours assigned to n objects. The values of the H (hue) channel range from 0 to 360. H=0 corresponds to pure red, H=120 to pure green and H=240 to pure blue. The values of the L (lightness) and S (saturation) channels range from 0 to 1. | |
Output: | ||
n/a | (n x 3) array of RGB colours assigned to n objects. The values of the R (red), G (green) and B (blue) channels range from 0 to 255. |
library("xplore"); library("plot"); library("graphic"); nsteps=100; origin=#(-1, -1); endpoints=#(1, 1); steps=(endpoints-origin)/nsteps; npoints=#(nsteps+1, nsteps+1); A=grid(origin,steps,npoints); L=0.5*matrix((nsteps+1)*(nsteps+1),1); S=1*matrix((nsteps+1)*(nsteps+1),1); H=360*(A[,1]+A[,2])/(endpoints[1,1]-origin[1,1]+endpoints[2,1]-origin[2,1]); HLS=H~L~S; RGB=hls2rgb(HLS); createcolor(RGB); di=createdisplay(1,1); setmaskp(A, RGB, 7, 4); show(di, 1, 1, A);
A two dimensional plot. The simulated colours change along a diagonal line.
library("xplore"); library("plot"); library("graphic"); points=colorcube(); hls2=rgb2hls(points.pcolor); rgb2=hls2rgb(hls2); new2=(hls2[,3].*cos((pi/180)*hls2[,1]))~hls2[,2]~(hls2[,3].*sin((pi/180)*hls2[,1])); new2=replace(new2,NaN,0); disp1=createdisplay(1,1); disp2=createdisplay(1,1); setmaskp(new2,points.pcolor,points.pstyle, 10); show(disp1,1,1,new2); setmaskp(rgb2,points.pcolor,points.pstyle, 10); show(disp2,1,1,rgb2);
HLS cone and RGB cube