#include "UniformHelper.h" /// /// ΟίΠΤ²εΦ΅ /// /// /// /// /// cv::Mat UniformHelper::LinearInterpolation(cv::Mat imgFront, cv::Mat imgBack, float position) { if(imgFront.size()!=imgBack.size()) { ErrorMsg::SetErrorMsg(LinearInterpolationError,{ "the size of the interpolating images should be equal."}); return cv::Mat(); } if (imgFront.depth() != imgBack.depth()) { ErrorMsg::SetErrorMsg(LinearInterpolationError,{ "the depth of the interpolating images should be equal." }); return cv::Mat(); } int imgWidth = imgFront.cols; int imgHeight = imgFront.rows; cv::MatStep step = imgFront.step; int type = imgFront.type(); cv::Mat dstImg = cv::Mat(cv::Size(imgWidth, imgHeight), type); if(type!=CV_8UC1 && type!=CV_16UC1 && type!=CV_8UC3 && type!=CV_8UC4 && type!=CV_32FC1) { char strMsgBuff[64]; std::snprintf(strMsgBuff, 64, "unexpected image type ( %i )", type); ErrorMsg::SetErrorMsg(LinearInterpolationError,{ strMsgBuff }); return cv::Mat(); } if (type == CV_8UC1) { uchar pixelFront; uchar pixelBack; uchar pixelDst; for (int nh = 0; nh < imgHeight; nh++) { for (int nw = 0; nw < imgWidth; nw++) { pixelFront = imgFront.at(nh, nw); pixelBack = imgBack.at(nh, nw); pixelDst = uchar(pixelFront * (1 - position) + pixelBack * position); dstImg.at(nh, nw) = pixelDst; } } } if (type == CV_16UC1) { ushort pixelFront; ushort pixelBack; ushort pixelDst; for (int nh = 0; nh < imgHeight; nh++) { for (int nw = 0; nw < imgWidth; nw++) { pixelFront = imgFront.at(nh, nw); pixelBack = imgBack.at(nh, nw); pixelDst = ushort(pixelFront * (1 - position) + pixelBack * position); dstImg.at(nh, nw) = pixelDst; } } } if (type == CV_8UC3) { cv::Vec pixelFront; cv::Vec pixelBack; cv::Vec pixelDst; for (int nh = 0; nh < imgHeight; nh++) { for (int nw = 0; nw < imgWidth; nw++) { pixelFront = imgFront.at>(nh, nw); pixelBack = imgBack.at>(nh, nw); for (int ni = 0; ni < 3; ni++) { pixelDst[ni] = uchar(pixelFront[ni] * (1 - position) + pixelBack[ni] * position); } dstImg.at>(nh, nw) = pixelDst; } } } if (type == CV_8UC4) { cv::Vec pixelFront; cv::Vec pixelBack; cv::Vec pixelDst; for (int nh = 0; nh < imgHeight; nh++) { for (int nw = 0; nw < imgWidth; nw++) { pixelFront = imgFront.at>(nh, nw); pixelBack = imgBack.at>(nh, nw); for (int ni = 0; ni < 4; ni++) { pixelDst[ni] = uchar(pixelFront[ni] * (1 - position) + pixelBack[ni] * position); } dstImg.at>(nh, nw) = pixelDst; } } } if (type == CV_32FC1) { float pixelFront; float pixelBack; float pixelDst; for (int nh = 0; nh < imgHeight; nh++) { for (int nw = 0; nw < imgWidth; nw++) { pixelFront = imgFront.at(nh, nw); pixelBack = imgBack.at(nh, nw); pixelDst = float(pixelFront * (1 - position) + pixelBack * position); dstImg.at(nh, nw) = pixelDst; } } } return dstImg; }