|
| 1 | +#include <gtest/gtest.h> |
| 2 | +#include <arrayfire.h> |
| 3 | +#include <af/dim4.hpp> |
| 4 | +#include <af/traits.hpp> |
| 5 | +#include <string> |
| 6 | +#include <vector> |
| 7 | +#include <testHelpers.hpp> |
| 8 | +#include <cmath> |
| 9 | + |
| 10 | +using std::string; |
| 11 | +using std::vector; |
| 12 | +using af::dim4; |
| 13 | + |
| 14 | +template<typename T> |
| 15 | +class Bilateral : public ::testing::Test |
| 16 | +{ |
| 17 | + public: |
| 18 | + virtual void SetUp() {} |
| 19 | +}; |
| 20 | + |
| 21 | +// create a list of types to be tested |
| 22 | +// FIXME: since af_load_image returns only f32 type arrays |
| 23 | +// only float, double, int data types test are enabledpassing |
| 24 | +// Note: compareArraysRMSD is handling upcasting while working |
| 25 | +// with two different type of types |
| 26 | +// |
| 27 | +//typedef ::testing::Types<float, double, int, uint, char, uchar> TestTypes; |
| 28 | +typedef ::testing::Types<float, double, int> TestTypes; |
| 29 | + |
| 30 | +// register the type list |
| 31 | +TYPED_TEST_CASE(Bilateral, TestTypes); |
| 32 | + |
| 33 | +TYPED_TEST(Bilateral, InvalidArgs) |
| 34 | +{ |
| 35 | + vector<TypeParam> in(100,1); |
| 36 | + |
| 37 | + af_array inArray = 0; |
| 38 | + af_array outArray = 0; |
| 39 | + |
| 40 | + // check for gray scale bilateral |
| 41 | + af::dim4 dims(5,5,2,2); |
| 42 | + ASSERT_EQ(AF_SUCCESS, af_create_array(&inArray, &in.front(), |
| 43 | + dims.ndims(), dims.get(), (af_dtype) af::dtype_traits<TypeParam>::af_type)); |
| 44 | + ASSERT_EQ(AF_ERR_ARG, af_bilateral(&outArray, inArray, 0.12f, 0.34f, false)); |
| 45 | + ASSERT_EQ(AF_SUCCESS, af_destroy_array(inArray)); |
| 46 | + |
| 47 | + // check for color image bilateral |
| 48 | + dims = af::dim4(100,1,1,1); |
| 49 | + ASSERT_EQ(AF_SUCCESS, af_create_array(&inArray, &in.front(), |
| 50 | + dims.ndims(), dims.get(), (af_dtype) af::dtype_traits<TypeParam>::af_type)); |
| 51 | + ASSERT_EQ(AF_ERR_ARG, af_bilateral(&outArray, inArray, 0.12f, 0.34f, true)); |
| 52 | + ASSERT_EQ(AF_SUCCESS, af_destroy_array(inArray)); |
| 53 | +} |
| 54 | + |
| 55 | +template<typename T, bool isColor> |
| 56 | +void bilateralTest(string pTestFile) |
| 57 | +{ |
| 58 | + vector<dim4> inDims; |
| 59 | + vector<string> inFiles; |
| 60 | + vector<dim_type> outSizes; |
| 61 | + vector<string> outFiles; |
| 62 | + |
| 63 | + readImageTests(pTestFile, inDims, inFiles, outSizes, outFiles); |
| 64 | + |
| 65 | + size_t testCount = inDims.size(); |
| 66 | + |
| 67 | + for (size_t testId=0; testId<testCount; ++testId) { |
| 68 | + |
| 69 | + af_array inArray = 0; |
| 70 | + af_array outArray = 0; |
| 71 | + af_array goldArray= 0; |
| 72 | + dim_type nElems = 0; |
| 73 | + |
| 74 | + inFiles[testId].insert(0,string(TEST_DIR"/bilateral/")); |
| 75 | + outFiles[testId].insert(0,string(TEST_DIR"/bilateral/")); |
| 76 | + |
| 77 | + ASSERT_EQ(AF_SUCCESS, af_load_image(&inArray, inFiles[testId].c_str(), isColor)); |
| 78 | + ASSERT_EQ(AF_SUCCESS, af_load_image(&goldArray, outFiles[testId].c_str(), isColor)); |
| 79 | + ASSERT_EQ(AF_SUCCESS, af_get_elements(&nElems, goldArray)); |
| 80 | + |
| 81 | + ASSERT_EQ(AF_SUCCESS, af_bilateral(&outArray, inArray, 2.25f, 25.56f, isColor)); |
| 82 | + |
| 83 | + T * outData = new T[nElems]; |
| 84 | + ASSERT_EQ(AF_SUCCESS, af_get_data_ptr((void*)outData, outArray)); |
| 85 | + |
| 86 | + T * goldData= new T[nElems]; |
| 87 | + ASSERT_EQ(AF_SUCCESS, af_get_data_ptr((void*)goldData, goldArray)); |
| 88 | + |
| 89 | + ASSERT_EQ(true, compareArraysRMSD(nElems, goldData, outData, 0.02f)); |
| 90 | + |
| 91 | + ASSERT_EQ(AF_SUCCESS, af_destroy_array(inArray)); |
| 92 | + ASSERT_EQ(AF_SUCCESS, af_destroy_array(outArray)); |
| 93 | + ASSERT_EQ(AF_SUCCESS, af_destroy_array(goldArray)); |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +TYPED_TEST(Bilateral, Grayscale) |
| 98 | +{ |
| 99 | + bilateralTest<TypeParam, false>(string(TEST_DIR"/bilateral/gray.test")); |
| 100 | +} |
| 101 | + |
| 102 | +TYPED_TEST(Bilateral, Color) |
| 103 | +{ |
| 104 | + bilateralTest<TypeParam, true>(string(TEST_DIR"/bilateral/color.test")); |
| 105 | +} |
0 commit comments