TEST(Regions, Docs_4) { // input data uchar input[64] = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0 }; // gold output float gold[64] = { 0.0000, 0.0000, 0.0000, 0.0000, 1.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 2.0000, 0.0000, 1.0000, 0.0000, 0.0000, 3.0000, 0.0000, 0.0000, 0.0000, 4.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 5.0000, 0.0000, 0.0000, 6.0000, 0.0000, 0.0000, 7.0000, 0.0000, 0.0000, 8.0000, 0.0000, 0.0000, 9.0000, 0.0000, 0.0000, 0.0000, 0.0000, 8.0000, 8.0000, 0.0000, 0.0000, 10.0000, 11.000, 11.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 11.0000, 0.0000, 12.0000, 12.0000, 12.0000, 12.0000, 0.0000 }; //![ex_image_regions_4conn] array in(8, 8, input); //af_print(in.T()); //in //0 0 0 0 1 0 1 0 //0 0 0 0 0 0 1 1 //0 1 0 1 0 0 0 0 //0 0 1 0 1 1 0 1 //1 1 0 0 0 1 0 1 //0 0 0 1 0 0 0 1 //0 0 0 0 1 0 0 1 //0 1 0 0 0 1 0 0 // Compute the label matrix using 4-way connectivity array out = regions(in.as(b8), AF_CONNECTIVITY_4); //af_print(out.T()); //out //0 0 0 0 7 0 11 0 //0 0 0 0 0 0 11 11 //0 2 0 5 0 0 0 0 //0 0 4 0 8 8 0 12 //1 1 0 0 0 8 0 12 //0 0 0 6 0 0 0 12 //0 0 0 0 9 0 0 12 //0 3 0 0 0 10 0 0 //![ex_image_regions_4conn] float output[64]; out.host((void*)output); for (int i=0; i<64; ++i) { ASSERT_EQ(gold[i], output[i])<<" mismatch at i="<<i<<endl; } }
///////////////////////////////////// CPP //////////////////////////////// // TEST(Regions, CPP) { if (noDoubleTests<float>()) return; vector<dim4> numDims; vector<vector<float> > in; vector<vector<float> > tests; readTests<float, float, unsigned>(string(TEST_DIR"/regions/regions_8x8_4.test"),numDims,in,tests); dim4 idims = numDims[0]; array input(idims, (float*)&(in[0].front())); array output = regions(input.as(b8)); // Get result float* outData = new float[idims.elements()]; output.host((void*)outData); // Compare result for (size_t testIter = 0; testIter < tests.size(); ++testIter) { vector<float> currGoldBar = tests[testIter]; size_t nElems = currGoldBar.size(); for (size_t elIter = 0; elIter < nElems; ++elIter) { ASSERT_EQ(currGoldBar[elIter], outData[elIter]) << "at: " << elIter << endl; } } // Delete delete[] outData; }
///////////////////////////////// Documentation Examples /////////////////// TEST(Regions, Docs_8) { // input data uchar input[64] = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0 }; // gold output float gold[64] = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 3, 0, 0, 4, 0, 0, 1, 0, 0, 3, 0, 0, 0, 0, 1, 1, 0, 0, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 6, 6, 6, 0 }; //![ex_image_regions] array in(8, 8, input); //af_print(in); // in = // 0 0 0 0 1 0 1 0 // 0 0 0 0 0 0 1 1 // 0 1 0 1 0 0 0 0 // 0 0 1 0 1 1 0 1 // 1 1 0 0 0 1 0 1 // 0 0 0 1 0 0 0 1 // 0 0 0 0 1 0 0 1 // 0 1 0 0 0 1 0 0 // Compute the label matrix using 8-way connectivity array out = regions(in.as(b8), AF_CONNECTIVITY_8); //af_print(out); // 0 0 0 0 4 0 5 0 // 0 0 0 0 0 0 5 5 // 0 1 0 1 0 0 0 0 // 0 0 1 0 1 1 0 6 // 1 1 0 0 0 1 0 6 // 0 0 0 3 0 0 0 6 // 0 0 0 0 3 0 0 6 // 0 2 0 0 0 3 0 0 //![ex_image_regions] float output[64]; out.host((void*)output); for (int i=0; i<64; ++i) { ASSERT_EQ(gold[i], output[i])<<" mismatch at i="<<i<<endl; } }
TEST(Regions, NoComponentImage) { const int dim = 101; const int sz = dim*dim; vector<char> input(sz, 0); vector<float> gold(sz, 0.0f); array in = array(dim, dim, input.data()); array out = regions(in, AF_CONNECTIVITY_4); vector<float> output(sz); out.host((void*)output.data()); for (int i=0; i<sz; ++i) ASSERT_FLOAT_EQ(gold[i], output[i])<<" mismatch at i="<<i<<endl; }