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

Home » Public Forums » archive » Re: sorting of a multi-dimensional array in only one "direction"/dimension
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: sorting of a multi-dimensional array in only one "direction"/dimension [message #41902] Thu, 02 December 2004 08:10 Go to previous message
JD Smith is currently offline  JD Smith
Messages: 850
Registered: December 1999
Senior Member
On Thu, 02 Dec 2004 15:19:54 +0100, Benjamin Luethi wrote:

> Hi,
>
> I'm looking for an efficient way of sorting a multi-dimensional array in
> only one "direction"/dimension?
>
> I have (let's say) 5 images in an array imgs=uintarr(1024,1024,5).
> I'd like to average pixel values over the 5 images, but only use the
> central three values of each position while discarding the minimum and
> maximum value.
>
> So far, I'm looping through all image positions (1024x1024!) and sorting
> the five elements in each position. (something like
> imgs[x,y,*]=sort(imgs[x,y,*]))
>
> Quote from JD Smith: "A typical rule of thumb: if you're looping over each
> data element individually, there's (probably) a faster way to do it."
> So, in this case that would be...? (something with histograms maybe?)
>
> thanks for your thoughts on this,

In your particular case, this is easy enough, since you're just
excluding one minimum and one maximum value:

m=max(imgs,DIMENSION=3,max_list,MIN=m,SUBSCRIPT_MIN=min_list )
imgs[max_list]=0.0 & imgs[min_list]=0.0
return,total(imgs,3)/3

You might also need to test for/exclude NaNs, but the basic idea is to
set the min and max to zero before totaling along the third dimension.
If you need to exclude NaNs, it's just:

m=max(imgs,DIMENSION=3,max_list,MIN=m,SUBSCRIPT_MIN=min_list ,/NAN)
imgs[max_list]=0.0 & imgs[min_list]=0.0
return,total(imgs,3,/NAN)/((total(finite(imgs),3)-2)>1)

What if you wanted to exlude more than one value? These types of
operations are actually not as easy as they should be in IDL. There
is a wonderful function inside of IRAF called IMCOMBINE (and you won't
find me singing IRAF's praises much), that is a very flexible combiner
of image stacks. Things IMCOMBINE can do:

- Combine with median or mean, or weighted mean.
- Use a reject mask to reject certain pixels
- MINMAX (nlow, nhigh) pixel rejection (e.g., this case is nlow=1,
nhigh=1)
- SIGCLIP reject via a sigma clipping algorithm, with adjustable low
side and high side sigma thresholds.
- AVSIGCLIP which takes advantage of the Poisson noise properties of
photosensors to compute sigmas directly from the median/mean.
- PCLIP or percentile clipping based on the histogram distribution at
each pixel.
- Many other thresholding rejections.

You can read about IMCOMBINE here:

http://iraf.noao.edu/scripts/irafhelp?imcombine

I have mentioned to RSI that they would do well to implement something
in IDL with similar functionality. Actually, standard array
inflation/comparison and WHERE can get you much of the way there. A
cheap addition which would go a bit further towards a full IMCOMBINE
would be to allow MIN and MAX to select the top N_max and/or bottom
N_min values along arbitrary dimensions. If you would find these
types of image operations useful, I urge you to contact RSI and let
them know that an IDL IMCOMBINE, or at the least a more flexible
MIN/MAX, would interest you.

JD
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: IDL and Intel's 64-bit Xeon processor
Next Topic: Re: IDL and Intel's 64-bit Xeon processor

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

Current Time: Fri Oct 10 13:02:50 PDT 2025

Total time taken to generate the page: 0.48199 seconds