diff --git a/common/waifu2x.cpp b/common/waifu2x.cpp index 7f1fd12..32f42c2 100644 --- a/common/waifu2x.cpp +++ b/common/waifu2x.cpp @@ -1451,6 +1451,10 @@ Waifu2x::eWaifu2xError Waifu2x::ReconstructFloatMat(const bool isReconstructNois // パディングを取り払う im = im(cv::Rect(offset, offset, image_size.width, image_size.height)); + + // 値を0〜1にクリッピング + cv::threshold(im, im, 1.0, 1.0, cv::THRESH_TRUNC); + cv::threshold(im, im, 0.0, 0.0, cv::THRESH_TOZERO); } if (cancel_func && cancel_func()) @@ -1471,6 +1475,10 @@ Waifu2x::eWaifu2xError Waifu2x::ReconstructFloatMat(const bool isReconstructNois // パディングを取り払う im = im(cv::Rect(offset, offset, image_size.width, image_size.height)); + + // 値を0〜1にクリッピング + cv::threshold(im, im, 1.0, 1.0, cv::THRESH_TRUNC); + cv::threshold(im, im, 0.0, 0.0, cv::THRESH_TOZERO); } } @@ -1560,6 +1568,10 @@ Waifu2x::eWaifu2xError Waifu2x::Reconstruct(const bool isReconstructNoise, const cv::cvtColor(reconstruct_image, reconstruct_image, CV_RGB2GRAY); // この地点ではまだRGBなことに注意 } + // 値を0〜1にクリッピング + cv::threshold(reconstruct_image, reconstruct_image, 1.0, 1.0, cv::THRESH_TRUNC); + cv::threshold(reconstruct_image, reconstruct_image, 0.0, 0.0, cv::THRESH_TOZERO); + out = reconstruct_image; return eWaifu2xError_OK;