From f21242c9d20921d7a653607d1f35250c867a75d2 Mon Sep 17 00:00:00 2001 From: Olzhas Zhumabek Date: Tue, 7 Jul 2020 02:43:24 +0600 Subject: [PATCH] Add diffusivity tests --- .../anisotropic_diffusion.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/core/image_processing/anisotropic_diffusion.cpp b/test/core/image_processing/anisotropic_diffusion.cpp index b2d5143c92..3b93bed3f3 100644 --- a/test/core/image_processing/anisotropic_diffusion.cpp +++ b/test/core/image_processing/anisotropic_diffusion.cpp @@ -5,6 +5,7 @@ // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // +#include #include #include #include @@ -18,6 +19,21 @@ namespace gil = boost::gil; +template +void diffusion_function_check(DiffusionFunction diffusion) +{ + using limits = std::numeric_limits; + using channel_type = typename gil::channel_type::type; + for (channel_type value = limits::min(); value <= limits::max(); ++value) + { + PixelType pixel; + gil::static_fill(pixel, value); + auto diffusivity_value = diffusion(pixel); + gil::static_for_each(diffusivity_value, + [](channel_type value) { BOOST_TEST(0 <= value && value <= 1.0); }); + } +} + template void heat_conservation_test(std::uint32_t seed) { @@ -83,5 +99,24 @@ int main() heat_conservation_test(seed); } + for (double kappa = 5; kappa <= 70; ++kappa) + { + diffusion_function_check( + gil::diffusion::perona_malik_diffusivity{kappa}); + diffusion_function_check(gil::diffusion::gaussian_diffusivity{kappa}); + diffusion_function_check( + gil::diffusion::wide_regions_diffusivity{kappa}); + diffusion_function_check( + gil::diffusion::more_wide_regions_diffusivity{kappa}); + + diffusion_function_check( + gil::diffusion::perona_malik_diffusivity{kappa}); + diffusion_function_check(gil::diffusion::gaussian_diffusivity{kappa}); + diffusion_function_check( + gil::diffusion::wide_regions_diffusivity{kappa}); + diffusion_function_check( + gil::diffusion::more_wide_regions_diffusivity{kappa}); + } + return boost::report_errors(); }