diff --git a/common/waifu2x.cpp b/common/waifu2x.cpp index 93afec2..9e11ed1 100644 --- a/common/waifu2x.cpp +++ b/common/waifu2x.cpp @@ -381,14 +381,19 @@ Waifu2x::eWaifu2xError Waifu2x::LoadMatBySTBI(cv::Mat &float_image, const std::s // 画像から輝度の画像を取り出す Waifu2x::eWaifu2xError Waifu2x::CreateBrightnessImage(const cv::Mat &float_image, cv::Mat &im) { - cv::Mat converted_color; - cv::cvtColor(float_image, converted_color, ConvertMode); + if (float_image.channels() > 1) + { + cv::Mat converted_color; + cv::cvtColor(float_image, converted_color, ConvertMode); - std::vector planes; - cv::split(converted_color, planes); + std::vector planes; + cv::split(converted_color, planes); - im = planes[0]; - planes.clear(); + im = planes[0]; + planes.clear(); + } + else + im = float_image; return eWaifu2xError_OK; }