Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Matrix Multiplication Type Issue

I'm trying to do color conversion from RGB into LMS and multiply the matrix using reshape.

void test(const Mat &ori, Mat &output, Mat &pic, int rows, int cols)
{
    Mat lms(3, 3, CV_32FC3);
    Mat rgb(3, 3, CV_32FC3);

    lms = (Mat_<float>(3, 3) << 1.4671, 0.1843, 0.0030,
                                3.8671, 27.1554, 3.4557,
                                4.1194, 45.5161 , 17.884 );
    /* switch the order of the matrix according to the BGR order of color on OpenCV */

    Mat transpose = (3, 3, CV_32FC3, lms).t();  // this will do transpose from matrix lms

    pic         = ori.reshape(1, rows*cols);
    rgb         = pic*transpose;
    output      = rgb.reshape(3, cols);
}

About reshape, because my original Mat object is from an image with 3 channel (RGB), and I need to multiply them with matrix of 1 channel, it seems like I have an issue with the matrix type.

This is how I define my original mat

Mat ori = imread("colorcubes.png", CV_LOAD_IMAGE_COLOR);
int rows = ori.rows;
int cols = ori.cols;
Mat pic(rows, cols, CV_32FC3);
Mat output(rows, cols, CV_32FC3);

Error is : OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) , so it's the type issue.

I tried to change all type into either 32FC3 of 32FC1, but doesn't seem to work. Any suggestion ?