File:ColorVSspectrum.webm
Summary
Description |
English: The human eyes have "only" 3 different colour receptors, so multiple spectra can be perceived as the same colour. |
Date | |
Source | https://mathstodon.xyz/@j_bertolotti/112513527893709299 |
Author | Berto |
Permission (Reusing this file) |
https://mathstodon.xyz/@j_bertolotti/111363365323269417 |
Mathematica 14.0 code
path = "path to where you saved the color matching functions";
LMS = Import[ path <> "/LMS.dat"]; (*All color matching functions downloaded from www.cvrl.org*)
Lr = LMS[[All, 1 ;; 2]];
Mr = LMS[[All, 1 ;; 3 ;; 2]];
Sr = LMS[[All, 1 ;; 4 ;; 3]];
{\[Lambda], X, Y, Z} = Transpose@Import[path <> "/XYZ-color_matching.dat"];
rgbcolor[spectrum_] := ColorConvert[({X, Y, Z} . spectrum), "XYZ" -> "RGB"];
\[Lambda]sampled = \[Lambda][[1 ;; -1 ;; 10]];
spectrum[coefficients_] := N[(Sum[coefficients[[j]]*E^(-((# - \[Lambda]sampled[[j]])^2/(2. (5)^2))), {j, 1, Dimensions[\[Lambda]sampled][[1]]}] &) /@ \[Lambda]];
plot[coefficients_] := Grid[{{Show[
ListPlot[{Lr, Mr, Sr}, PlotStyle -> {Red, Green, Blue}, Joined -> True, Axes -> {True, False}, Frame -> False, AxesLabel -> {"\[Lambda]", ""}, LabelStyle -> {FontSize -> 14, Bold, Black}, PlotRange -> All]
,
Graphics[{FontSize -> 14, Blue, Text[Style["S", Bold], {465, 0.95}], Green, Text[Style["M", Bold], {515, 0.95}], Red, Text[Style["L", Bold], {610, 0.95}]}]
,
ListPlot[Transpose[{\[Lambda], spectrum[coefficients]}], PlotStyle -> Black, Joined -> True, PlotRange -> All], PlotRange -> All, ImageSize -> Medium]
,
Graphics[{rgbcolor[0.25*spectrum[coefficients]], Disk[], Black,
Thick, Circle[]}]
}}]
plot1[k_] := Grid[{{Show[
ListPlot[{Lr, Mr, Sr}, PlotStyle -> {Red, Green, Blue}, Joined -> True, Axes -> {True, False}, Frame -> False, AxesLabel -> {"\[Lambda]", ""}, LabelStyle -> {FontSize -> 14, Bold, Black}, PlotRange -> All]
,
Graphics[{FontSize -> 14, Blue, Text[Style["S", Bold], {465, 0.95}], Green, Text[Style["M", Bold], {515, 0.95}], Red, Text[Style["L", Bold], {610, 0.95}]}]
,
ListPlot[ Transpose[{\[Lambda], Table[If[j == k, 1, 0], {j, 1, Dimensions[\[Lambda]][[1]]}]}], PlotStyle -> Black, Joined -> True, PlotRange -> All]
, PlotRange -> All, ImageSize -> Medium]
,
Graphics[{rgbcolor[ Table[If[j == k, 1, 0], {j, 1, Dimensions[\[Lambda]][[1]]}]], Disk[], Black, Thick, Circle[]}]
}}];
frames0 = Grid[{{Show[
ListPlot[{Lr, Mr, Sr}, PlotStyle -> {Red, Green, Blue}, Joined -> True, Axes -> {True, False}, Frame -> False, AxesLabel -> {"\[Lambda]", ""}, LabelStyle -> {FontSize -> 14, Bold, Black}, PlotRange -> All]
,
Graphics[{FontSize -> 14, Blue, Text[Style["S", Bold], {465, 0.95}], Green, Text[Style["M", Bold], {515, 0.95}], Red, Text[Style["L", Bold], {610, 0.95}]}]
,
ListPlot[ Transpose[{\[Lambda], ConstantArray[0, Dimensions[\[Lambda]][[1]]]}], PlotStyle -> Black, Joined -> True, PlotRange -> All]
, PlotRange -> All, ImageSize -> Medium]
,
Graphics[{Black, Disk[], Black, Thick, Circle[]}]
}}];
frames1 = Table[plot1[k], {k, 1, Dimensions[\[Lambda]][[1]], 2}];
sinstep[t_] := Sin[\[Pi]/2 t]^2;
frames2 = Table[plot[Table[If[j == 5 || j == 10 || j == 25, 0.5*sinstep[t], 0], {j, 1, 45}]], {t, 0, 1, 0.05}];
spectrlets = Table[{X, Y, Z} . (spectrum@Table[If[j == k, 1, 0], {j, 1, 45}]), {k, 1, 45}];
spectrum2[k_] := Module[{tmp}, tmp = ConstantArray[0, 45]; tmp[[1]] = 1; Return[RotateRight[tmp, k - 1]]];
frames3 = Table[plot[0.5*coefficients2], {t, 0, 1.5, 0.01}];
t = 1.5;
frames4 = Table[plot[a*coefficients2], {a, 0, 0.5, 0.05}];
ListAnimate[ Join[Table[frames0, {5}], Reverse[frames1[[1 ;; -1 ;; 2]]], Table[frames0, {5}], Table[frames2[[1]], {5}], frames2, Table[frames2[[-1]], {5}], frames3, Reverse[frames4] ] ]
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
![]() ![]() |
This file is made available under the Creative Commons CC0 1.0 Universal Public Domain Dedication. |
The person who associated a work with this deed has dedicated the work to the public domain by waiving all of their rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.
|