casacore
Loading...
Searching...
No Matches
scimath
Mathematics
MedianSlider.h
Go to the documentation of this file.
1
//# MedianSlider.h: Optimized sliding-median computator
2
//# Copyright (C) 2000,2001
3
//# Associated Universities, Inc. Washington DC, USA.
4
//#
5
//# This library is free software; you can redistribute it and/or modify it
6
//# under the terms of the GNU Library General Public License as published by
7
//# the Free Software Foundation; either version 2 of the License, or (at your
8
//# option) any later version.
9
//#
10
//# This library is distributed in the hope that it will be useful, but WITHOUT
11
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13
//# License for more details.
14
//#
15
//# You should have received a copy of the GNU Library General Public License
16
//# along with this library; if not, write to the Free Software Foundation,
17
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18
//#
19
//# Correspondence concerning AIPS++ should be addressed as follows:
20
//# Internet email: casa-feedback@nrao.edu.
21
//# Postal address: AIPS++ Project Office
22
//# National Radio Astronomy Observatory
23
//# 520 Edgemont Road
24
//# Charlottesville, VA 22903-2475 USA
25
26
#ifndef SCIMATH_MEDIANSLIDER_H
27
#define SCIMATH_MEDIANSLIDER_H
28
29
//#! Includes go here
30
31
#include <casacore/casa/aips.h>
32
#include <casacore/casa/Arrays/Vector.h>
33
34
namespace
casacore
{
//# NAMESPACE CASACORE - BEGIN
35
36
//# Forward Declarations
37
38
// <summary>
39
// Class to compute sliding median
40
// </summary>
41
42
// <use visibility=export>
43
44
// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
45
// </reviewed>
46
47
// <synopsis>
48
// MedianSlider is a class for efficient computing of sliding medians.
49
// </synopsis>
50
//
51
// <example>
52
// </example>
53
//
54
// <motivation>
55
// Flagging Agents make extended use of sliding medians.
56
// </motivation>
57
//
58
// <todo asof="yyyy/mm/dd">
59
// <li> think about a 2D sliding median
60
// </todo>
61
62
class
MedianSlider
63
{
64
public
:
65
66
MedianSlider
();
67
MedianSlider
(
int
halfwin
);
68
MedianSlider
(
const
MedianSlider
&other );
69
~MedianSlider
();
70
MedianSlider
&
operator =
(
const
MedianSlider
&other );
71
72
void
cleanup
();
73
74
// Adds a datum to the slider. Once the window is full, newer values will
75
// push out older values. Returns the new median value.
76
// If flag is set to true, adds a "flagged" datum, one which takes
77
// up space in the window but is skipped during median computations.
78
Float
add
(
Float
d,
Bool
flag=
False
);
79
// Adds a flagged datum
80
Float
add
() {
return
add
(0,
True
); }
81
// Adds N flagged datums
82
Float
next
(
uInt
n=1 );
83
// Adds several datums at once (with corresponding flags)
84
Float
add
(
const
Vector<Float>
&d,
const
Vector<Bool>
&flag );
85
// Adds several non-flagged datums at once
86
Float
add
(
const
Vector<Float>
&d );
87
88
// Returns the number of values currently in the window. This is less
89
// than the window width initially.
90
// Int size ();
91
92
// Returns the number of non-flagged values in window
93
Int
nval
();
94
95
// Returns the current median value
96
Float
median
();
97
98
// Returns a previous value (from n steps ago) from the sliding window
99
Float
prevVal
(
uInt
n,
Bool
&flag );
100
101
// Returns value from midpoint (center) of window, possibly with flag
102
Float
midpoint
(
Bool
&flag );
103
Float
midpoint
()
104
{
Bool
dum;
return
midpoint
(dum); }
105
106
// Returns the difference between the current median and the value
107
// at window center. Optionally, also returns flag of median center
108
Float
diff
(
Bool
&flag ) {
return
midpoint
(flag) -
median
(); }
109
Float
diff
()
110
{
Bool
dum;
return
diff
(dum); }
111
112
// returns total memory usage (in bytes) for a given halfwin size
113
static
size_t
objsize
(
int
halfwin
)
114
{
return
sizeof
(
MedianSlider
)+(
sizeof
(
Float
)+
sizeof
(
uInt
)+
sizeof
(
Bool
))*(
halfwin
*2+1); }
115
116
// For testing purposes only: verifies current value of median.
117
// Throws an exception if it fails.
118
Bool
assure
();
119
120
private
:
121
122
uInt
halfwin
,
fullwin
;
123
Float
*
buf
;
124
uInt
*
index
;
125
Bool
*
valid
;
126
uInt
ibuf
,
nind
;
127
128
};
129
130
131
inline
Int
MedianSlider::nval
()
132
{
133
return
nind
;
134
}
135
136
inline
Float
MedianSlider::median
()
137
{
138
if
( !
nind
)
139
return
0;
140
return
nind
%2 ?
buf
[
index
[
nind
/2] ]
141
: (
buf
[
index
[
nind
/2-1] ] +
buf
[
index
[
nind
/2] ] )/2;
142
// return nind%2 ? buf[ index[nind/2] ]
143
// : buf[ index[nind/2-1] ];
144
}
145
146
inline
Float
MedianSlider::midpoint
(
Bool
&flag )
147
{
148
return
prevVal
(
halfwin
+1,flag);
149
}
150
151
152
153
}
//# NAMESPACE CASACORE - END
154
155
#endif
casacore::MedianSlider
Definition
MedianSlider.h:63
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
Generated by
1.9.8