Re: transparent routine using either readu or assoc for same array variable [message #10849] |
Mon, 16 February 1998 00:00 |
Evilio del Rio
Messages: 17 Registered: December 1997
|
Junior Member |
|
|
Jacobus Koster wrote:
>
> 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.
> E.g.:
> ...
> Can I name an array of 96 elements in this way, each array element being
>
> a 128x128 image, or do I have to define a structure of 128x128 integer
> arrays,
> , and if so, can I use assoc and readu transparently
> with the same array structure name ?
>
> Thanks for your help,
> Sjaak Koster
Hi Jacobus,
I think it's easier than that. Just use READ or ASSOC and access the
data either as a collection of 96 images:
OPENR,1,Filename
Image = BYTARR(128L,128L,96L)
readu,1,Image
close,1
(...)
process_image,Image[*,*,i]
then you will get Image as an array of 128x128x96 (i.e. 96 128x128
images). Either with random I/O:
OPENR,1,Filename
Stack = ASSOC(1, BYTARR(128L,128L))
(...)
Image = Stack[i]
process_image,Image
here Image is just a 128x128 image. You access different images through
the assignement "Image = Stack[i]". Since it seems that you process your
images sequentally and they are not too big, I would prefer 1st solution
because all I/O is made once for all.
Hope this helps.
Cheers,
____________________________________________________________ ________
Evilio Jose del Rio Silvan Institut de Ciencies del Mar
E-mail: edelrio@icm.csic.es URL: http://www.ieec.fcr.es/~evilio/
"Anywhere you choose,/ Anyway, you're gonna lose"- Mike Oldfield
|
|
|
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/
|
|
|