Skip to content

Commit

Permalink
アルファチャンネルの取り扱い方を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
lltcggie committed Jul 10, 2015
1 parent 0ff35a9 commit e3e621f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions common/waifu2x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cv::Mat> 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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit e3e621f

Please sign in to comment.