mirror of
https://github.com/lltcggie/waifu2x-caffe.git
synced 2025-06-26 13:42:48 +00:00
アルファチャンネル付き画像で透明領域内の引き伸ばした部分がうまく消えていなかったのを修正
This commit is contained in:
parent
aaa191dd9b
commit
1e1cf6a6a0
@ -1342,21 +1342,13 @@ Waifu2x::eWaifu2xError Waifu2x::AfterReconstructFloatMatProcess(const bool isRec
|
|||||||
Reconstruct(false, true, cancel_func, planes[3], alpha);
|
Reconstruct(false, true, cancel_func, planes[3], alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
// アルファチャンネルがあったらアルファを付加して、完全透明のピクセルの色を消す(処理の都合上、完全透明のピクセルにも色を付けたから)
|
// アルファチャンネルがあったらアルファを付加する
|
||||||
if (!alpha.empty())
|
if (!alpha.empty())
|
||||||
{
|
{
|
||||||
std::vector<cv::Mat> planes;
|
std::vector<cv::Mat> planes;
|
||||||
cv::split(process_image, planes);
|
cv::split(process_image, planes);
|
||||||
process_image.release();
|
process_image.release();
|
||||||
|
|
||||||
cv::Mat mask;
|
|
||||||
cv::threshold(alpha, mask, 0.0, 1.0, cv::THRESH_BINARY); // アルファチャンネルを二値化してマスクとして扱う
|
|
||||||
|
|
||||||
// アルファチャンネルが0のところの色を消す
|
|
||||||
planes[0] = planes[0].mul(mask);
|
|
||||||
planes[1] = planes[1].mul(mask);
|
|
||||||
planes[2] = planes[2].mul(mask);
|
|
||||||
|
|
||||||
planes.push_back(alpha);
|
planes.push_back(alpha);
|
||||||
|
|
||||||
cv::merge(planes, process_image);
|
cv::merge(planes, process_image);
|
||||||
@ -1410,6 +1402,24 @@ Waifu2x::eWaifu2xError Waifu2x::waifu2x(const std::string &input_file, const std
|
|||||||
process_image.convertTo(write_iamge, CV_8U, 255.0);
|
process_image.convertTo(write_iamge, CV_8U, 255.0);
|
||||||
process_image.release();
|
process_image.release();
|
||||||
|
|
||||||
|
// 完全透明のピクセルの色を消す(処理の都合上、完全透明のピクセルにも色を付けたから)
|
||||||
|
// モデルによっては画像全域の完全透明の場所にごく小さい値のアルファが広がることがある。それを消すためにuint8_tに変換してからこの処理を行うことにした
|
||||||
|
if (write_iamge.channels() > 3)
|
||||||
|
{
|
||||||
|
std::vector<cv::Mat> planes;
|
||||||
|
cv::split(write_iamge, planes);
|
||||||
|
|
||||||
|
cv::Mat mask;
|
||||||
|
cv::threshold(planes[3], mask, 0.0, 1.0, cv::THRESH_BINARY); // アルファチャンネルを二値化してマスクとして扱う
|
||||||
|
|
||||||
|
// アルファチャンネルが0のところの色を消す
|
||||||
|
planes[0] = planes[0].mul(mask);
|
||||||
|
planes[1] = planes[1].mul(mask);
|
||||||
|
planes[2] = planes[2].mul(mask);
|
||||||
|
|
||||||
|
cv::merge(planes, write_iamge);
|
||||||
|
}
|
||||||
|
|
||||||
ret = WriteMat(write_iamge, output_file);
|
ret = WriteMat(write_iamge, output_file);
|
||||||
if (ret != eWaifu2xError_OK)
|
if (ret != eWaifu2xError_OK)
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user