Loading...
Searching...
No Matches
MedianSlider.h
Go to the documentation of this file.
//# MedianSlider.h: Optimized sliding-median computator
//# Copyright (C) 2000,2001
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef SCIMATH_MEDIANSLIDER_H
#define SCIMATH_MEDIANSLIDER_H
//#! Includes go here
#include <casacore/casa/aips.h>
#include <casacore/casa/Arrays/Vector.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
//# Forward Declarations
// <summary>
// Class to compute sliding median
// </summary>
// <use visibility=export>
// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
// </reviewed>
// <synopsis>
// MedianSlider is a class for efficient computing of sliding medians.
// </synopsis>
//
// <example>
// </example>
//
// <motivation>
// Flagging Agents make extended use of sliding medians.
// </motivation>
//
// <todo asof="yyyy/mm/dd">
// <li> think about a 2D sliding median
// </todo>
class MedianSlider
{
public:
MedianSlider ();
MedianSlider ( int halfwin );
MedianSlider ( const MedianSlider &other );
~MedianSlider ();
MedianSlider & operator = ( const MedianSlider &other );
void cleanup ();
// Adds a datum to the slider. Once the window is full, newer values will
// push out older values. Returns the new median value.
// If flag is set to true, adds a "flagged" datum, one which takes
// up space in the window but is skipped during median computations.
Float add ( Float d,Bool flag=False );
// Adds a flagged datum
Float add () { return add(0,True); }
// Adds N flagged datums
Float next ( uInt n=1 );
// Adds several datums at once (with corresponding flags)
Float add ( const Vector<Float> &d,const Vector<Bool> &flag );
// Adds several non-flagged datums at once
Float add ( const Vector<Float> &d );
// Returns the number of values currently in the window. This is less
// than the window width initially.
// Int size ();
// Returns the number of non-flagged values in window
Int nval ();
// Returns the current median value
Float median ();
// Returns a previous value (from n steps ago) from the sliding window
Float prevVal ( uInt n,Bool &flag );
// Returns value from midpoint (center) of window, possibly with flag
Float midpoint ( Bool &flag );
Float midpoint ()
{ Bool dum; return midpoint(dum); }
// Returns the difference between the current median and the value
// at window center. Optionally, also returns flag of median center
Float diff ( Bool &flag ) { return midpoint(flag) - median(); }
Float diff ()
{ Bool dum; return diff(dum); }
// returns total memory usage (in bytes) for a given halfwin size
static size_t objsize ( int halfwin )
{ return sizeof(MedianSlider)+(sizeof(Float)+sizeof(uInt)+sizeof(Bool))*(halfwin*2+1); }
// For testing purposes only: verifies current value of median.
// Throws an exception if it fails.
Bool assure ();
private:
uInt halfwin,fullwin;
Float *buf;
uInt *index;
Bool *valid;
uInt ibuf,nind;
};
inline Int MedianSlider::nval ()
{
return nind;
}
inline Float MedianSlider::median ()
{
if( !nind )
return 0;
return nind%2 ? buf[ index[nind/2] ]
: ( buf[ index[nind/2-1] ] + buf[ index[nind/2] ] )/2;
// return nind%2 ? buf[ index[nind/2] ]
// : buf[ index[nind/2-1] ];
}
inline Float MedianSlider::midpoint ( Bool &flag )
{
return prevVal(halfwin+1,flag);
}
} //# NAMESPACE CASACORE - END
#endif
casacore::MedianSlider::add
Float add()
Adds a flagged datum.
Definition MedianSlider.h:80
casacore::MedianSlider::nind
uInt nind
Definition MedianSlider.h:126
casacore::MedianSlider::next
Float next(uInt n=1)
Adds N flagged datums.
casacore::MedianSlider::halfwin
uInt halfwin
Definition MedianSlider.h:122
casacore::MedianSlider::buf
Float * buf
Definition MedianSlider.h:123
casacore::MedianSlider::~MedianSlider
~MedianSlider()
casacore::MedianSlider::cleanup
void cleanup()
casacore::MedianSlider::add
Float add(Float d, Bool flag=False)
Adds a datum to the slider.
casacore::MedianSlider::median
Float median()
Returns the current median value.
Definition MedianSlider.h:136
casacore::MedianSlider::MedianSlider
MedianSlider(const MedianSlider &other)
casacore::MedianSlider::assure
Bool assure()
For testing purposes only: verifies current value of median.
casacore::MedianSlider::add
Float add(const Vector< Float > &d, const Vector< Bool > &flag)
Adds several datums at once (with corresponding flags).
casacore::MedianSlider::fullwin
uInt fullwin
Definition MedianSlider.h:122
casacore::MedianSlider::nval
Int nval()
Returns the number of values currently in the window.
Definition MedianSlider.h:131
casacore::MedianSlider::prevVal
Float prevVal(uInt n, Bool &flag)
Returns a previous value (from n steps ago) from the sliding window.
casacore::MedianSlider::MedianSlider
MedianSlider()
casacore::MedianSlider::ibuf
uInt ibuf
Definition MedianSlider.h:126
casacore::MedianSlider::diff
Float diff(Bool &flag)
Returns the difference between the current median and the value at window center.
Definition MedianSlider.h:108
casacore::MedianSlider::objsize
static size_t objsize(int halfwin)
returns total memory usage (in bytes) for a given halfwin size
Definition MedianSlider.h:113
casacore::MedianSlider::add
Float add(const Vector< Float > &d)
Adds several non-flagged datums at once.
casacore::MedianSlider::index
uInt * index
Definition MedianSlider.h:124
casacore::MedianSlider::MedianSlider
MedianSlider(int halfwin)
casacore::MedianSlider::valid
Bool * valid
Definition MedianSlider.h:125
casacore::MedianSlider::diff
Float diff()
Definition MedianSlider.h:109
casacore::MedianSlider::operator=
MedianSlider & operator=(const MedianSlider &other)
casacore::MedianSlider::midpoint
Float midpoint()
Definition MedianSlider.h:103
casacore::Vector
Definition Vector.h:82
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::False
const Bool False
Definition aipstype.h:42
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::Float
float Float
Definition aipstype.h:52
casacore::Int
int Int
Definition aipstype.h:48
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
casacore::True
const Bool True
Definition aipstype.h:41