Fix pixels being rounded to int values in some cases (#2228)

This commit is contained in:
Davis King 2020-11-08 10:22:40 -05:00
parent 83921b390e
commit 3f163bd433
3 changed files with 23 additions and 4 deletions

View File

@ -3049,7 +3049,7 @@ namespace dlib
const M& m const M& m
) )
{ {
pixel = static_cast<unsigned char>(m(0)); pixel = static_cast<P>(m(0));
} }
}; };

View File

@ -1754,6 +1754,23 @@ namespace
<< " error: " << max(abs(chip-255)) ); << " error: " << max(abs(chip-255)) );
} }
// So the same as above, but for an image with float values that are all the same to make
// sure noting funny happens for float images.
{
print_spinner();
const long nr = 53;
const long nc = 67;
const long size = 8*9;
const double angle = 30*pi/180;
matrix<float> img(501,501), chip;
img = 1234.5;
chip_details details(centered_rect(center(get_rect(img)),nr,nc), size, angle);
extract_image_chip(img, details, chip);
DLIB_TEST_MSG(max(abs(chip-1234.5))==0,"nr: " << nr << " nc: "<< nc << " size: " << size << " angle: " << angle
<< " error: " << max(abs(chip-255)) );
}
{ {
// Make sure that the interpolation in extract_image_chip() keeps stuff in the // Make sure that the interpolation in extract_image_chip() keeps stuff in the

View File

@ -449,7 +449,7 @@ namespace
p_gray = 8; p_gray = 8;
p_schar = 8; p_schar = 8;
p_int = 8; p_int = 8;
p_float = 8; p_float = 8.5;
p_hsi.h = 9; p_hsi.h = 9;
p_hsi.s = 10; p_hsi.s = 10;
@ -501,7 +501,7 @@ namespace
DLIB_TEST(p_gray == 8); DLIB_TEST(p_gray == 8);
DLIB_TEST(p_schar == 8); DLIB_TEST(p_schar == 8);
DLIB_TEST(p_int == 8); DLIB_TEST(p_int == 8);
DLIB_TEST(p_float == 8); DLIB_TEST(p_float == 8.5);
DLIB_TEST(p_hsi.h == 9); DLIB_TEST(p_hsi.h == 9);
DLIB_TEST(p_hsi.s == 10); DLIB_TEST(p_hsi.s == 10);
@ -550,7 +550,7 @@ namespace
DLIB_TEST(p_gray == 8); DLIB_TEST(p_gray == 8);
DLIB_TEST(p_int == 8); DLIB_TEST(p_int == 8);
DLIB_TEST(p_float == 8); DLIB_TEST(p_float == 8.5);
DLIB_TEST(p_schar == 8); DLIB_TEST(p_schar == 8);
DLIB_TEST(p_hsi.h == 9); DLIB_TEST(p_hsi.h == 9);
@ -566,6 +566,7 @@ namespace
assign_pixel(p_rgb,0); assign_pixel(p_rgb,0);
assign_pixel(p_lab,0); assign_pixel(p_lab,0);
vector_to_pixel(p_float, m_float);
vector_to_pixel(p_gray, m_gray); vector_to_pixel(p_gray, m_gray);
vector_to_pixel(p_hsi, m_hsi); vector_to_pixel(p_hsi, m_hsi);
vector_to_pixel(p_rgb, m_rgb); vector_to_pixel(p_rgb, m_rgb);
@ -581,6 +582,7 @@ namespace
DLIB_TEST(p_rgba.alpha == 7); DLIB_TEST(p_rgba.alpha == 7);
DLIB_TEST(p_gray == 8); DLIB_TEST(p_gray == 8);
DLIB_TEST(p_float == 8.5);
DLIB_TEST(p_hsi.h == 9); DLIB_TEST(p_hsi.h == 9);
DLIB_TEST(p_hsi.s == 10); DLIB_TEST(p_hsi.s == 10);