diff --git a/modules/img/alg/tests/CMakeLists.txt b/modules/img/alg/tests/CMakeLists.txt index cdbd8b459c114e0765bb53280f144043be34a8cc..cea46dcb979d4f6a73e515b81bf26858876f2468 100644 --- a/modules/img/alg/tests/CMakeLists.txt +++ b/modules/img/alg/tests/CMakeLists.txt @@ -14,6 +14,7 @@ test_power_spectrum.cc test_shift.cc test_stat.cc test_transform.cc +test_normalizer.cc tests.cc ) diff --git a/modules/img/alg/tests/test_normalizer.cc b/modules/img/alg/tests/test_normalizer.cc new file mode 100644 index 0000000000000000000000000000000000000000..e072626dbc562e70703ae226606c4c9e0d1f6c9d --- /dev/null +++ b/modules/img/alg/tests/test_normalizer.cc @@ -0,0 +1,76 @@ +//------------------------------------------------------------------------------ +// This file is part of the OpenStructure project <www.openstructure.org> +// +// Copyright (C) 2008-2011 by the OpenStructure authors +// Copyright (C) 2003-2010 by the IPLT authors +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License as published by the Free +// Software Foundation; either version 3.0 of the License, or (at your option) +// any later version. +// This library is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +// details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with this library; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +//------------------------------------------------------------------------------ + +/* + Author: Andreas Schenk +*/ + +#include <iostream> + +#include "tests.hh" + +#include <ost/img/image.hh> +#include <ost/img/alg/normalizer_factory.hh> +#include <ost/img/alg/stat.hh> + + + +namespace { + +using namespace ost::img; +using namespace ost::img::alg; + +void test() +{ + boost::test_tools::close_at_tolerance<Real> close_test(::boost::test_tools::percent_tolerance(0.001)); + ost::img::ImageHandle testimage=ost::img::CreateImage(ost::img::Extent(ost::img::Point(0,0),ost::img::Point(3,3))); + int counter=0; + for (ost::img::ExtentIterator i(testimage.GetExtent()); !i.AtEnd(); ++i, ++counter) { + testimage.SetReal(i, counter); + } + ost::img::alg::Normalizer norm=ost::img::alg::CreateLinearRangeNormalizer(testimage,0.0,65535.0); + ost::img::ImageHandle scaled_image=testimage.Apply(norm); + scaled_image+=0.01; //if all values are > 0.0 we can use close_at_tolerance + bool failed=false; + ost::img::ExtentIterator eit(testimage.GetExtent()); + for(;!eit.AtEnd();++eit) { + if( ! close_test(scaled_image.GetReal(eit),testimage.GetReal(eit)/15.0*65535.0+0.01)){ + failed=true; + break; + } + } + if(failed){ + BOOST_ERROR("Normalizer failed at point " + << ost::img::Point(eit)<< ". Should be " + << testimage.GetReal(eit)/15.0*65535.0+0.01 << ", but " + << scaled_image.GetReal(eit) << " found."); + } +} + +} // ns + +test_suite* CreateNormalizerTest() +{ + test_suite* ts=BOOST_TEST_SUITE("img alg Normalizer Test"); + + ts->add(BOOST_TEST_CASE(&test)); + + return ts; +} diff --git a/modules/img/alg/tests/tests.cc b/modules/img/alg/tests/tests.cc index 0a4ae6cecd7020190c0e6415ae0938ba0061a481..d3db88c2f29c5c3bbb19517e4d0800f9488f4ea3 100644 --- a/modules/img/alg/tests/tests.cc +++ b/modules/img/alg/tests/tests.cc @@ -41,6 +41,7 @@ extern test_suite* CreateClearTest(); extern test_suite* CreateFFTTest(); extern test_suite* CreateNegateTest(); extern test_suite* CreateConjugateTest(); +extern test_suite* CreateNormalizerTest(); bool init_ost_img_alg_unit_tests() { try { @@ -54,6 +55,7 @@ bool init_ost_img_alg_unit_tests() { framework::master_test_suite().add(CreateClearTest()); framework::master_test_suite().add(CreateNegateTest()); framework::master_test_suite().add(CreateFFTTest()); + framework::master_test_suite().add(CreateNormalizerTest()); } catch(std::exception& e) { return false; }