How to dot multiply and add two matrix
Hi, Is there any way to just dot multiply two matrices AND is there any way ti simply add two matrices?
Thanks, Ahmed Ehsan
You can add two matrices with addWeighted (set weights to 1.0 for both)
cv.readImage("image1.jpg", function(err, image1)
{
if (err) throw err;
cv.readImage("image2.jpg", function(err, image2)
{
if (err) throw err;
var sum = new cv.Matrix(image1.width(), image1.height());
sum.addWeighted(image1, 1.0, image2, 1.0);
sum.save("sum.jpg");
});
});
But what about dot multiplication? On 9 Dec 2014 19:22, "Salman Ul Haq" [email protected] wrote:
You can add two matrices with addWeighted (set weights to 1.0 for both)
cv.readImage("image1.jpg", function(err, image1) { if (err) throw err; cv.readImage("image2.jpg", function(err, image2) { if (err) throw err; var sum = new cv.Matrix(image1.width(), image1.height()); sum.addWeighted(image1, 1.0, image2, 1.0); sum.save("sum.jpg"); }); });
— Reply to this email directly or view it on GitHub https://github.com/peterbraden/node-opencv/issues/198#issuecomment-66289100 .
It's fairly simply, though not available yet. I'll add image arithmetic ops, check back in a few days :)
@salmanulhaq Is it ready now? I am working on an image segmentation program, so I want to multiply a matrix by a scalar. I have used a for loop but it ends up in a segmentation fault if I do several multiplications.
for (i = 0; i <= width; i++) {
for (j = 0; j <= height; j++) {
var prod = mat1.get(i, j) * scalar1;
mat1.set(i, j, prod);
var prod = mat2.get(i, j) * scaler2;
mat2.set(i, j, prod);
}
}
And the console result is:
[1] 7190 segmentation fault node segmentation.js
Is there other options to solve this problem?
Thanks in advance!
@marcos90gil did you figure it out?
It could probably be added in easily: http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html?highlight=dot#mat-dot
Please i need the same!! Anyone could solve this?