Skip to content

Commit 6917d84

Browse files
committed
add test for min filter
1 parent 3e4b3d2 commit 6917d84

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

test/APRTest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,6 +3257,19 @@ bool test_median_filter(TestData &test_data) {
32573257
}
32583258

32593259

3260+
template<int size_y, int size_x, int size_z>
3261+
bool test_min_filter(TestData &test_data) {
3262+
3263+
ParticleData<float> output;
3264+
APRFilter::min_filter<size_y, size_x, size_z>(test_data.apr, test_data.particles_intensities, output);
3265+
3266+
ParticleData<float> output_gt;
3267+
FilterTestHelpers::compute_min_filter_gt(test_data.apr, test_data.particles_intensities, output_gt, size_y, size_x, size_z);
3268+
3269+
return compareParticles(output_gt, output) == 0;
3270+
}
3271+
3272+
32603273
bool test_convolve_pencil(TestData &test_data, const bool boundary = false, const std::vector<int>& stencil_size = {3, 3, 3}) {
32613274

32623275
auto it = test_data.apr.iterator();
@@ -4337,6 +4350,12 @@ TEST_F(CreateDiffDimsSphereTest, APR_FILTER) {
43374350
bool success1D = test_median_filter<7, 1, 1>(test_data);
43384351
ASSERT_TRUE(success3D && success2D && success1D);
43394352

4353+
// Min filter
4354+
success3D = test_min_filter<7, 5, 3>(test_data);
4355+
success2D = test_min_filter<5, 3, 1>(test_data);
4356+
success1D = test_min_filter<7, 1, 1>(test_data);
4357+
ASSERT_TRUE(success3D && success2D && success1D);
4358+
43404359
}
43414360

43424361
TEST_F(CreateAPRTest, READ_PARTICLE_TYPE){

test/FilterTestHelpers.hpp

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
#include <vector>
1313

1414

15+
template<typename T>
16+
T compute_median(std::vector<T>& input) {
17+
std::sort(input.begin(), input.end());
18+
const auto n = input.size();
19+
return (n % 2 == 0) ? (input[n/2 - 1] + input[n/2]) / 2 : input[n/2];
20+
}
21+
22+
template<typename T>
23+
T compute_min(std::vector<T>& input){
24+
return *std::min_element(input.begin(), input.end());
25+
26+
}
27+
1528
namespace FilterTestHelpers {
1629

1730
template<typename InputType, typename StencilType, typename OutputType>
@@ -23,7 +36,8 @@ namespace FilterTestHelpers {
2336

2437
template<typename InputType, typename OutputType>
2538
void compute_generic_filter_gt(APR& apr,
26-
const ParticleData<InputType>& input_particles,
39+
ParticleData<InputType>& input_particles,
40+
ParticleData<OutputType>& tree_particles,
2741
ParticleData<OutputType>& output_particles,
2842
int size_y,
2943
int size_x,
@@ -32,23 +46,31 @@ namespace FilterTestHelpers {
3246
OutputType filter(std::vector<OutputType>&));
3347

3448

35-
template<typename T>
36-
T median(std::vector<T>& input) {
37-
std::sort(input.begin(), input.end());
38-
const auto n = input.size();
39-
return (n % 2 == 0) ? (input[n/2 - 1] + input[n/2]) / 2 : input[n/2];
40-
}
41-
42-
4349
template<typename InputType, typename OutputType>
4450
void compute_median_filter_gt(APR& apr,
45-
const ParticleData<InputType>& input_particles,
51+
ParticleData<InputType>& input_particles,
4652
ParticleData<OutputType>& output_particles,
4753
int size_y,
4854
int size_x,
4955
int size_z) {
5056

51-
compute_generic_filter_gt(apr, input_particles, output_particles, size_y, size_x, size_z, true, FilterTestHelpers::median);
57+
ParticleData<OutputType> tree_particles;
58+
APRTreeNumerics::fill_tree_mean(apr, input_particles, tree_particles);
59+
compute_generic_filter_gt(apr, input_particles, tree_particles, output_particles, size_y, size_x, size_z, true, compute_median);
60+
}
61+
62+
63+
template<typename InputType, typename OutputType>
64+
void compute_min_filter_gt(APR& apr,
65+
ParticleData<InputType>& input_particles,
66+
ParticleData<OutputType>& output_particles,
67+
int size_y,
68+
int size_x,
69+
int size_z) {
70+
71+
ParticleData<OutputType> tree_particles;
72+
APRTreeNumerics::fill_tree_min(apr, input_particles, tree_particles);
73+
compute_generic_filter_gt(apr, input_particles, tree_particles, output_particles, size_y, size_x, size_z, true, compute_min);
5274
}
5375

5476
}
@@ -152,7 +174,8 @@ void FilterTestHelpers::compute_convolution_gt(APR &apr,
152174

153175

154176
template<typename InputType, typename OutputType>
155-
void FilterTestHelpers::compute_generic_filter_gt(APR &apr, const ParticleData<InputType> &input_particles,
177+
void FilterTestHelpers::compute_generic_filter_gt(APR &apr, ParticleData<InputType> &input_particles,
178+
ParticleData<OutputType> &tree_particles,
156179
ParticleData<OutputType> &output_particles, const int size_y,
157180
const int size_x, const int size_z, const bool reflect_boundary,
158181
OutputType filter(std::vector<OutputType>&)) {
@@ -166,7 +189,7 @@ void FilterTestHelpers::compute_generic_filter_gt(APR &apr, const ParticleData<I
166189
ReconPatch patch_spec;
167190
patch_spec.level_delta = level - apr.level_max();
168191
PixelData<OutputType> by_level_recon;
169-
APRReconstruction::reconstruct_constant(apr, by_level_recon, input_particles, patch_spec);
192+
APRReconstruction::reconstruct_constant(apr, by_level_recon, input_particles, tree_particles, patch_spec);
170193

171194
// iteration over particles - at each location compute filter output using the reconstructed image
172195
for (int z = 0; z < apr_it.z_num(level); ++z) {

0 commit comments

Comments
 (0)