繁体   English   中英

在C ++ OpenCV中使用多个自定义矩阵计算RGB图像矩阵

[英]Calculate RGB Image Matrix with several custom matrices in C++ OpenCV

Helllo,我是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矩阵相乘。 有人可以帮助我吗? 谢谢

如果您问如何将矩阵相乘,OpenCV API会这样做:

Mat :: mul对两个矩阵执行逐元素乘法或除法。

编辑:

本教程说明了如何在图像上应用遮罩矩阵。 我想这就是您要寻找的..

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM