On Friday, March 30, 2012 4:48:42 AM UTC-4, Matteo wrote:
> Hallo,
> I've checked many of David's links and I seem to find all pieces for a
> little problem I'm trying to solve...still I can't manage to glue them
> together properly.
> I'm trying to scale an image between arbitrary min and max values,
> with an arbitrary number of levels, and getting the proper (discrete)
> colorbar associated with it. I'm trying to use the new OOB_* options
> to leave values < min in one color and values > max of another.
>
> In the example below, I'd for example to have 10 levels between 0 and
> 3000m, and elevations <0 set to black and elevations > 2000 set to
> white.
>
> I'm also trying to get the same result using bytscl and scale_vector.
>
> Does anybody have any suggestions?
>
> Many thanks,
> Matteo
>
>
> pro cbar
> compile_opt idl2
>
> nclrs=10
> minelev=0.
> maxelev=2000.
> p = [0.02, 0.15, 0.98, 0.98]
>
> cgLoadCT, 33, NColors=nclrs, Bottom=1
> TVLCT, cgcolor('white',/Triple), nclrs+1
>
> image=cgDemoData(7)
> ;scaledImage = Scale_Vector(image, 0, nclrs, MINVALUE=minelev,
> MAXVALUE=maxelev, /nan)
> scaledImage = bytscl(image, MIN=minelev, MAX=maxelev, top=nclrs+1, /
> nan)
>
> cgWindow, WXSize=700, WYSize=700
> cgImage, scaledimage, position = p, MinValue=0, MaxValue=nclrs,
> Top=nclrs-1, /Keep, /Add
> cgColorbar, Position=[p[0], p[1]-0.1, p[2], p[1]-0.05], NColors=nclrs,
> $
> Range=[minelev,maxelev], Divisions=10, bottom=1, $
> /discrete, OOB_Low='black', OOB_High='white', /Add
>
> end
My code to convert images to colors looks like this :
n_colors= ;; whatever you have
sz=SIZE(data,/DIM)
data_colors=FLTARR(sz)
;; in your case
range_values=FINDGEN(n_colors+1)*3000./(n_colors)
;; convert to colors
FOR i=0, n_colors DO data_colors+=data GE range_values[i]
ww=WHERE(data LT 0 OR data GT 3000,nn_w)
IF nn_w GT 0 THEN data_colors[ww]=white_index
Regards,
nata
|