comparison tests/TestMedianFilter.cpp @ 392:e7010b8eb0c6

Median filter standalone method, and tests
author Chris Cannam <c.cannam@qmul.ac.uk>
date Mon, 07 Apr 2014 14:04:39 +0100
parents a1c6153d4b49
children 5ec47007b873
comparison
equal deleted inserted replaced
391:a1c6153d4b49 392:e7010b8eb0c6
90 BOOST_CHECK_EQUAL(f.get(), 7); 90 BOOST_CHECK_EQUAL(f.get(), 7);
91 f.push(3); // 5 7 3 3 91 f.push(3); // 5 7 3 3
92 BOOST_CHECK_EQUAL(f.get(), 7); 92 BOOST_CHECK_EQUAL(f.get(), 7);
93 } 93 }
94 94
95 BOOST_AUTO_TEST_CASE(oddStandalone)
96 {
97 // The standalone (static filter() method) function is intended to
98 // match e.g. MATLAB median filter, filtering a row at once
99 // assuming the values beyond its edges are zeroes. This basically
100 // just means it needs to compensate for the latency in the raw
101 // filter:
102 //
103 // Raw filter
104 // 1 3 5 7 -> 0 1 3 5 (N=3)
105 // (because at each step only the values up to that step are
106 // available)
107 //
108 // Standalone function:
109 // 1 3 5 7 -> 1 3 5 5 (N=3)
110
111 std::vector<double> in;
112 in.push_back(1);
113 in.push_back(3);
114 in.push_back(5);
115 in.push_back(7);
116
117 std::vector<double> out = MedianFilter<double>::filter(3, in);
118 BOOST_CHECK_EQUAL(out[0], 1);
119 BOOST_CHECK_EQUAL(out[1], 3);
120 BOOST_CHECK_EQUAL(out[2], 5);
121 BOOST_CHECK_EQUAL(out[3], 5);
122 }
123
124 BOOST_AUTO_TEST_CASE(evenStandalone)
125 {
126 // See above. But note that the even length does not match the
127 // MATLAB because it doesn't halve the middle, as MATLAB does
128
129 std::vector<double> in;
130 in.push_back(1);
131 in.push_back(3);
132 in.push_back(5);
133 in.push_back(7);
134
135 std::vector<double> out = MedianFilter<double>::filter(4, in);
136 BOOST_CHECK_EQUAL(out[0], 3);
137 BOOST_CHECK_EQUAL(out[1], 5);
138 BOOST_CHECK_EQUAL(out[2], 5);
139 BOOST_CHECK_EQUAL(out[3], 5);
140 }
141
142 BOOST_AUTO_TEST_CASE(standaloneEmpty)
143 {
144 std::vector<double> in;
145 std::vector<double> out1 = MedianFilter<double>::filter(3, in);
146 BOOST_CHECK_EQUAL(out1.size(), 0);
147 std::vector<double> out2 = MedianFilter<double>::filter(4, in);
148 BOOST_CHECK_EQUAL(out2.size(), 0);
149 }
150
151 BOOST_AUTO_TEST_CASE(types)
152 {
153 MedianFilter<double> dfilt(3);
154 dfilt.push(1.2);
155 BOOST_CHECK_EQUAL(dfilt.get(), 0.0);
156 dfilt.push(2.4);
157 BOOST_CHECK_EQUAL(dfilt.get(), 1.2);
158 dfilt.push(1e-6);
159 BOOST_CHECK_EQUAL(dfilt.get(), 1.2);
160 dfilt.push(1e6);
161 BOOST_CHECK_EQUAL(dfilt.get(), 2.4);
162
163 MedianFilter<int> ifilt(3);
164 ifilt.push(1);
165 BOOST_CHECK_EQUAL(ifilt.get(), 0);
166 ifilt.push(2);
167 BOOST_CHECK_EQUAL(ifilt.get(), 1);
168 ifilt.push(0);
169 BOOST_CHECK_EQUAL(ifilt.get(), 1);
170 ifilt.push(1000);
171 BOOST_CHECK_EQUAL(ifilt.get(), 2);
172 }
173
95 BOOST_AUTO_TEST_SUITE_END() 174 BOOST_AUTO_TEST_SUITE_END()
96 175
97 176