13361
How do I add a new predefined color table to my IDL color table file?
This help article illustrates how an IDL user can add a new predefined color table to their IDL color table file.
---------
Note: If your IDL installation has been installed in a public directory location, such as
C:\Program Files\
/usr/local/
/Applications/
--then your IDL session launched as a regular user may not have adequate permissions to modify the default color table file provided with your IDL installation. In any case, you may wish to preserve your original IDL color table file, and instead make a copy of this file to modify, using the steps in this help article.
In that case, in preparation for modifying your color table file, you can copy your original IDL color table file, which is located in your IDL installation under the [IDL-directory]/resource/colors/ subdirectory, to a convenient writable location such as your home directory, and then proceed to modify this copy of the file, following the steps below. For example, for IDL 8.3 on Windows 7 in the default location, the IDL color table file is located at:
C:\Program Files\exelis\idl83\resource\colors\colors1.tbl
You could save a renamed copy of this file in your home directory, for example:
C:\Users\joeuser\myidlcolors.tbl
---------
The following steps illustrates how create a modified version of the standard IDL color table list file that adds a new custom "red-white-blue" color table entry (with a fully saturated red and blue color elements on the ends) to the list of color tables.
1.) Prepare the IDL direct graphics environment to use a loaded color table by issuing the command:
DEVICE, DECOMPOSED=0
2.) Next, assuming you would like to add a new predefined color table, rather than modify an existing predefined color table in your IDL color table file, determine what is the first unassigned color table index in the current color table file.
One way to do this is to issue the IDL "LOADCT" command without any parameters. This produces a numbered listing of the predefined color tables. After making note of the highest index number, enter any of the color table indexes to return to the IDL> command prompt. For example:
IDL> loadct
0- B-W LINEAR 25- Mac Style 50- CB-BuGn
1- BLUE/WHITE 26- Eos A 51- CB-BuPu
2- GRN-RED-BLU-WHT 27- Eos B 52- CB-GnBu
3- RED TEMPERATURE 28- Hardcandy 53- CB-Greens
4- BLUE/GREEN/RED/YE 29- Nature 54- CB-Greys
5- STD GAMMA-II 30- Ocean 55- CB-Oranges
6- PRISM 31- Peppermint 56- CB-OrRd
7- RED-PURPLE 32- Plasma 57- CB-PuBu
8- GREEN/WHITE LINEA 33- Blue-Red 58- CB-PuBuGn
9- GRN/WHT EXPONENTI 34- Rainbow 59- CB-PuRd
10- GREEN-PINK 35- Blue Waves 60- CB-Purples
11- BLUE-RED 36- Volcano 61- CB-RdPu
12- 16 LEVEL 37- Waves 62- CB-Reds
13- RAINBOW 38- Rainbow18 63- CB-YlGn
14- STEPS 39- Rainbow + white 64- CB-YlGnBu
15- STERN SPECIAL 40- Rainbow + black 65- CB-YlOrBr
16- Haze 41- CB-Accent 66- CB-BrBG
17- Blue - Pastel - R 42- CB-Dark2 67- CB-PiYG
18- Pastels 43- CB-Paired 68- CB-PRGn
19- Hue Sat Lightness 44- CB-Pastel1 69- CB-PuOr
20- Hue Sat Lightness 45- CB-Pastel2 70- CB-RdBu
21- Hue Sat Value 1 46- CB-Set1 71- CB-RdGy
22- Hue Sat Value 2 47- CB-Set2 72- CB-RdYlBu
23- Purple-Red + Stri 48- CB-Set3 73- CB-RdYlGn
24- Beach 49- CB-Blues 74- CB-Spectral
Enter table number: 0
% LOADCT: Loading table B-W LINEAR
IDL>
In this case, the highest index of the default predefined color tables is 74. Then for this example, the next available color table index is 75.
(Note that additional predefined color tables may be added to the default IDL color table file in future versions of IDL. Consequently, one should verify the assigned color table indices in future versions of IDL, before choosing a new color table index to add to the color table file.)
3.) Launch the XPALETTE tool, which can be used to define a new color table, by issuing the IDL command:
XPALETTE
4.) In the XPALETTE GUI, load a predefined color table to modify (by clicking on the Predefined button to launch the XLOADCT tool to select a color table; dismiss XLOADCT after selecting a color table), and/or simply begin modifying the color elements of the currently loaded color table, to define your new color table.
For example, to create your own red-white-blue gradient color table, do the following:
a.) Select color index 0, and then reposition the sliders labeled "Red", "Green" and "Blue" such that Red has the value 255, Green is 0 and Blue is 0.
b.) Then with color index 0 still selected, click on the Set Mark button.
c.) Next click on or select color index 128, and then reposition the sliders such that Red is 255, Green is 255 and Blue is 255.
d.) With color index 128 still selected, click on Interpolate. Then to see the change to the intermediate color index elements, click on the Redraw button.
e.) Then, with the color index 128 selected, click on the Set Mark button.
f.) Next click on or select color index 255, and then reposition the slider to Red = 0, Green = 0 and Blue = 255.
g.) With color index 255 still selected, click on Interpolate. Again, to see the change to the intermediate color index elements, click on the Redraw button.
Figure 1: XPALETTE with custom red-white-blue color table defined.
h.) Click on the "Done" button to properly dismiss XPALETTE.
The new color table that you defined is now loaded into the IDL session memory, but not yet added to the color table file.
You can verify that the colors are loaded into memory by issuing the commands:
TVSCL, DIST(256,256)
Figure 2: Example image displayed using currently loaded custom red-white-blue color table.
4.) Access the currently loaded red, green and blue color table vectors by issuing the following command:
TVLCT, red, green, blue, /GET
5.) Add your new predefined color table as index "41", and with a name of "red-white-blue" to your copy of the IDL color table file (e.g., "C:\Users\joeuser\myidlcolors.tbl") by issuing the command:
file = 'C:\Users\joeuser\myidlcolors.tbl'
MODIFYCT, 75, 'red-white-blue', red, green, blue, FILE=file
Note that the MODIFYCT command above can only modify an existing copy of an IDL color table file. If not already done, as mentioned previously, you can copy the original IDL color table file, which is located in your IDL installation under the [IDL-directory]/resource/colors/ subdirectory, to a convenient writable location such as your home directory, and then modify this copy of the file. For example, for IDL 8.2 on Windows 7 in the default location, the IDL color table file is located at:
C:\Program Files\exelis\idl82\resource\colors\colors1.tbl
You could save a copy of this file in your home directory, renaming it, for example, to "myidlcolors.tbl":
C:\Users\joeuser\myidlcolors.tbl
|
---
At this point, predefined color table 75 has been added to the custom IDL color table file:
C:\Users\joeuser\myidlcolors.tbl
To load custom color table index 75 from the custom color table file to the IDL session direct graphics environment, issue the command:
LOADCT, 75, FILE='C:\Users\joeuser\myidlcolors.tbl'
Or to interactively load color table 75, issue the command:
XLOADCT, FILE='C:\Users\joeuser\myidlcolors.tbl'
and then select color table 75 to load it (click Done to dismiss XLOADCT).
Figure 3: XLOADCT with new custom red-white-blue color table selected.
Draw a test image to verify the colors:
TVSCL, DIST(256,256)
You can also use your new color table entry with IDL 8 function graphics, for example:
LOADCT, 75, FILE='C:\Users\joeuser\myidlcolors.tbl'
TVLCT, red, green, blue, /GET
rwb = [[red],[green],[blue]]
surf = Surface(data, VERT_COLORS=BYTSCL(data), RGB_TABLE=rwb)
cb = Colorbar(POSITION=[.3, .8, .7, .85])
Figure 4: Example new graphics Surface and Colorbar using the new custom red-white-blue color table.
Reviewed on 11-Sep-2014 by JU, DS