Re: transparent routine using either readu or assoc for same array variable [message #10853 is a reply to message #10849] |
Sun, 15 February 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
Jacobus Koster (nosuch@ix.netcom.com) writes:
> Ye of wisdom,
> I would like to write a routine to open a file and read an image stack,
> say 128x128 images, 96 of 'em. I would like to be able to pass a keyword
> to this routine, telling it to either read the whole file into an image
> array, or alternately associates it with such an array of the same name
> and dimensions.
FUNCTION READ_STACK, filename, ASSOCIATE=associate
IF N_Params() EQ 0 THEN filename = Dialog_Pickfile()
IF filename EQ '' THEN RETURN, -1
OpenR, lun, filename, /Get_Lun
IF Keyword_Set(associate) THEN BEGIN
image = ASSOC(lun, IntArr(128, 128))
ENDIF ELSE BEGIN
image = IntArr(128,128,96)
READU, lun, image
FREE_LUN, lun
ENDELSE
RETURN, image
END
Now, if you want the whole stack in a variable, you type
this:
image = Read_Stack('myfile.dat')
If you want to display the 20th image, you type:
TV, image(*,*,19)
If you want to do something with a particular slice, you
probably do something like this:
thisImage = Reform(image(*,*,19))
TV, thisImage * factor
The REFORM function will get rid of the third single dimension
for you.
If you want to use the associated variable method, which
I STRONGLY recommend, and you want to display the 20th image
you do this:
TV, image(19)
The Associate variable method will only read and write the
data when it is required. This will be a much more efficient
way to work with this kind of data.
Cheers,
David
-----------------------------------------------------------
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/
|
|
|