**** GNUPLOT COLOR TOOLS **** Motivation: ----------- Current gnuplot versions already contain mighty color tools like free color palette definition by the user, RGB formulae, hexadecimal color specifiers etc. However, there may sometimes be the need for additional color manipulation tools, e.g. easy gamma correction adjustment, switch a color plot to b/w to see how it will appear on grayscale plot etc. This scripts collection provides some tools for such issues. The script has been tested with the gnuplot 4.4 and the development version. However, it probably also works fine with version 4.2 (however, textcolors were not introduced in 4.2). Files related to Color Manager: ------------------------------- colormanager.gp Main definitions (to be called once) rgbformulae.gp RGB formulae, currently equivalent to gnuplot's collection. Having them as functions allows more flexible use. rgbstring_base.gp Simplified script for HEX line and text color (once) rgbstring_process.gp hexadecimal line and text color transformation script (to be called once for each hex-rgb string variable. testcolor.gp Test script for colormanager.gp & rgbstring_process.gp testrgb.gp Test script for rgbstring_base.gp & rgbstring_process.gp Independent Files: ------------------ cubehelix.gp Cube helix method by D.A. Green (2011, arXiv:1108.5083) plotcubehelix.gp Plot the cube helix color profile printcubehelix.gp Print cube helix palette into gnuplot palette file (called from plotcubehelix.gp) splotcubehelix.gp 3D-Plot of colour profile (called independently) testcubehelix.gp Demo/testing script testpalette.gp Similar analysis tool for any gnuplot palette file COLORMANAGER: ============= Usage: ------ Line and text colors: First, hexadecimal rgb color specifiers have to be defined the same way as required for linecolor and textcolor. Gnuplot recognizes them either directly specified as in linecolor rgb '#ff00ff' (giving a violet color tone in this example) or via a string variable rgb01='#ff00ff': linecolor rgb rgb01 rgbstring_process.gp use string variables as color specifiers. After having a color string defined, it can be processed by rgbstring_process.gp. Before it can be used, some basic definitions have to be done by rgbstring_base.gp and some variables to be set in advance. These are: pgamma : gamma correction sat : color saturation wlo,whi : lower, upper gray value (0=black, 1=white) wr,wg,wb : user-defined gray weighting (for graymode !=0,1,2,3) graymode : gray weighting mode 0 - simple equal weighting 1 - CCIR 601 (used e.g. by the GIMP) 2 - SMPTE 240M (1035i HDTV) 3 - ITU-R (modern HDTV) else - custom wr,wg,wb (defined before calling) Here is an example to convert colors into b/w at full contrast and user-defined r,g,b weights.: sat=0.; pgamma=1.; wlo=0.; whi=1.; graymode=4 wr=0.24; wg=0.64; wb=0.12 load 'rgbstring_base.gp' Palette manipulation: Similar to rgbstring_base.gp some (more) variables have to be defined: PARAMETERS (to be set before calling this script) colormode : 0 - convert to grayscale 1 - keep RGB color -1 - old (obsolete) gray-RGB saturation else - gray-RGB saturation graymode : gray weighting mode 0 - simple equal weighting 1 - CCIR 601 (used e.g. by the GIMP) 2 - SMPTE 240M (1035i HDTV) 3 - ITU-R (modern HDTV) else - custom wr,wg,wb (defined before calling) rgbfnmode : 1 - use RGB formulae else - use palette file f1(x),f2(x),f3(x): RGB formulae; any function [0:1] -> [0:1] try funcs from rgbformulae.gp use fn(1-x) for "negative" and 1-fn(x) for inverse permrgb : permutation of RGB colors; default=123 dimr,g,b : dim R,G,B by a factor 0...1 wlo,whi : lower, upper gray value (0=black, 1=white) sat : color saturation 0--1 pgamma : Gamma correction (gray) gamr, gamg, gamb : RGB gamma exponents gammamode : 0 - gray only 1 - gamrgb=pgamma 2 - individual RGB gammas 3 - like 2 but also scaled by pgamma else - all = 1 Example: load 'rgbformulae.gp' f1(x)=frgb07(x);f2(x)=frgb05(x);f3(x)=frgb15(x) wr=0.3; wg=0.6; wb=0.1 colormode=1;graymode=1;rgbfnmode=0;gammamode=0 sat=1.;pgamma=1.;gamr=1.;gamg=1.;gamb=1. permrgb=123;dimr=1.;dimg=1.;dimb=1. palettefile='nebula1.rgb' load 'colormanager.gp' The specified palette is not changed as a file, but manipulated upon being loaded by gnuplot. colormanager.gp does also contain the definitions used by rgbstring_process.gp, so that you do not need to load rgbstring_base.gp separately. CUBE HELIX ========== This script uses the isophote colour scheme described by D.A. Green (2011, arXiv:1108.5083) which allows easy monotonic grayscale conversion. The details are described in that paper. To use the script in any gnuplot script using RGB palettes just invoke it before the plot by the 'load' statement: load 'cubehelix.gp' To generate a gnuplot RGB palette file "cubehelix.rgb" run gnuplot on plotcubehelix.gp (this will also generate a profile graph named "cubehelix.eps"). Note that using a pre-calculated palette file for large colour images in gnuplot may be *way* more efficient than using cubehelix during the plot. A 3D view of the colour profile can be displayed via splotcubehelix.gp from gnuplot terminal. Version 4.5 or higher allows for variable line colour. For older versions, monochrome line styles are used (set by gpversion; 4.4 by default). The parameters to be set inside the script are given in this sample code snippet with the default settings: #### Main parameters (Green 2011) phi_start=0.5 # start color (1.0=red, 2.0=green etc.; modulo 3) rotations=-1. # number of colour space rotations along grayscale sathue=1.5 # saturation of hue (0=gray...1=colour) gamma_gry=1.0 # gamma correction #### Non-standard exponents (added by IT) gamma_rot=1. # "gamma" correction for rotation rate gamma_amp=1.5 # "gamma" correction for colour amplification #### RGB weights (Green uses fixed values) #### wr=0.30; wg=0.59; wb=0.11 Standard RGB weights are wr=0.30; wg=0.59; wb=0.11 - NTSC, Green (2011) wr=0.299; wg=0.587; wb=0.114 - PAL wr=0.2126; wg=0.7152; wb=0.0722 - HDTV NOTE: cubehelix.gp is not (yet) compatible with colormanager.gp. However, the generated cubehelix.rgb can be used with colormanager like any other RGB palette. COLOR HELIX: ============ This Fortran90 program is an improvement of Cube helix making use of the CIE LAB (1976) color space. Optionally, the original cube helix method is also included. COLOR HELIX generates RGB palettes which can be used in gnuplot. Color helix is best compiled with the free GNU Fortran Compiler. More details are included in the readme4colorhelix.txt file included in the tarball. colorhelix.tar.bz2 License info: ------------- I am not sure whether these scripts are of sufficient complexity to be subject to copyright law. However, in case it does I am providing these scripts colormanager.gp rgbformulae.gp rgbstring_base.gp rgbstring_process.gp testcolor.gp testrgb.gp cubehelix.gp plotcubehelix.gp printcubehelix.gp splotcubehelix.gp testpalette.gp and the RGB palette files distributed with these scripts under the FreeBSD License license: -------------------------------------------------------------------------------------------- LICENCE TERMS Copyright (c) 2010-2011 by Ingo Thies Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of the copyright holder. --------------------------------------------------------------------------------------------