Re: color .ps/gamma_ct [message #10809] |
Fri, 23 January 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Peter Gallagher (P.Gallagher@qub.ac.uk) writes:
> I'm trying to plot two images in one Postscript file using the
> same color table. The only problem is that I want to apply a
> different gamma correction to each image.
> The GAMMA_CT changes the appearance of both the images each time
> it is applied - I want a separate gamma correction for each image.
>
> Any body come up against this problem before?
This is another of those "color awareness" issues that
comes up over and over and is a weakness, I think, in
the routines that are supplied with IDL. This is one
of the things I harp on in my book and I even supply
several routines (e.g., XColors) to help you solve
the problem.
Here is a better routine named Set_Gamma that can
be used to change the gamma correction. It uses the
keywords NCOLORS and BOTTOM so that you can determine
just which portion of the color table you want to change
the gamma correction on. It will allow you to have
two (or more) independent images with different gamma
corrections.
Suppose I had 200 colors and I wanted to use the
gray-scale color table for each, but I want each
image to have a different gamma correction. I would
do it like this:
image = GETImage()
LoadCT, 0, NColors=100
LoadCT, 0, NColors=100, Bottom=100
Set_Gamma, 0.7, NColors=100
Set_Gamma, 0.3, NColors=100, Bottom=100
TV, BytScl(image, Top=99)
TV, BytScl(Image, Top=99) + 100B
Cheers,
David
***************************************************
PRO Set_Gamma, gamma, NColors=ncolors, Bottom=bottom
IF N_Elements(ncolors) EQ 0 THEN ncolors = (!D.N_Colors < 256)
IF N_Elements(bottom) EQ 0 THEN bottom = 0
; Keep gamma between 0.1 and 10.
IF N_Params() EQ 0 THEN gamma = 1.0
gamma = gamma > 0.1
gamma = gamma < 10.0
; Get the current color table vectors.
TVLCT, r, g, b, /Get
; Pull the colors needed.
red = r[bottom:ncolors-1+bottom]
green = g[bottom:ncolors-1+bottom]
blue = b[bottom:ncolors-1+bottom]
; Apply gamma correction.
index = Findgen(ncolors)
distribution = index^gamma
index = Round(distribution * (ncolors-1) / Max(distribution))
red = Congrid(red(index), ncolors)
green = Congrid(green(index), ncolors)
blue = Congrid(blue(index), ncolors)
; Update the color table vectors.
r[bottom:ncolors-1+bottom] = red
g[bottom:ncolors-1+bottom] = green
b[bottom:ncolors-1+bottom] = blue
; Reload the color table.
TVLCT, r, g, b
END
***********************************************************
-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438
Coyote's Guide to IDL Programming: http://www.dfanning.com/
|
|
|