From e3e621f2e4d12e4a663f9be2983f21c592ed98ed Mon Sep 17 00:00:00 2001 From: lltcggie Date: Fri, 10 Jul 2015 15:44:03 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A2=E3=83=AB=E3=83=95=E3=82=A1=E3=83=81?= =?UTF-8?q?=E3=83=A3=E3=83=B3=E3=83=8D=E3=83=AB=E3=81=AE=E5=8F=96=E3=82=8A?= =?UTF-8?q?=E6=89=B1=E3=81=84=E6=96=B9=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/waifu2x.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/common/waifu2x.cpp b/common/waifu2x.cpp index a56d624..4120f69 100644 --- a/common/waifu2x.cpp +++ b/common/waifu2x.cpp @@ -205,17 +205,16 @@ Waifu2x::eWaifu2xError Waifu2x::LoadMat(cv::Mat &float_image, const std::string cv::cvtColor(convert, convert, cv::COLOR_GRAY2BGR); else if (convert.channels() == 4) { - // アルファチャンネル付きだったら背景を1(白)として画像合成する + // アルファチャンネル付きだったらα乗算済みにする std::vector planes; cv::split(convert, planes); - cv::Mat w2 = planes[3]; - cv::Mat w1 = 1.0 - planes[3]; + cv::Mat w = planes[3]; - planes[0] = planes[0].mul(w2) + w1; - planes[1] = planes[1].mul(w2) + w1; - planes[2] = planes[2].mul(w2) + w1; + planes[0] = planes[0].mul(w); + planes[1] = planes[1].mul(w); + planes[2] = planes[2].mul(w); cv::merge(planes, convert); } @@ -1158,9 +1157,9 @@ Waifu2x::eWaifu2xError Waifu2x::waifu2x(const std::string &input_file, const std cv::Mat w2 = planes[3]; - planes[0] = (planes[0] - 1.0).mul(1.0 / w2) + 1.0; - planes[1] = (planes[1] - 1.0).mul(1.0 / w2) + 1.0; - planes[2] = (planes[2] - 1.0).mul(1.0 / w2) + 1.0; + planes[0] = (planes[0]).mul(1.0 / w2); + planes[1] = (planes[1]).mul(1.0 / w2); + planes[2] = (planes[2]).mul(1.0 / w2); cv::merge(planes, process_image); }