// // Copyright 2019 Miral Shah // // Use, modification and distribution are subject to the Boost Software License, // 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 #include namespace gil = boost::gil; int main() { int height = 4; int width= 4; gil::gray8_image_t original(width, height), threshold(width, height), expected(width, height); //filling original view's upper half part with gray pixels of value 50 //filling original view's lower half part with gray pixels of value 150 gil::fill_pixels(gil::subimage_view(gil::view(original), 0, 0, original.width(), original.height()/2), gil::gray8_pixel_t(50)); gil::fill_pixels(gil::subimage_view(gil::view(original), 0, original.height()/2, original.width(), original.height()/2), gil::gray8_pixel_t(150)); /*------------------------------Threshold Binary-----------------------------------*/ //expected view after thresholding of the original view with threshold value of 100 //filling expected view's upper half part with gray pixels of value 0 //filling expected view's lower half part with gray pixels of value 255 gil::fill_pixels(gil::subimage_view(gil::view(expected), 0, 0, original.width(), original.height() / 2), gil::gray8_pixel_t(0)); gil::fill_pixels(gil::subimage_view(gil::view(expected), 0, original.height() / 2, original.width(), original.height() / 2), gil::gray8_pixel_t(255)); gil::threshold_binary(gil::view(original), gil::view(threshold), 100); //comparing threshold view generated by the function with the expected view BOOST_TEST(gil::equal_pixels(gil::view(threshold), gil::view(expected))); /*-----------------------Threshold Binary with inverse----------------------------*/ //expected view after thresholding of the original view with threshold value of 100 //filling expected view's upper half part with gray pixels of value 200 //filling expected view's lower half part with gray pixels of value 0 gil::fill_pixels(gil::subimage_view(gil::view(expected), 0, 0, original.width(), original.height() / 2), gil::gray8_pixel_t(200)); gil::fill_pixels(gil::subimage_view(gil::view(expected), 0, original.height() / 2, original.width(), original.height() / 2), gil::gray8_pixel_t(0)); gil::threshold_binary ( gil::view(original), gil::view(threshold), 100, 200, gil::threshold_direction::inverse ); //comparing threshold view generated by the function with the expected view BOOST_TEST(gil::equal_pixels(gil::view(threshold), gil::view(expected))); return boost::report_errors(); }