Re: Colormaps (a favorite subject!) [message #19431] |
Mon, 27 March 2000 00:00 |
Craig Hamilton
Messages: 28 Registered: December 1996
|
Junior Member |
|
|
David:
Thanks for the code, but my problem is not with grey-levels vs.
number of colormap entries. My problem is as originally stated
it: I want the user to be able to select the number of colors
in the colormap, but I can't popup a window to get that information
without having the number of colormap entries already set
in the act of popping up the window. I must not be explaining
myself very well. I've done loads of image processing programming
in other languages on Unix and Windoze, so I'm familiar
with colormaps and scaling of image data for display.
I'm working with 16-bit data on 8-bit displays right now and I want to
avoid color-flashing, so I want to use from 32 to 128 colormap
entries for this display program. I want the user to be
able to select how many entries are used.
Maybe a little more simply:
I have been initializing the size of the colormap used with:
window,0,colors=numcolors,/pixmap,xsize=10,ysize=10
wdelete,0
But now I just want to get the number 'numcolors' from the user first.
I think I am realizing that I cannot get that number with a widget.
Right?
Craig
PS: I really appreciate all the time you spend helping us
IDL novices out.... where do we mail the beer?
>
> 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.
> 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
|
|
|
Re: Colormaps (a favorite subject!) [message #19441 is a reply to message #19431] |
Sun, 26 March 2000 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
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
|
|
|
Re: Colormaps (a favorite subject!) [message #19445 is a reply to message #19441] |
Fri, 24 March 2000 00:00  |
John-David T. Smith
Messages: 384 Registered: January 2000
|
Senior Member |
|
|
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.
You could save the user preference in a file, and read it in. It wouldn't work
for the same session, but at least it would be something.
JD
--
J.D. Smith |*| WORK: (607) 255-5842
Cornell University Dept. of Astronomy |*| (607) 255-6263
304 Space Sciences Bldg. |*| FAX: (607) 255-5875
Ithaca, NY 14853 |*|
|
|
|