From 64c7af32f4dfd80515343a7d16e80e9ec25b7d08 Mon Sep 17 00:00:00 2001 From: lltcggie Date: Sun, 6 Dec 2015 14:28:14 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=AE=B6=E3=81=AB=E5=90=88=E3=82=8F?= =?UTF-8?q?=E3=81=9B=E3=81=A6=E7=94=BB=E5=83=8F=E3=82=92=E6=95=B4=E6=95=B0?= =?UTF-8?q?=E3=81=AB=E6=88=BB=E3=81=99=E3=81=A8=E3=81=8D=E3=81=AB=E5=9B=9B?= =?UTF-8?q?=E6=8D=A8=E4=BA=94=E5=85=A5=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/waifu2x.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/waifu2x.cpp b/common/waifu2x.cpp index 0a3b750..5af90d1 100644 --- a/common/waifu2x.cpp +++ b/common/waifu2x.cpp @@ -78,6 +78,9 @@ const int ConvertInverseMode = CV_YUV2RGB; // 最低限必要なCUDAドライバーのバージョン const int MinCudaDriverVersion = 6050; +// floatな画像をuint8_tな画像に変換する際の四捨五入に使う値 +const double clip_eps8 = (1.0 / 255.0) * 0.5 - (1.0e-7 * (1.0 / 255.0) * 0.5); + static std::once_flag waifu2x_once_flag; static std::once_flag waifu2x_cudnn_once_flag; static std::once_flag waifu2x_cuda_once_flag; @@ -256,7 +259,7 @@ Waifu2x::eWaifu2xError Waifu2x::AlphaMakeBorder(std::vector &planes, co cv::filter2D(mask, mask_weight, -1, sum2d_kernel, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT); // マスクの3×3領域の合計値を求める cv::Mat mask_nega_u8; - mask_nega.convertTo(mask_nega_u8, CV_8U, 255.0); // mask_negaのCV_U8版(OpenCVのAPI上必要になる) + mask_nega.convertTo(mask_nega_u8, CV_8U, 255.0, clip_eps8); // mask_negaのCV_U8版(OpenCVのAPI上必要になる) for (auto &p : planes) // 1チャンネルずつ処理 { @@ -1399,7 +1402,7 @@ Waifu2x::eWaifu2xError Waifu2x::waifu2x(const std::string &input_file, const std float_image.release(); cv::Mat write_iamge; - process_image.convertTo(write_iamge, CV_8U, 255.0); + process_image.convertTo(write_iamge, CV_8U, 255.0, clip_eps8); process_image.release(); // 完全透明のピクセルの色を消す(処理の都合上、完全透明のピクセルにも色を付けたから)