Skip to content

Commit

Permalink
added tests for signed integer and floating point channel types for t…
Browse files Browse the repository at this point in the history
…hreshold algorithms
  • Loading branch information
marco-langer committed Jun 27, 2022
1 parent 68b7e8b commit a44ed0d
Showing 1 changed file with 68 additions and 4 deletions.
72 changes: 68 additions & 4 deletions test/core/image_processing/threshold_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ namespace gil = boost::gil;
int height = 4;
int width = 4;

gil::gray8_image_t original_gray(width, height), threshold_gray(width, height),
expected_gray(width, height);
gil::gray8_image_t original_gray(width, height);
gil::gray8_image_t threshold_gray(width, height);
gil::gray8_image_t expected_gray(width, height);

gil::rgb8_image_t original_rgb(width, height), threshold_rgb(width, height),
expected_rgb(width, height);
gil::rgb8_image_t original_rgb(width, height);
gil::rgb8_image_t threshold_rgb(width, height);
gil::rgb8_image_t expected_rgb(width, height);

gil::rgb8s_image_t original_rgbs(width, height);
gil::rgb8s_image_t threshold_rgbs(width, height);
gil::rgb8s_image_t expected_rgbs(width, height);

gil::gray32f_image_t original_gray32f(width, height);
gil::gray32f_image_t threshold_gray32f(width, height);
gil::gray32f_image_t expected_gray32f(width, height);

void fill_original_gray()
{
Expand All @@ -44,6 +53,26 @@ void fill_original_rgb()
original_rgb.width(), original_rgb.height() / 2), gil::rgb8_pixel_t(203, 9, 60));
}

void fill_original_rgbs()
{
//filling original_rgb view's upper half part with rgbs pixels of value 50, 155, 115
//filling original_rgb view's lower half part with rgbs pixels of value 203, 9, 60
gil::fill_pixels(gil::subimage_view(gil::view(original_rgbs), 0, 0, original_rgbs.width(),
original_rgbs.height() / 2), gil::rgb8s_pixel_t(-42, 80, 83));
gil::fill_pixels(gil::subimage_view(gil::view(original_rgbs), 0, original_rgbs.height() / 2,
original_rgbs.width(), original_rgbs.height() / 2), gil::rgb8s_pixel_t(95, -50, 42));
}

void fill_original_gray32f()
{
//filling original_gray view's upper half part with gray pixels of value 0.3
//filling original_gray view's lower half part with gray pixels of value 0.7
gil::fill_pixels(gil::subimage_view(gil::view(original_gray32f), 0, 0, original_gray32f.width(),
original_gray32f.height() / 2), gil::gray32f_pixel_t(0.3f));
gil::fill_pixels(gil::subimage_view(gil::view(original_gray32f), 0, original_gray32f.height() / 2,
original_gray32f.width(), original_gray32f.height() / 2), gil::gray32f_pixel_t(0.7f));
}

void binary_gray_to_gray()
{
//expected_gray view after thresholding of the original_gray view with threshold_gray value of 100
Expand Down Expand Up @@ -122,16 +151,51 @@ void binary_inverse_rgb_to_rgb()
BOOST_TEST(gil::equal_pixels(gil::view(threshold_rgb), gil::view(expected_rgb)));
}

void binary_rgbs_to_rgbs()
{
//expected_rgbs view after thresholding of the original_rgbs view with threshold value of 70
//filling expected_rgb view's upper half part with rgb pixels of value -128, 127, 127
//filling expected_rgb view's lower half part with rgb pixels of value 127, -128, -128
gil::fill_pixels(gil::subimage_view(gil::view(expected_rgbs), 0, 0, original_rgbs.width(),
original_rgbs.height() / 2), gil::rgb8s_pixel_t(-128, 95, 95));
gil::fill_pixels(gil::subimage_view(gil::view(expected_rgbs), 0, original_rgbs.height() / 2,
original_rgbs.width(), original_rgbs.height() / 2), gil::rgb8s_pixel_t(95, -128, -128));

gil::threshold_binary(gil::view(original_rgbs), gil::view(threshold_rgbs), 70, 95);

//comparing threshold_rgb view generated by the function with the expected_rgb view
BOOST_TEST(gil::equal_pixels(gil::view(threshold_rgb), gil::view(expected_rgb)));
}

void binary_gray32f_to_gray32f()
{
//expected_gray view after thresholding of the original_gray view with threshold_gray value of 0.5f
//filling expected_gray view's upper half part with gray pixels of value 0.0
//filling expected_gray view's lower half part with gray pixels of value 1.0f
gil::fill_pixels(gil::subimage_view(gil::view(expected_gray32f), 0, 0, original_gray32f.width(),
original_gray32f.height() / 2), gil::gray32f_pixel_t(0.0f));
gil::fill_pixels(gil::subimage_view(gil::view(expected_gray32f), 0, original_gray32f.height() / 2,
original_gray32f.width(), original_gray32f.height() / 2), gil::gray32f_pixel_t(1.0f));

gil::threshold_binary(gil::view(original_gray32f), gil::view(threshold_gray32f), 0.5);

//comparing threshold_gray view generated by the function with the expected_gray view
BOOST_TEST(gil::equal_pixels(gil::view(threshold_gray32f), gil::view(expected_gray32f)));
}

int main()
{
fill_original_gray();
fill_original_rgb();
fill_original_rgbs();
fill_original_gray32f();

binary_gray_to_gray();
binary_inverse_gray_to_gray();
binary_rgb_to_rgb();
binary_rgbs_to_rgbs();
binary_inverse_rgb_to_rgb();
binary_gray32f_to_gray32f();

return boost::report_errors();
}

0 comments on commit a44ed0d

Please sign in to comment.