comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Function that returns the dimension of an array?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Function that returns the dimension of an array? [message #32751] Fri, 01 November 2002 20:40 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
K Banerjee (kbanerjee@ucwphilly.rr.com) writes:

> Is there such a function in IDL? Say the array A is 2 by 3. I am looking for
> a function that returns an array containing the entries 2 and 3.

You are looking for this:

dim = Size(array, /Dimensions)

While we are on the subject though, here is a one-off
that I find myself using over and over in my own work.
I use it to find the proper window size for images,
when I am not sure if I have an 8-bit or 24-bit
image, or how the 24-bit image is interleaved. Might
be handy to someone. :-)

dim = ImageDimensions(unkownImage, XSize=xsize, $
YSize=ysize, TrueIndex=trueIndex
Window, XSize=xsize, YSize=ysize
TV, unknownImage, True=trueIndex

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155

;*********************************************************** ***
FUNCTION ImageDimensions, image, $

; This function returns the dimensions of the image, and also
; extracts relevant information via output keywords. Works only
; with 2D and 3D (24-bit) images.

; All keywords are OUTPUT keywords.

XSize=xsize, $ ; The X size of the image.
YSize=ysize, $ ; The Y size of the image.
TrueIndex=trueindex, $ ; Position of "true color" index (0 for 2D).
XIndex=xindex, $ ; The position or index of the X image size.
YIndex=yindex ; The position or index of the Y image size.

; Get the number of dimensions and the size of those dimensions.

ndims = Size(image, /N_Dimensions)
dims = Size(image, /Dimensions)

; Is this a 2D or 3D image?

IF ndims EQ 2 THEN BEGIN
xsize = dims[0]
ysize = dims[1]
trueindex = -1
xindex = 0
yindex = 1
ENDIF ELSE BEGIN
IF ndims NE 3 THEN $
Message, /NoName, 'Unknown image dimensions. Returning.'
true = Where(dims EQ 3, count)
trueindex = true[0] + 1
IF count EQ 0 THEN Message, /NoName, 'Unknown image type. Returning.'
CASE true[0] OF
0: BEGIN
xsize = dims[1]
ysize = dims[2]
xindex = 1
yindex = 2
ENDCASE
1: BEGIN
xsize = dims[0]
ysize = dims[2]
xindex = 0
yindex = 2
ENDCASE
2: BEGIN
xsize = dims[0]
ysize = dims[1]
xindex = 0
yindex = 1
ENDCASE
ENDCASE
ENDELSE
RETURN, dims
END
;*********************************************************** ****
[Message index]
 
Read Message
Read Message
Previous Topic: Function that returns the dimension of an array?
Next Topic: Re: VRML export in IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 20:56:35 PDT 2025

Total time taken to generate the page: 1.36285 seconds