I looked into xcolor, and the color matching function they implement is 
only a rough approximation (page 55 of the xcolor manual), whereas Color.jl 
actually matches wavelengths to the CIE standard observer measurements. In 
this case, I think Color is more correct. Here's someone else's plot made 
from the CIE data that looks close to the Color.jl one: 
http://en.wikipedia.org/wiki/Luminosity_function#mediaviewer/File:Srgbspectrum.png


On Monday, August 25, 2014 8:43:13 PM UTC-7, Yakir Gagnon wrote:
>
> Oh sorry, I vaguely mentioned it in my first reply. 
> The short answer is:
>
> using Color,Images
> n = 500
> wl1 = 380.
> wl2 = 780.
> wl = linspace(wl1,wl2,n)
> I = Array(Float64,n,n,3)
> for i = 1:n
>     xyz = colormatch(wl[i])
>     rgb = convert(RGB,xyz)
>     for (j,f) in enumerate([:r,:g,:b])
>         I[i,:,j] = rgb.(f)
>     end
> end
> imwrite(I,"a.png")
>
> This results in the attached image. While I'm sure there's a much better 
> way of getting that done (feel free to show be btw, I'd love to know how to 
> improve), you can immediately see that the blues and reds are too far close 
> to each other and that the UV violet and IR black are overly represented. 
>
> The long answer is that I used pgfplots with Julia to generate that first 
> image. So the pgfplots part is this:
>
> \begin{tikzpicture}
>     \draw (0,0) node {\pgfuseshading{mySpectrum}};
>     \foreach \x/\xl in {-3/400,-1/500,1/600,3/700}{
>         \draw[gray] (\x,-.75) -- (\x,-1.25) node[anchor=north,black] {\xl};
>     }
>     \node at (0,-2) {Wavelength (nm)};
> \end{tikzpicture}
>
> and the julia part is this:
>
> using Color
>
> n = 50
> wl1 = 380
> wl2 = 780
> width = 8
> wl = linspace(wl1,wl2,n)
>
> d = linspace(0,width,n)
> f = open("spectrum.txt","w")
> write(f,"\\pgfdeclarehorizontalshading{mySpectrum}{2cm}{\n")
> for i = 1:n-1
>     xyz = colormatch(wl[i])
>     rgb = convert(RGB,xyz)
>
>     txt = "\trgb($(d[i])cm)=($(rgb.r),$(rgb.g),$(rgb.b));\n"
>     write(f,txt)
> end
> i = n
> xyz = colormatch(wl[i])
> rgb = convert(RGB,xyz)
> txt = "\trgb($(d[i])cm)=($(rgb.r),$(rgb.g),$(rgb.b))}"
> write(f,txt)
> close(f)
>
> xl = [400:100:700]
> nxl = length(xl)
> wli = wl2-wl1
> w = zeros(nxl)
> for i  = 1:nxl
>     r = (xl[i]-wl1)/wli
>     w[i] = width*r
> end
> w .-= width/2
>
>
>
>
> Yakir Gagnon
> The Queensland Brain Institute (Building #79)
> The University of Queensland
> Brisbane QLD 4072
> Australia
>
> cell +61 (0)424 393 332
> work +61 (0)733 654 089
>  
>
> On Tue, Aug 26, 2014 at 11:43 AM, Steven G. Johnson <[email protected] 
> <javascript:>> wrote:
>
>>
>>
>> On Monday, August 25, 2014 6:35:43 PM UTC-4, Yakir Gagnon wrote:
>>
>>> I tried the checkout version of Color, and it's the same (see attached), 
>>> i.e. wrong: the blues should be close to the 400 mark and the reds closer 
>>> to the 700. the UV purple and IR "black" should be closer to the ends than 
>>> what we see. Any idea what's going wrong? 
>>>
>>
>> You didn't give any indication of how you made that plot... 
>>
>
>

Reply via email to