color table [message #8601] |
Wed, 26 March 1997 00:00  |
Ye Hong
Messages: 6 Registered: October 1996
|
Junior Member |
|
|
Does anyone know why the system variable !d.table_size is changing ?
Is !d.table_size machine-dependent?
I have my own color table which includes 235 colors. When I need color
image, I load it in. It has been working fine until yesterday when I
found only first 90 color were loaded. It took me a while to figure out
that !d.table_size was changed from 256 to 90. After I exited and
re-ran IDL several time, I found !d.table_size was changing although it
was 256 in most cases.
Thanks in advance.
-- Ye
|
|
|
Re: color table [message #8604 is a reply to message #8601] |
Wed, 26 March 1997 00:00   |
J.D. Smith
Messages: 214 Registered: August 1996
|
Senior Member |
|
|
Ye Hong wrote:
>
> Does anyone know why the system variable !d.table_size is changing ?
> Is !d.table_size machine-dependent?
!D.Table_Size represents the number of colors in IDL's internal color
table. It depends on your machine color bit depth (e.g. 8-bit or
24-bit).
> I have my own color table which includes 235 colors. When I need color
> image, I load it in. It has been working fine until yesterday when I
> found only first 90 color were loaded. It took me a while to figure out
> that !d.table_size was changed from 256 to 90. After I exited and
> re-ran IDL several time, I found !d.table_size was changing although it
> was 256 in most cases.
!D.Table_Size isn't set until you open an IDL window for the first
time. Until then, it defaults to 256 (which *doesn't* mean you have 256
colors). I open and delete a small window upon startup (via the idl
startup file) to ensure the system variable actually reflects the number
of available colors. Loadct does this for you when loading a built-in
color table. If you don't want to do this on startup, you could always
add code like:
if !d.name eq 'X' and !d.window eq -1 then begin ;Uninitialized?
;;If so, make a dummy window to determine the # of colors available.
window,/free,/pixmap,xs=4, ys=4
wdelete, !d.window
endif
The more colors being used by other applications (e.g. Netscape), the
fewer IDL can take for itself. Likely, when you only got 90, you were
running some other color hungry app.
To implement your color table, either create it on the fly to fit into
!D.Table_Size (which is fine if it's simple -- see
<http://www.dfanning.com/tips/create_colortable.html>), or store the
r,g,b vectors in a file, read them in, and down-sample by interpolation
to fit. This is essentially what loadct does with the built-in color
tables with a set of commands like:
if nc ne 256 then begin ;Interpolate
p = (lindgen(nc) * 255) / (nc-1)
r = r(p)
g = g(p)
b = b(p)
endif
where nc is the number of colors (defaults to !D.Table_Size) and the
r,g,b vectors are read in from colors1.tbl. You could be more careful
with your interpolation, if, for instance, you had a few colors that you
require to be in your map (e.g. some plotting colors at the bottom
end). You might then set these required colors (n of them,say), and
then interpolate the rest of your colormap onto the remaining
!D.Table_Size-n spots in the palette.
Good Luck,
JD
|
|
|
|
Re: Color table [message #40415 is a reply to message #8601] |
Thu, 05 August 2004 08:46   |
R.G. Stockwell
Messages: 363 Registered: July 1999
|
Senior Member |
|
|
"Tmorri" <torrimorri@yahoo.com> wrote in message news:30a2ff5d0dde2057290d4c1a21faa55a@localhost.talkaboutpro gramming.com...
> Hi, can anyone create a color table (200 colors) that goes from yellow to
> green to blue to red to white?
> Thanks a lot.
> Tmorri
Yes, absolutely anyone can.
Cheers,
bob
PS so as not to be %100 smartass,
the r g b colors are:
color[0] = yellow = [255,255,0]
color[64] = green = [0,255,0]
color[ 128] = blue = [ 0, 0,255]
color[192] = red = [255,0,0]
color[255] = white = [255,255,255]
and just ramp the numbers between for each component.
|
|
|
|
Re: Color table [message #58176 is a reply to message #8601] |
Mon, 21 January 2008 07:09   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
WRC2008@gmail.com writes:
> me....again...
>
> Everything works out fine for the blue-white-red, even the background
> color and axis colors, as the colortable.
>
> BUT, I am also working with the blue-red color table, defined as
> follows:
>
>
> steps = 256
> scaleFactor = FINDGEN(steps) / (steps - 1)
> ;color scheme by Fanning to go from blue to red
> tvlct,red,green,blue,/get
> ;Red vector: 0 -> 255
> red = 0 + (255 - 0) * scaleFactor
> ; Green vector: 0 -> 0
> green= REPLICATE(0, steps)
> ; Blue vector: 255 -> 0
> blue = 255 + (0 - 255) * scaleFactor
> TVLCT, red, green, blue
> DEVICE, RETAIN=2, DECOMPOSED=0
> Window, Xsize=steps,Ysize=40, Title='Color Table'
> TV, bindgen(steps) # replicate(1B,40)
>
>
>
> This is also working, fine, but again, my background went to blue, as
> do all the symbols, axes and text in the plot. I would like to change
> background (outside of the plot, but in the window) into white, and
> the rest in black. How can this be done? Just changing to another
> colorvalue e.g. 0 to 255, of course doesn't change with this blue-red
> color table...
The best way to avoid changing the background and foreground
colors is to, well, avoid changing them. :-)
They are located at the top and the bottom of the color table.
(Another good reason not to change them is that if you don't your
PostScript output has a fairly good chance of looking like your
display output.)
Try something like this:
steps = 254
scaleFactor = FINDGEN(steps) / (steps - 1)
;color scheme by Fanning to go from blue to red
tvlct,red,green,blue,/get
;Red vector: 0 -> 255
red = 0 + (255 - 0) * scaleFactor
; Green vector: 0 -> 0
green= REPLICATE(0, steps)
; Blue vector: 255 -> 0
blue = 255 + (0 - 255) * scaleFactor
Loadct, 0, /Silent
TVLCT, red, green, blue, 1
DEVICE, RETAIN=2, DECOMPOSED=0
Window, Xsize=steps,Ysize=40, Title='Color Table'
TV, BytScl(bindgen(steps) # replicate(1B,40), Top=253) + 1B
window, 1
plot, findgen(11)
If you have the CINDEX program, you can have a look at
how your color table looks:
IDL> CIndex
You can find the program here:
http://www.dfanning.com/programs/cindex.pro
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Color table [message #58180 is a reply to message #8601] |
Mon, 21 January 2008 04:35   |
WRC2008
Messages: 14 Registered: September 2007
|
Junior Member |
|
|
me....again...
Everything works out fine for the blue-white-red, even the background
color and axis colors, as the colortable.
BUT, I am also working with the blue-red color table, defined as
follows:
steps = 256
scaleFactor = FINDGEN(steps) / (steps - 1)
;color scheme by Fanning to go from blue to red
tvlct,red,green,blue,/get
;Red vector: 0 -> 255
red = 0 + (255 - 0) * scaleFactor
; Green vector: 0 -> 0
green= REPLICATE(0, steps)
; Blue vector: 255 -> 0
blue = 255 + (0 - 255) * scaleFactor
TVLCT, red, green, blue
DEVICE, RETAIN=2, DECOMPOSED=0
Window, Xsize=steps,Ysize=40, Title='Color Table'
TV, bindgen(steps) # replicate(1B,40)
This is also working, fine, but again, my background went to blue, as
do all the symbols, axes and text in the plot. I would like to change
background (outside of the plot, but in the window) into white, and
the rest in black. How can this be done? Just changing to another
colorvalue e.g. 0 to 255, of course doesn't change with this blue-red
color table...
Thank you!!!
|
|
|
|
Re: Color table [message #58186 is a reply to message #8601] |
Sun, 20 January 2008 09:53   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
WRC2008@gmail.com writes:
> I would like to plot a contour line figure, filled with colors.
> Thereby, positive values should be red-shaded filled, negative blue-
> shaded filled, and white shade around the zero.
>
> Now, I have checked the color table in IDL, and none of them seems to
> have this configuration? If possible, I would like to define the
> colors myself in fixed intervals, like [-10,0] = light grey, [0] =
> white, [0,10] = darkgrey,.... [10,20] = light red, ....
>
> Hope somebody can help me with this!
I would do this:
IDL> CTLoad, 1, NCOLORS=128
IDL> CTLoad, 3, /REVERSE, NCOLORS=128, BOTTOM=128
You can find CTLOAD here:
http://www.dfanning.com/programs/ctload.pro
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Color table [message #58187 is a reply to message #8601] |
Sun, 20 January 2008 07:58   |
mmiller3
Messages: 81 Registered: January 2002
|
Member |
|
|
This is what I use for making tables like you are looking for:
;; Set up a blue=negative, red=positive color scale. The
;; middle of the scale is black:
red = [bytarr(128), 2*bindgen(128)]
green = bytarr(256)
blue = [2*reverse(bindgen(128)), bytarr(128)]
color_table = 0
tvlct, red, green, blue
;; Set up a blue=negative, red=positive color scale. The
;; middle of the scale is white:
H = [replicate(240.0, 128), replicate(360.0, 128)]
S = 2*[reverse(findgen(128)), findgen(128)]/255
V = fltarr(256)+1
tvlct, H, S, V, /hsv
tvlct, R, G, B, /get
red = R
green = G
blue = B
color_table = 0
tvlct, red, green, blue
Mike
|
|
|
Re: Color table [message #58189 is a reply to message #8601] |
Sat, 19 January 2008 10:39   |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Jan 19, 6:20 am, WRC2...@gmail.com wrote:
> Dear all,
>
> I would like to plot a contour line figure, filled with colors.
> Thereby, positive values should be red-shaded filled, negative blue-
> shaded filled, and white shade around the zero.
>
> Now, I have checked the color table in IDL, and none of them seems to
> have this configuration? If possible, I would like to define the
> colors myself in fixed intervals, like [-10,0] = light grey, [0] =
> white, [0,10] = darkgrey,.... [10,20] = light red, ....
>
> Hope somebody can help me with this!
>
> Cheers,
> Matthias
http://www.dfanning.com/color_tips/create_colortable.html
|
|
|
|
|
|
Re: Color table [message #58281 is a reply to message #8601] |
Fri, 25 January 2008 02:35   |
WRC2008
Messages: 14 Registered: September 2007
|
Junior Member |
|
|
On Jan 25, 10:15 am, David Fanning <n...@dfanning.com> wrote:
> WRC2...@gmail.com writes:
>> it seems this is never going to work. I tried this program, after
>> getting the fsc_color function from your website, and now he tells me
>> the following:
>
>> Compiled module: FSC_COLOR.
>> % Attempt to call undefined procedure/function: 'FSC_COLOR'.
>
>> How is this possible? I got the module like I already got many modules
>> from your website, and all worked beforehand...except this one...
>
> You do seem to be running into an extraordinary number
> of strange problems. Have you noticed anyone giving you
> the Evil Eye lately. :-)
>
> Did you save the function to some location on your IDL path?
> IDL has to be able to find it. It looks in the list of directories
> on its !PATH system variable:
>
> IDL> Print, !PATH
>
Yes, of course! I save all my uploaded modules into the lib directory,
and normally, everything works (like I used the cindex.pro,
ctload.pro,...). But this time, the evil eye has taken
over....grrr....I have no idea what is going on?
|
|
|
|
Re: Color table [message #58283 is a reply to message #8601] |
Fri, 25 January 2008 00:54   |
WRC2008
Messages: 14 Registered: September 2007
|
Junior Member |
|
|
> PRO testcolor
>
> Device, Decomposed=0, Get_Decomposed=theState
> CTLoad, 1, NCOLORS=127, CLIP=[10, 245]
> CTLoad, 3, NCOLORS=127, BOTTOM=127, CLIP=[10, 245]
> white = FSC_Color('white', 254) ; Background
> black = FSC_Color('black', 255) ; Foreground
> Erase, COLOR=white
> pos = [0.1, 0.1, 0.9, 0.9]
> TVImage, Bytscl(dist(200), top=253), POSITION=pos
> Plot, [0,200], /NODATA, POSITION=pos, /NOERASE, COLOR=black
>
> void = TVREAD(/PNG, Filename='testcolor')
> Device, Decomposed=theState
>
> END
it seems this is never going to work. I tried this program, after
getting the fsc_color function from your website, and now he tells me
the following:
Compiled module: FSC_COLOR.
% Attempt to call undefined procedure/function: 'FSC_COLOR'.
How is this possible? I got the module like I already got many modules
from your website, and all worked beforehand...except this one...
|
|
|
Re: Color table [message #58294 is a reply to message #8601] |
Thu, 24 January 2008 10:00   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
WRC2008@gmail.com writes:
>
>> OK, can you tell me the results of this command:
>>
>> IDL> Help, /Device
>
> Screen Resolution: 1280x800
> Simultaneously displayable colors: 16777216
> Number of allowed color values: 16777216
> System colors reserved by Windows: 0
> IDL Color Table Entries: 256
> NOTE: this is a TrueColor device
> NOT using Decomposed color
> Graphics Function: 3 (copy)
> Current Font: System, Current TrueType Font: <default>
> Default Backing Store: None.
Well, here is a program. No salmon colors here! :-)
PRO testcolor
Device, Decomposed=0, Get_Decomposed=theState
CTLoad, 1, NCOLORS=127, CLIP=[10, 245]
CTLoad, 3, NCOLORS=127, BOTTOM=127, CLIP=[10, 245]
white = FSC_Color('white', 254) ; Background
black = FSC_Color('black', 255) ; Foreground
Erase, COLOR=white
pos = [0.1, 0.1, 0.9, 0.9]
TVImage, Bytscl(dist(200), top=253), POSITION=pos
Plot, [0,200], /NODATA, POSITION=pos, /NOERASE, COLOR=black
void = TVREAD(/PNG, Filename='testcolor')
Device, Decomposed=theState
END
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
|
|
Re: Color table [message #58298 is a reply to message #8601] |
Thu, 24 January 2008 09:02   |
WRC2008
Messages: 14 Registered: September 2007
|
Junior Member |
|
|
On Jan 24, 5:19 pm, David Fanning <n...@dfanning.com> wrote:
> WRC2...@gmail.com writes:
>> I have tried plotting the 9 plots a page into a ps file, but also
>> there many things went wrong, so therefore, I opt to use the window
>> file and write it with write_png. But in there, my background has this
>> salmon color....
>
> Ah, well, have you tried using TVREAD to create your
> PNG file? Lot's of things could be going wrong with
> how this file is created. TVREAD almost always gives
> good results:
>
> http://www.dfanning.com/programs/tvread.pro
>
> See the code there for details.
>
> Cheers,
>
> David
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming (www.dfanning.com)
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Hummmm....I really would like to thank you for all the help, but
still I can't get it right. As you suggest, I use TVread to create a
tiff file, which is written to the file, but again, with this salmon
background.
img=tvread(filename=output+'plot',tiff)
The plots looks perfect, just this background color seems to be
untouchable???
|
|
|
Re: Color table [message #58299 is a reply to message #8601] |
Thu, 24 January 2008 08:19   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
WRC2008@gmail.com writes:
> I have tried plotting the 9 plots a page into a ps file, but also
> there many things went wrong, so therefore, I opt to use the window
> file and write it with write_png. But in there, my background has this
> salmon color....
Ah, well, have you tried using TVREAD to create your
PNG file? Lot's of things could be going wrong with
how this file is created. TVREAD almost always gives
good results:
http://www.dfanning.com/programs/tvread.pro
See the code there for details.
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
|
Re: Color table [message #58310 is a reply to message #8601] |
Thu, 24 January 2008 05:04   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
WRC2008@gmail.com writes:
> Just one more fact (again, as also posted in another topic....). My
> background color changed again.
Changed again where? On the display? In a PS file?
> Although I define the blue-white-red color table just before putting !
> P.BACKGROUND = 128, checking the 128 color with the cindex tool (being
> white!!), I get a salmon color background, and by no means I can
> change it to white. I can change it to all other colors I want (black,
> blue, red,...) but no white....I am getting a bit desperate with the
> colors here, so I hope someone can help me out!!!
The question is not what the background color is just before
you set !P.Background. The question is, what is the background
color just before you draw your background? If you are using
indexed color (extremely likely from your description of things),
then colors can be changed all the time. You have to have
the right colors in the color table at the time you draw
the thing that is suppose to be in those particular colors.
Or, you can use 24-bit color and have all 16.7 million
colors available 24/7. Have you read the several hundred
articles on color management on my web page? :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: Color table [message #58311 is a reply to message #58176] |
Thu, 24 January 2008 00:31   |
WRC2008
Messages: 14 Registered: September 2007
|
Junior Member |
|
|
Just one more fact (again, as also posted in another topic....). My
background color changed again.
Although I define the blue-white-red color table just before putting !
P.BACKGROUND = 128, checking the 128 color with the cindex tool (being
white!!), I get a salmon color background, and by no means I can
change it to white. I can change it to all other colors I want (black,
blue, red,...) but no white....I am getting a bit desperate with the
colors here, so I hope someone can help me out!!!
The 2 defined color schemes, as suggested by David:
; blue - red
ctload, 1, clip=[10,235], ncolors=128
ctload, 3, clip=[10,235], /reverse, ncolors=128, bottom=128
;blue - white - red
CTLoad, 1, NCOLORS=128
CTLoad, 3, /REVERSE, NCOLORS=128, BOTTOM=128
THANKS!
|
|
|
Re: Color Table [message #72178 is a reply to message #8601] |
Wed, 18 August 2010 05:44   |
Nikola
Messages: 53 Registered: November 2009
|
Member |
|
|
The specified values are not equidistant, so the correct solution is:
r= interpol([0,100,120,20,0,50], [0, 28, 46, 89, 153, 255],
findgen(256))
g= interpol([0,30,20,20,200,220], [0, 28, 46, 89, 153, 255],
findgen(256))
b= interpol([0,150,40,255,230,50], [0, 28, 46, 89, 153, 255],
findgen(256))
tvlct,r,g,b
Cheers,
Nikola
|
|
|
Re: Color Table [message #72186 is a reply to message #8601] |
Tue, 17 August 2010 06:32   |
panblosky
Messages: 17 Registered: May 2005
|
Junior Member |
|
|
On 17 ago, 14:42, Wox <s...@nomail.com> wrote:
> On Tue, 17 Aug 2010 03:27:37 -0700 (PDT), Andres <panblo...@gmail.com>
> wrote:
>
>
>
>> Dear all,
>
>> I want to create a color table with the following values:
>
>> index red green blue
>> 0 0 0 0
>> 28 100 30 150
>> 46 120 20 40
>> 89 20 20 255
>> 153 0 200 230
>> 255 50 220 80
>
>> I tried with the xpalette, but when I interpolate, it just gives
>> everything green. Am I doing something wrong? Is there a simple way to
>> do this?
>
>> Thanks!
>
>> Pablo
>
> How about this:
>
> r=congrid([0,100,120,20,0,50],256,/interp)
> g=congrid([0,30,20,20,200,220],256,/interp)
> b=congrid([0,150,40,255,230,50],256,/interp)
> tvlct,r,g,b
> window & tvscl,dist(200)
Thanks!
|
|
|
Re: Color Table [message #72187 is a reply to message #8601] |
Tue, 17 August 2010 05:42   |
Wout De Nolf
Messages: 194 Registered: October 2008
|
Senior Member |
|
|
On Tue, 17 Aug 2010 03:27:37 -0700 (PDT), Andres <panblosky@gmail.com>
wrote:
> Dear all,
>
> I want to create a color table with the following values:
>
> index red green blue
> 0 0 0 0
> 28 100 30 150
> 46 120 20 40
> 89 20 20 255
> 153 0 200 230
> 255 50 220 80
>
> I tried with the xpalette, but when I interpolate, it just gives
> everything green. Am I doing something wrong? Is there a simple way to
> do this?
>
> Thanks!
>
> Pablo
How about this:
r=congrid([0,100,120,20,0,50],256,/interp)
g=congrid([0,30,20,20,200,220],256,/interp)
b=congrid([0,150,40,255,230,50],256,/interp)
tvlct,r,g,b
window & tvscl,dist(200)
|
|
|
Re: Color table [message #81901 is a reply to message #8601] |
Sat, 10 November 2012 17:38  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Gompie writes:
> I have a single variable spread over three years. I wish to give a
different color to each year.
>
> But instead of color I get grey scale. I have the following script.
>
>
> cgLoadCT, 4, NCOLORS=3, CLIP=[16,240]
> bplate=fltarr(18)
> name=strarr(18)
> mont=fltarr(19)
> years=fltarr(19)
> ffiles = FILE_SEARCH('*.txt1')
> for index=0,n_elements( ffiles)-1 do begin
> year=(strsplit(ffiles(index),'.,_',/extract))[0]
> month=(strsplit(ffiles(index),'.,_',/extract))[1]
> name(index)=string(month)
> years(index) = float(year)
> OPENR, lun, ffiles(index), /GET_LUN
> temp=0.0D
> i=0L
> data=strarr(1)
> print,ffiles(index)
> WHILE ~ EOF(lun) DO BEGIN
> readf,lun,data
> temp=float(data) + temp
> i=i+1
> ;print,i,float(data),data
> ENDWHILE
> print,temp/i
> bplate(index)=temp/i
> mont(index)=index
> close,lun
> free_lun,lun
> endfor
>
> colors = Scale_Vector(Findgen(3), 2009, 2011)
>
> elevColors = Value_Locate(colors,years )
> elevColors = StrTrim(Round(Scale_Vector(elevColors, 0, 10)),2)
>
> !X.TICKNAME=name
>
> cgplot,mont,bplate,psym=4,thick=2,xticks=17,yrange=[260,270] ,xtitle='MONTHS',ytitle='MIN_0_87_MICRON_DETECTOR_TEMP',BACK GROUND = 255, COLOR = 0
> FOR j=0,n_elements(mont)-2 DO cgPlotS, mont[j], bplate[j], Color=elevColors[j], Thick=2,psym=sym(5),symsize = 1.15
> fname="bplate.gif"
> result = cgSnapshot(FILENAME=fname,/gif ,/nodialog)
Uh, well, I think I would just do something like this:
elevColors = ['red', 'green', 'blue']
> Question .2 . Is it possible to view the exact colors Vs color number that are finally loaded by the color table.
Try CIndex:
IDL> cindex
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|