J.D. Smith (jdsmith@astro.cornell.edu ) writes:
> Craig Hamilton wrote:
>>
>> Hi all:
>> I've run into a little snag dealing with colormaps and thought I would seek
>> the advice of the wise ones.
>>
>> I have an image-viewing program that displays gray-level images.
>> Works great. I had this idea that I wanted to make some
>> of settings user-selectable on startup, so I first popped up a window with
>> some radio buttons in it. One set of radio buttons lets the user select
>> the number of gray-levels used in the colormap.
>>
>> The problem is that IDL requires something like:
>> window,0,colors=numcolors,/pixmap,xsize=10,ysize=10
>> wdelete,0
>>
>> to initially setup the colormap, prior to any windows being created.
>>
>> But, I have already created my popup window. So it seems to me
>> I'm in a catch-22: I have to specify the number of colors before I
>> create my popup window, but I don't know the number of desired
>> colors until after I have created my popup window.
>>
>> My popup doesn't create any draw widgets, if that matters.
>>
>> So, the question is:
>> Is it possible to use a popup window to get from the user the number
>> of desired gray-levels?
>>
>> I hope this is clear. Any tips most appreciated.
I'm traveling and didn't see the original post from Craig,
but JD quotes enough that I get the general idea, I think.
Craig is correct in thinking that opening the first IDL
graphics window establishes the number of colors in that
IDL session, but I think he is misunderstanding the notion
of the "number of gray-levels" an image can have. The first
is a physical limitation (more or less, but I don't really
want to get into it), the second is a *display* function
and has nothing to do with anything other than what the
IDL programmer chooses to do. In practice an image can
be displayed with *any* number of gray levels, up to and
including the number of colors or levels available in the
IDL session.
Here is a program that would let you select the number
of gray-levels and display an image with that number.
Call it like this:
IDL> Choose_Levels, myimage
PRO Choose_Levels_Quit, event
Widget_Control, event.top, /Destroy
END; ----------------------------------------------------
PRO Choose_Levels_Slider, event
Widget_Control, event.top, Get_UValue=ptr
*ptr = event.value
END; ----------------------------------------------------
PRO Choose_Levels, image
IF N_Elements(image) EQ 0 THEN image = DIST(400)
Window, /Free, /Pixmap, XSize=10, YSize=10
WDelete, !D.Window
ncolors = !D.Table_Size
tlb = Widget_Base(Title='Choose Gray-Scale Levels...', Column=1)
slider = Widget_Slider(tlb, Value=(100 < ncolors), Min=0, Max=ncolors, $
Title='Levels', Event_Pro='Choose_Levels_Slider')
done = Widget_Button(tlb, Value='Done', Event_Pro='Choose_Levels_Quit')
Widget_Control, tlb, /Realize
ptr = Ptr_New(100 < ncolors)
Widget_Control, tlb, Set_UValue=ptr
XManager, 'choose_levels', tlb ; Block here until program destroyed.
levels = *ptr
Print, 'Number of gray-scale levels: ', levels
LoadCT, 0, NColors=levels ; Load number of gray-scale levels.
s = Size(image, /Dimensions)
Window, /Free, XSize=s[0], YSize=s[1], $
Title='Gray-Scale Levels: ' + StrTrim(levels,2)
Device, Decomposed=0
TV, BytScl(image, Top=levels-1) ; Display image with gray-scale levels.
Ptr_Free, ptr
END; ----------------------------------------------------
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|