【发布时间】: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