【问题标题】:Calculate RGB Image Matrix with several custom matrices in C++ OpenCV在 C++ OpenCV 中使用几个自定义矩阵计算 RGB 图像矩阵
【发布时间】:2015-02-20 15:00:00
【问题描述】:

你好, 我是 C++ OpenCV 编程的新手。我有一张彩色图像,我希望该图像与几个矩阵相乘(掩蔽)。这是代码大纲:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
char* hai;
int main()
{

hai = "c:/Dalton/grayscale.jpg";
Mat im = imread(hai);
Mat Result;
const int nChannels = im.channels(); //get channel sum from the image (it should be 3 channel,because RGB)
Result.create(im.size(), im.type()); //create new mat (for the result) which have same size and type with first mat
double rgb2lms[3][3] = { 17.8824, 43.5161, 4.11935,
    3.45565, 27.1554, 3.86714,
    0.0299566, 0.184309, 1.46709 };
double lms2lmsp[3][3] = { 0, 2.02344, -2.52581,
                        0, 1, 0,
                        0, 0, 1 };
if (im.empty())
{
    cout << "Cannot load image!" << endl;
    return -1;
}
//access pixel
for (int i = 0; i < im.rows; i++)
{
    for (int j = 0; j < im.cols; j++)
    {
        for (int k = 0; k < nChannels; k++)
        {

            //main program
            //calculating matrix    
            //i want calculate im(RGB matrix) multiply with rgb2lms
            //after that, the result is multiplied again with lms2lmsp matrix
        }
    }
}   
imshow("Image", im);
imshow("Image Result", Result);
waitKey(0);

}

如何将此 RGB 矩阵与另一个矩阵相乘?我应该访问每个像素吗?我想将原始图像与 rgb2lms 矩阵相乘,然后将结果再次与 lms2lmsp 矩阵相乘。任何人都可以帮助我吗? 谢谢

【问题讨论】:

  • 你不知道怎么算吗?您是在问是否有一个预先存在的库可以做到这一点?您是否遇到性能问题并正在寻找最有效的方法来做到这一点?有点不清楚您希望我们为您提供什么帮助。
  • @JeffBridgman 显然,我想将 RGB 矩阵与几个矩阵相乘。示例:A=RGBrgb2lms 然后 C=Alms2lmsp。我不知道在 C++ 中使用 3 个通道矩阵来做到这一点。
  • 卷积,而不是乘法。

标签: c++ opencv masking imagefilter


【解决方案1】:

如果您询问如何将矩阵相乘,OpenCV API 会:

Mat::mul Performs an element-wise multiplication or division of two matrices.

编辑:

本教程介绍了如何在图像上应用蒙版矩阵。我想这就是你要找的东西..

http://docs.opencv.org/doc/tutorials/core/mat-mask-operations/mat-mask-operations.html

【讨论】:

  • 但我仍然对如何将 RGB 3 通道图像矩阵与 3x3 矩阵相乘感到困惑。我应该使用普通矩阵乘法(A * B)吗?或者我必须使用元素乘法??
  • @MahendraSuntServanda 希望本教程对您有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
  • 2014-05-11
  • 2020-06-16
相关资源
最近更新 更多