本家に合わせて画像を整数に戻すときに四捨五入するようにした

This commit is contained in:
lltcggie 2015-12-06 14:28:14 +09:00
parent 7119903830
commit 64c7af32f4

View File

@ -78,6 +78,9 @@ const int ConvertInverseMode = CV_YUV2RGB;
// 最低限必要なCUDAドライバーのバージョン // 最低限必要なCUDAドライバーのバージョン
const int MinCudaDriverVersion = 6050; 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_once_flag;
static std::once_flag waifu2x_cudnn_once_flag; static std::once_flag waifu2x_cudnn_once_flag;
static std::once_flag waifu2x_cuda_once_flag; static std::once_flag waifu2x_cuda_once_flag;
@ -256,7 +259,7 @@ Waifu2x::eWaifu2xError Waifu2x::AlphaMakeBorder(std::vector<cv::Mat> &planes, co
cv::filter2D(mask, mask_weight, -1, sum2d_kernel, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT); // マスクの3×3領域の合計値を求める cv::filter2D(mask, mask_weight, -1, sum2d_kernel, cv::Point(-1, -1), 0, cv::BORDER_DEFAULT); // マスクの3×3領域の合計値を求める
cv::Mat mask_nega_u8; 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チャンネルずつ処理 for (auto &p : planes) // 1チャンネルずつ処理
{ {
@ -1399,7 +1402,7 @@ Waifu2x::eWaifu2xError Waifu2x::waifu2x(const std::string &input_file, const std
float_image.release(); float_image.release();
cv::Mat write_iamge; 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(); process_image.release();
// 完全透明のピクセルの色を消す(処理の都合上、完全透明のピクセルにも色を付けたから) // 完全透明のピクセルの色を消す(処理の都合上、完全透明のピクセルにも色を付けたから)