0

Helllo, I'm newbie in C++ OpenCV programming. I have one colour image, and i want that image multiplied with several matrices (masking). This is the outline of code:

#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);

}

How i can multiply this RGB mat matrix with another matrix? Should i access every pixel? I want to multiplied original image with rgb2lms matrix and then the result multiplied again with lms2lmsp matrix. Anyone can help me? Thanks

  • Do you not know how to do the math? Are you asking if there's a pre-existing library that does this? Are you having performance problems and are looking for the most efficient way to do this? It's a bit unclear what you're wanting us to help you with. – Jeff B Dec 22 '14 at 13:47
  • @JeffBridgman clearly, i want to multiply RGB matrix with several matrices. Example: A=RGB*rgb2lms and then C=A*lms2lmsp. I don't have any idea to do that in c++ with 3 channels matrix. – Mahendra Sunt Servanda Dec 23 '14 at 00:54
  • convolution, not multiplication. – berak Dec 23 '14 at 10:55

1 Answers1

1

If you are asking how to multiply matrices, OpenCV API does it:

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

EDIT:

This tutorial explains how to apply a mask matrix on an image. I think that's what you are looking for..

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

Daniel
  • 406
  • 1
  • 4
  • 14