Color bar colors not matching Image colors [message #87306] |
Thu, 23 January 2014 12:30  |
fischertc13
Messages: 4 Registered: October 2012
|
Junior Member |
|
|
Hi all,
I'm having trouble getting colors in a 2D data array to agree with my colorbar range. How can I set a Min and Max value for colors in an image without requiring the data be scaled to use the whole range?
i.e. My color bar goes from -500 (blue) to 500 (red) and the values in the field only range between 100 and 400. How do I set the colors in the field to match their corresponding colors in the colorbar? I know they are not currently corresponding because I am getting blue colors in field even though there are no negative values.
I tried setting Min = -500 and Max = 500 in the cgimage command, but it did not seem to make a difference.
I'm sure there is some simple oversight here, but I'm not finding it.
Cheers,
Travis
;; Image
i = WHERE(velarray EQ 0.000, count)
IF (count GT 0) THEN velarray[i] = 600 ; non-measurements will be transparent
LOADCT,0
background = BYTARR(720,600)
background(*,*) = 255 ; creates a white background
CGIMAGE, velarray, AlphaBackgroundImage=background, CTIndex=34, $
Missing_Value=600, POSITION=[.12,.10,.83,.95]
;; Axes Overplot - Likely irrelevant here
PLOT,[1],[1],/nodata,xrange = [-1.5,1.5],yrange= [-1.5,1.5], $
xstyle=1,ystyle=1,position = [.12,.10,.83,.95],xtitle = 'Arcseconds', $
ytitle = 'Arcseconds', title = '[SIII] Velocity - Red Line'
;; Color Bar
LOADCT,34
CGCOLORBAR, position=[0.83,0.10,0.86,0.95], divisions=6, minor=7, $
format='(F5.0)', range=[-500, 500], title='Velocity (km/s)', /vertical, /right
|
|
|
Re: Color bar colors not matching Image colors [message #87307 is a reply to message #87306] |
Thu, 23 January 2014 13:03   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Travis Fischer writes:
> I'm having trouble getting colors in a 2D data array to agree with my colorbar range. How can I set a Min and Max value for colors in an image without requiring the data be scaled to use the whole range?
>
> i.e. My color bar goes from -500 (blue) to 500 (red) and the values in the field only range between 100 and 400. How do I set the colors in the field to match their corresponding colors in the colorbar? I know they are not currently corresponding because I am getting blue colors in field even though there are no negative values.
>
> I tried setting Min = -500 and Max = 500 in the cgimage command, but it did not seem to make a difference.
>
> I'm sure there is some simple oversight here, but I'm not finding it.
Humm. Quite a bit going wrong here. :-)
Basically, to display color images this way your image has to be scaled
into no more than 256 colors. To make your color bar match your image,
it has to use the same colors you use to display the image. I would
recommend you use *less* than 256, since it appears you want some colors
for other things (like the missing data).
You will be further ahead if you learn how to scale your data yourself,
rather than letting programs like cgImage do it for you. This will allow
you to understand what programs that *do* scale your data have to cope
with. In this case, you can't have your cake and eat it, too. In other
words, you can't use 256 colors for your image AND use another color for
the missing data. There are ONLY 256 colors.
Suppose you decided to use 250 colors for your image. That would allow
you to use 6 colors for other things. You could scale your data like
this:
velarrayScaled = BytScl(velarray, MIN=-500, MAX=500, TOP=249)
Now your data is scaled into the range 0 to 249, or 250 colors. If you
wanted to use a missing color, you could assign it the value of, say,
252.
indicies = Where(velarray EQ 0., count)
IF count GT 0 THEN velarrayScaled[indicies] = 252
Now, you can load your colors for this display.
cgLoadCT, 34, NColors=250
Now, display your data:
cgImage, velarrayScaled, MISSING_VALUE=252, MISSING_INDEX=252, $
MISSING_COLOR='charcoal', ...
Not sure what you are doing with the Plot command. Erasing the image you
just put in the window is what it looks like to me. All of that can be
done with keywords to cgImage, if you are interested.
Finally, display a color bar that uses the same colors as the image.
cgColorbar, NColors=250, Range=[-500, 500], ...
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
|
|
|
|