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

Home » Public Forums » archive » WHERE Function
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: WHERE Function [message #4223 is a reply to message #4152] Fri, 12 May 1995 00:00 Go to previous messageGo to previous message
rivers is currently offline  rivers
Messages: 228
Registered: March 1991
Senior Member
In article <1995May10.175428.15046@ultb.isc.rit.edu>, bjp8350@osfmail.isc.rit.edu (PRYHODA) writes:
> I am using the WHERE function to return the pixel locations of a single object
> in a binary image. The WHERE function returns a LONGWORD VECTOR that can be
> used to subscript the image array. I need to calculate the distance between
> each combination of border pixels to find the object's major axis.
>
> How can I seperate the LONGWORD VECTOR into its X and Y components? so I can
> use the distance formula. Or is there an easier way to find the distance
> between each pixel?
>

Here is a function I wrote to do just that.

____________________________________________________________
Mark Rivers (312) 702-2279 (office)
CARS (312) 702-9951 (secretary)
Univ. of Chicago (312) 702-5454 (FAX)
5640 S. Ellis Ave. (708) 922-0499 (home)
Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)

************************************************************ ********************

function convert_index, index, array

;+
; NAME:
; CONVERT_INDEX
; PURPOSE:
; Converts a one dimensional array index into a vector of indices, whose
; length is equal to the number of dimensions of the array. This is
; useful when wanting to know, for instance, what row and column element
; 10034 corresponds to in a 200x150 2-D array. The routine is general and
; can handle arrays with any number of array dimensions, up to the IDL
; maximum of 7.
; CALLING SEQUENCE:
; new_index = CONVERT_INDEX(index, array)
; INPUTS:
; INDEX
; A 1 dimensional array index to be converted. IDL can reference
; multidimensional arrays using a simple 1 dimensional index.
; Such an index is obtained, for instance from functions such as
; MAX, MIN and WHERE.
; ARRAY
; The array to which this index applies. This routine only uses this
; parameter to determine the array dimensions, it does not actually use
; the data stored in the array.
; OUTPUTS:
; NEW_INDEX
; The function returns an array of indices, in increasing array index
; order. NEW_INDEX has a maximum lenght of 7, since IDL arrays are limited
; to 7 dimensions.
; EXAMPLE:
; If ARRAY is a 4x3 array and INDEX=7 then this function will return
; [3,1], since array element 7 (when ARRAY is viewed as a
; one-dimensional array) is actually column 3, row 1 when ARRAY is viewed
; as a 2-dimensional array.
; MODIFICATION HISTORY:
; Created October 1990 by Mark Rivers
;-


nd = size(array)
ndims = nd(0)

denom = 1
for i=1, ndims do denom = denom * nd(i)
result = lonarr(7)

for i=ndims, 0, -1 do begin
result(i) = index / denom
index = index MOD denom
denom = denom / nd(i)
endfor

return, result(0:ndims-1)
end
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: where function
Next Topic: Need help with map projection conversion in ENVI

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

Current Time: Thu Oct 09 23:15:30 PDT 2025

Total time taken to generate the page: 0.15936 seconds