Ask Your Question
0

Need to multiply two Mat elementwise

asked 2018-04-14 10:59:34 -0500

Kafan gravatar image

updated 2018-04-14 10:59:53 -0500

I have two Mat of same size. A of type CV_8UC1 and B of type CV_64F

I am trying to multiply A with B elementwise such that output should be of CV_8UC1 obtained by doing either a round of or simple casting of values to CV_8UC1.

I am not sure if the result will be of desired type from A.mul(B)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-04-14 11:11:22 -0500

LBerger gravatar image

using mul resut type will be CV_8UC1. If you want a good result you have to use multiply :

Mat A = (Mat_<uchar>(2, 4) << 5, 6, 0, 4, 0, 1, 9, 9);
Mat B = (Mat_<uchar>(2, 4) << 60,9,1,0,4,0,6,5);
cout << "mat.mul =" << A.mul(B) << endl;
Mat C;
multiply(A, B, C, 1, CV_32S);
cout << "C =" << C << endl;

Results are

mat.mul =[255,  54,   0,   0;
   0,   0,  54,  45]
C =[300, 54, 0, 0;
 0, 0, 54, 45]
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-04-14 10:59:34 -0500

Seen: 26 times

Last updated: Apr 14