Ignore:
Timestamp:
07/12/07 11:43:56 (17 years ago)
Author:
mar637
Message:

Added running median to smooth. This addresses Ticket #115

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/MathUtils.cpp

    r1325 r1373  
    3232#include <casa/aips.h>
    3333#include <casa/Arrays/Vector.h>
     34#include <casa/Arrays/Slice.h>
    3435#include <casa/Arrays/MaskedArray.h>
    3536#include <casa/Arrays/MaskArrMath.h>
    3637#include <casa/Arrays/VectorSTLIterator.h>
    3738#include <casa/BasicSL/String.h>
     39#include <scimath/Mathematics/MedianSlider.h>
    3840
    3941#include "MathUtils.h"
     
    147149  }
    148150}
     151
     152
     153void mathutil::runningMedian(Vector<Float>& out, Vector<Bool>& outflag,
     154                             const Vector<Float>& in, const Vector<Bool>& flag,
     155                             float width)
     156{
     157  Int hwidth = Int(width+0.5);
     158  Int fwidth = hwidth*2+1;
     159  out.resize(in.nelements());
     160  outflag.resize(flag.nelements());
     161  MedianSlider ms(hwidth);
     162  Slice sl(0, fwidth-1);
     163  Float medval = ms.add(const_cast<Vector<Float>& >(in)(sl),
     164                  const_cast<Vector<Bool>& >(flag)(sl));
     165  uInt n = in.nelements();
     166  for (uInt i=hwidth; i<(n-hwidth); ++i) {
     167    // add data value
     168    cout << ms.nval() << endl;
     169    out[i] = ms.add(in[i], flag[i]);
     170    outflag[i] = (ms.nval() == 0);   
     171  }
     172  // replicate edge values from fisrt value with full width of values
     173  for (uInt i=0;i<hwidth;++i) {
     174    out[i] = out[hwidth];
     175    outflag[i] = outflag[hwidth];   
     176    out[n-1-i] = out[n-1-hwidth];
     177    outflag[n-1-i] = outflag[n-1-hwidth];   
     178  }
     179}
Note: See TracChangeset for help on using the changeset viewer.