[AIT logo]

Institut für Astronomie und Astrophysik

Abteilung Astronomie

Sand 1, D-72076 Tübingen, Germany
[Uni logo]


MEDARR Source code in medarr.pro

MEDARR

Name
       MEDARR
Purpose
       Compute the median at each pixel across a set of 2-d images
Explanation
       Each pixel in the output array contains  the median of the
       corresponding pixels in the input arrays.   Useful, for example to
       combine a stack of CCD images, while removing cosmic ray hits.
       This routine became partially obsolete in V5.6 with the introduction
       of the DIMENSION keyword to the intrinsic MEDIAN() function.   However,
       it is  still useful if a input mask is needed (though it is much
       faster to set invalid pixels to NaN values.)
Calling Sequence
       MEDARR, inarr, outarr, [ mask, output_mask ]
Input Parameters
       inarr  -- A three dimensional array containing the input arrays to
                 combine together.  Each of the input arrays must be two
                 dimensional and must have the same dimensions.  These arrays
                 should then be stacked together into a single 3-D array,
                 creating INARR.
Optional Input Parameters
       mask   -- Same structure as inarr, byte array with 1b where
                 pixels are to be included, 0b where they are to be
                 excluded.    For floating point images, it is much faster to
                 set masked pixels in inarr equal to !VALUES.F_NAN (see below),
                 rather than use the mask parameter.
Output Parameters
       outarr -- The output array.  It will have dimensions equal to the
                 first two dimensions of the input array.
Optional Output
       output_mask -- Same structure as outarr, byte array with 1b
                      pixels are valid, 0b where all the input pixels
                      have been masked out.
Restrictions
        Prior to V5.6, this procedure was *SLOW* because it had to loop over
        each pixel of the image.   See notes below about an alternative with
        CALL_EXTERNAL.
Example
       Suppose one wants to combine three floating point 1024 x 1024 bias
       frames which have been read into the IDL variables im1,im2,im3
       IDL> bigim = fltarr(1024,1024,3)        ;Create big array to hold images
       IDL> bigim(0,0,0) = im1 & bigim(0,0,1) = im2 & bigim(0,0,2) = im2
       IDL> medarr, bigim, avgbias
       The variable avgbias will be the desired 1024x 1024 float image.
Procedure
       A scalar median function over the third dimension is looped over
       each pixel of the first two dimensions.   The /EVEN keyword is used
       with MEDIAN (which averages the two middle values), since this avoids
       biasing the output for an even number of images.
       Any values set to NAN (not a number) are ignored when computing the
       median.    If all values for a pixel location are NAN, then the median
       is also returned as NAN.
       MEDARR is also available as a C procedure linked to IDL via
       CALL_EXTERNAL (but without the mask parameter).   The callable C
       version is 2-3 times faster for large  (~ 500 x 500 x 7) images.
       Contact W. Landsman (landsman@mpb.gsfc.nasa.gov) for the C program
Revision History
       Written by Michael R. Greason, STX, 12 June 1990.
       Don't use MEDIAN function for even number of images.
          W. Landsman Sep 1996
       Mask added.  RS Hill, HSTX, 13 Mar. 1997
       Converted to IDL V5.0   W. Landsman   September 1997
       Use /EVEN keyword to MEDIAN    W. Landsman  September 1997
       Rearranged code for faster execution   W. Landsman January 1998
       Faster execution for odd number of images   W. Landsman July 2000
       V5.4 fix for change in SIZE() definition of undefined variable
                W. Landsman/E. Young   May 2001
       Use MEDIAN(/DIMEN) for V5.6 or later   W. Landsman   November 2002
       Use keyword_set() instead of ARG_present() to test for presence of mask
           parameter  D. Hanish/W. Landsman   June 2003
       Use MEDIAN(/EVEN) when mask not set V5.6 or later W. Landsman Feb 2004

Last modified by pro2html on 2004 July 28 at 04:05 UTC

[Home Page] [Software, Documentation] [IDL Documentation] [Quick Reference] [Feedback]

Jörn Wilms (wilms@astro.uni-tuebingen.de)
Updated automatically