diff --git a/dlib/image_transforms/interpolation.h b/dlib/image_transforms/interpolation.h index 2e19c0f6b..d7a26026c 100644 --- a/dlib/image_transforms/interpolation.h +++ b/dlib/image_transforms/interpolation.h @@ -865,10 +865,18 @@ namespace dlib float fout[4]; out.store(fout); - out_img[r][c] = static_cast(fout[0]); - out_img[r][c+1] = static_cast(fout[1]); - out_img[r][c+2] = static_cast(fout[2]); - out_img[r][c+3] = static_cast(fout[3]); + const auto convert_to_output_type = [](float value) + { + if (std::is_integral::value) + return static_cast(value + 0.5); + else + return static_cast(value); + }; + + out_img[r][c] = convert_to_output_type(fout[0]); + out_img[r][c+1] = convert_to_output_type(fout[1]); + out_img[r][c+2] = convert_to_output_type(fout[2]); + out_img[r][c+3] = convert_to_output_type(fout[3]); } x = -x_scale + c*x_scale; for (; c < out_img.nc(); ++c) diff --git a/examples/dnn_instance_segmentation_ex.cpp b/examples/dnn_instance_segmentation_ex.cpp index cf337eeb2..c390b47fd 100644 --- a/examples/dnn_instance_segmentation_ex.cpp +++ b/examples/dnn_instance_segmentation_ex.cpp @@ -136,7 +136,7 @@ int main(int argc, char** argv) try static_cast(chip_details.rect.width()) ); - dlib::resize_image(mask, resized_mask, interpolate_nearest_neighbor()); + dlib::resize_image(mask, resized_mask); for (int r = 0; r < resized_mask.nr(); ++r) for (int c = 0; c < resized_mask.nc(); ++c)