Re: Convert Hue[] to RGBColor[] and backwards
- To: mathgroup at smc.vnet.net
- Subject: [mg103483] Re: Convert Hue[] to RGBColor[] and backwards
- From: Ray Koopman <koopman at sfu.ca>
- Date: Thu, 24 Sep 2009 07:50:15 -0400 (EDT)
- References: <BLU0-SMTP4514449534FFC9FA25CF7EADC0@phx.gbl> <h9e6k2$42v$1@smc.vnet.net>
On Sep 23, 3:14 pm, "Alexey Popkov" <lehi... at gmail.com> wrote: > Thank you. It is just that I need. Nevertheless, you might also want to look at Sean Ross's Nov 5, 2003, post in the thread "RGB to HSB color conversion", http://groups.google.ca/group/comp.soft-sys.math.mathematica/msg/eae1d2fea61d0cd1 > > ----- Original Message ----- > From: "Alexander Elkins" <alexander_elk... at hotmail.com> > To: <hanl... at cox.net>; <lehi... at gmail.com> > Sent: Wednesday, September 23, 2009 2:32 AM > Subject: Re: Convert Hue[] to RGBColor[] and backwards > >> ?ToColor >> >> ToColor[color, form] converts color to form if form is GrayLevel, RGBColor >> or CMYKColor. >> Otherwise form[color] is evaluated and the result is expected to be a >> valid >> color directive. >> >> In both v6 and v7 form can also be Hue. For example: >> In[1]:= ToColor[Hue[0.1333333, 0.625, 0.8], RGBColor] >> Out[1]= RGBColor[0.8, 0.7, 0.3] >> >> In[2]:= ToColor[RGBColor[0.8, 0.7, 0.3], Hue] >> Out[2]= Hue[0.133333, 0.625, 0.8] >> >> Of course it is possible to roll one's own ToHue function: >> >> In[3]:= ToHue[color_RGBColor] := Module[{rgb, m, n}, rgb = Clip[#, {0, 1}] >> & /@ color; >> m = Max @@ rgb + 0.; n = Min @@ rgb; >> If[m == n, Hue[0., 0., m], >> Hue[Function[{r, g, b}, >> Which[r == m, Mod[(g - b)/(m - n), 6], g == m, (b - r)/(m - n) + 2, >> True, (r - g)/(m - n) + 4]/6] @@ rgb, 1 - n/m, m]]]; >> >> In[4]:= ToHue[RGBColor[0.8, 0.7, 0.3]] >> Out[4]= Hue[0.133333, 0.625, 0.8] >> >> - Alexander Elkins >> >> "Bob Hanlon" <hanl... at cox.net> wrote in message >> news:h97msg$7fi$1 at smc.vnet.net... >>> >>> In v7 there is ColorConvert >>> >>> Table[ColorConvert[Hue[h], "RGBColor"], {h, 0, 1, 0.1}] >> >> {RGBColor[1.,0.,0.],RGBColor[1.,0.6,0.],RGBColor[0.8,1.,0.],RGBColor[0.2,1., >> 0.],RGBColor[0.,1.,0.4],RGBColor[0.,1.,1.],RGBColor[0.,0.4,1.],RGBColor[0.2, >> 0.,1.],RGBColor[0.8,0.,1.],RGBColor[1.,0.,0.6],RGBColor[1.,0.,0.]} >> >>> ColorConvert[#, "Hue"] & /@ % >> >> {Hue[0.,1.,1.],Hue[0.1,1.,1.],Hue[0.2,1.,1.],Hue[0.3,1.,1.],Hue[0.4,1.,1.], >> Hue[0.5,1.,1.],Hue[0.6,1.,1.],Hue[0.7,1.,1.],Hue[0.8,1.,1.],Hue[0.9,1.,1.], >> Hue[0.,1.,1.]} >> >>> As can be seen, the conversions are somewhat approximate. >>> >>> Bob Hanlon >>> >>> ---- Alexey Popkov <lehi... at gmail.com> wrote: >>> >>> ============= >>> Hello, >>> I have not found in the Documentation any information on relation >>> between Hue[] and RGBColor[] representations of color. How can I >>> convert one to another? >>> >>> -- >>> >> Bob Hanlon