Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I don't figure out what you supposed to do, but what you need to know is,

since assignment of matrix multiplication only supports certain types such as CV_32FC1, CV_32FC2, CV_64FC1, and CV_64FC2 as assertion failure shows, "img" and "d" must follow one of these types and also "img" and "d" have to be the same type.

I don't know properties of "33.jpg" yet, imread would set img as channel of 3 if "33.jpg" is color image. So, "img" divides into three matrices for each channel with 32F or 64F type. Then do multiplication.

Or, simply use convertTo() and reshape() to make correct types. For example,

img.convertTo(img, CV_64F);
d.convertTo(d, CV_64F);
img.reshape(1);
d.reshape(1);
e = img*d;

I don't figure out what you supposed to do, but what you need to know is,

since assignment of matrix multiplication only supports certain types such as CV_32FC1, CV_32FC2, CV_64FC1, and CV_64FC2 as assertion failure shows, "img" and "d" must follow one of these types and also "img" and "d" have to be the same type.

I don't know properties of "33.jpg" yet, imread would set img as channel of 3 if "33.jpg" is color image. So, "img" divides into three matrices for each channel with 32F or 64F type. Then do multiplication.

Or, simply use convertTo() and reshape() to make correct types. For example,

img.convertTo(img, CV_64F);
d.convertTo(d, CV_64F);
img.reshape(1);
d.reshape(1);
e = img*d;

updated: I missed several things. Here's full code.

Mat img = imread ("D:\\33.jpg");
Mat a,b,c,d,e;
a = getGaussianKernel(img.cols,300,CV_64F);
b = getGaussianKernel(img.rows,300,CV_64F);
double minVal;     
double maxVal;

c = img;    // assign img to c because d must be the same dimension to img
cv::minMaxLoc(c, &minVal, &maxVal);
d = c/maxVal;

img.convertTo(img, CV_64F);       // convert Depth for multiplication
d.convertTo(d, CV_64F);

Mat imgPlanes[3], dPlanes[3], res[3];
split(img, imgPlanes);                 // split 3 channels to 1 channel matrices
split(d, dPlanes);

res[0] = imgPlanes[0]*dPlanes[0];   // I guess this is what you supposed to multiply
res[1] = imgPlanes[1]*dPlanes[1];
res[2] = imgPlanes[2]*dPlanes[2];

merge(res, 3, img);            // combine single channels to one multi-channel

return 0;

Also, I would like to mention that reshape() makes channels to columns. For instance, if 300 (row) x 300 (col) x 3 (ch) reshapes to 1 channel matrix which will be changed to 300 (row) x 900 (col) x 1 (ch).

I don't figure out what you supposed to do, but what you need to know is,

since assignment of matrix multiplication only supports certain types such as CV_32FC1, CV_32FC2, CV_64FC1, and CV_64FC2 as assertion failure shows, "img" and "d" must follow one of these types and also "img" and "d" have to be the same type.

I don't know properties of "33.jpg" yet, imread would set img as channel of 3 if "33.jpg" is color image. So, "img" divides into three matrices for each channel with 32F or 64F type. Then do multiplication.

Or, simply use convertTo() and reshape() to make correct types. For example,

img.convertTo(img, CV_64F);
d.convertTo(d, CV_64F);
img.reshape(1);
d.reshape(1);
e = img*d;

updated:


Update:

I missed several things. Here's full code.

Mat img = imread ("D:\\33.jpg");
Mat a,b,c,d,e;
a = getGaussianKernel(img.cols,300,CV_64F);
b = getGaussianKernel(img.rows,300,CV_64F);
double minVal;     
double maxVal;

c = img;    // assign img to c because d must be the same dimension to img
cv::minMaxLoc(c, &minVal, &maxVal);
d = c/maxVal;

img.convertTo(img, CV_64F);       // convert Depth for multiplication
d.convertTo(d, CV_64F);

Mat imgPlanes[3], dPlanes[3], res[3];
split(img, imgPlanes);                 // split 3 channels to 1 channel matrices
split(d, dPlanes);

res[0] = imgPlanes[0]*dPlanes[0];   // I guess this is what you supposed to multiply
res[1] = imgPlanes[1]*dPlanes[1];
res[2] = imgPlanes[2]*dPlanes[2];

merge(res, 3, img);            // combine single channels to one multi-channel

return 0;

Also, I would like to mention that reshape() makes channels to columns. For instance, if 300 (row) x 300 (col) x 3 (ch) reshapes to 1 channel matrix which will be changed to 300 (row) x 900 (col) x 1 (ch).

I don't figure out what you supposed to do, but what you need to know is,

since assignment of matrix multiplication only supports certain types such as CV_32FC1, CV_32FC2, CV_64FC1, and CV_64FC2 as assertion failure shows, "img" and "d" must follow one of these types and also "img" and "d" have to be the same type.

I don't know properties of "33.jpg" yet, imread would set img as channel of 3 if "33.jpg" is color image. So, "img" divides into three matrices for each channel with 32F or 64F type. Then do multiplication.

Or, simply use convertTo() and reshape() to make correct types. For example,

img.convertTo(img, CV_64F);
d.convertTo(d, CV_64F);
img.reshape(1);
d.reshape(1);
e = img*d;

Update:

I missed several things. Here's full code.

Mat img = imread ("D:\\33.jpg");
Mat a,b,c,d,e;
a = getGaussianKernel(img.cols,300,CV_64F);
b = getGaussianKernel(img.rows,300,CV_64F);
double minVal;     
double maxVal;

c = img;    // assign img to c because d must be the same dimension to img
cv::minMaxLoc(c, &minVal, &maxVal);
d = c/maxVal;

img.convertTo(img, CV_64F);       // convert Depth for multiplication
d.convertTo(d, CV_64F);

Mat imgPlanes[3], dPlanes[3], res[3];
split(img, imgPlanes);                 // split 3 channels to 1 channel matrices
split(d, dPlanes);

res[0] = imgPlanes[0]*dPlanes[0];   // I guess this is what you supposed to multiply
res[1] = imgPlanes[1]*dPlanes[1];
res[2] = imgPlanes[2]*dPlanes[2];

merge(res, 3, img);            // combine single channels to one multi-channel

return 0;

Also, I would like to mention that reshape() makes channels to columns. For instance, if 300 (row) x 300 (col) x 3 (ch) reshapes to 1 channel matrix which matrix, it will be changed to 300 (row) x 900 (col) x 1 (ch).