基本上我想乘以矢量的圖像的每個通道值。例如Vec4f(1,2,3,4)1 *圖像2的紅色通道*綠色通道等等這裏是我的代碼(不是一個完整的代碼,有一些錯誤),但我的老闆說,必須有更好更簡單的方法與opencv,但我無法找到。預先感謝。用給定的矢量乘以每個通道像素
void scaleImage(TextureData& dst, TextureData const& src, cv::Vec4f
const& scale)
{
auto size = src.info.size;
dst=src;
cv::Mat bgr[4];
cv::split(src.levels[0].images[0], bgr);
for (int y = 0; y < size.height; ++y)
{
for (int x = 0; x < size.width; ++x)
{
src.levels[0].images[0].channels();
if (src.levels[0].images[0].channels() == 4)
{
auto& imgRGB = dst.levels[0].images[0].at<cv::Vec4f>(x, y);
imgRGB[3] = static_cast<uint8_t>(scale.w()*bgr[3].at[x, y]);
imgRGB[2] = static_cast<uint8_t>(scale.x()*bgr[2].at[x, y]);
imgRGB[1] = static_cast<uint8_t>(scale.y()*bgr[1].at[x, y]);
imgRGB[0] = static_cast<uint8_t>(scale.z()*bgr[0].at[x, y]);
}
if (src.levels[0].images[0].channels() == 3)
{
auto& imgRGB = dst.levels[0].images[0].at<cv::Vec3f>(x, y);
imgRGB[2] = static_cast<uint8_t>(scale.x()*bgr[2].at[x, y]);
imgRGB[1] = static_cast<uint8_t>(scale.y()*bgr[1].at[x, y]);
imgRGB[0] = static_cast<uint8_t>(scale.z()*bgr[0].at[x, y]);
}
if (src.levels[0].images[0].channels() == 2)
{
auto& imgRGB = dst.levels[0].images[0].at<cv::Vec2f>(x, y);
imgRGB[1] = static_cast<uint8_t>(scale.x()*bgr[2].at[x, y]);
imgRGB[0] = static_cast<uint8_t>(scale.y()*bgr[1].at[x, y]);
}
if (src.levels[0].images[0].channels() == 2)
{
auto& imgRGB = dst.levels[0].images[0].at<float>(x, y);
imgRGB[0] = static_cast<uint8_t>(scale.x()*bgr[2].at[x, y]);
}
}
}
非常感謝安東尼奧,但墊*標給出錯誤 –