gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:30:55 26 4
gpt4 key购买 nike

你好,我是 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 mat 矩阵与另一个矩阵相乘?我应该访问每个像素吗?我想将原始图像与 rgb2lms 矩阵相乘,然后将结果再次与 lms2lmsp 矩阵相乘。任何人都可以帮助我吗?谢谢

最佳答案

如果您询问如何乘以矩阵,OpenCV API 可以做到:

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

编辑:

本教程介绍了如何在图像上应用 mask 矩阵。我想这就是您要找的..

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

关于c++ - 在 C++ OpenCV 中使用多个自定义矩阵计算 RGB 图像矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27603920/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com