从OpenCV中的cv :: Mat对象中减去固定值 [英] Subtracting a fixed value from cv::Mat objects in OpenCV

查看:1359
本文介绍了从OpenCV中的cv :: Mat对象中减去固定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对OpenCV相当陌生,并且有点了解它.我知道cv::Mat类中的矩阵运算符已被重载以执行A.mult(B),A + B,A-B,A/B等.

I am fairly new to OpenCV and sort of understanding it bit by bit. I know that the matrix operators in cv::Mat class has been overloaded to do A.mult(B), A+B, A-B, A/B, etc.

我有两个向量,分别是图像的行和列的投影.我有两个图像(S和T),所以每个图像都有两个投影向量(rowProejctionS,columnProjectionS,rowProjectionT,columnProjectionT).我也有图像的均值(meanS,meanT).我需要进行产品总和"的相关计算,在MATLAB中如下所示

I have two vectors which are projections of rows and columns of an image. I have two images(S and T), so each of them will have two projection vectors (rowProejctionS, columnProjectionS, rowProjectionT, columnProjectionT). I also have the means of the images (meanS, meanT). I need to do a "SUM OF PRODUCT" related calculation, which in MATLAB is as follows

numeratorLambdaRo = sum((rowProjectionT - meanT).*(rowProjectionS - meanS));
denominatorLambdaRo = sqrt(sum((rowProjectionT - meanT).^2)*sum((rowProjectionS - meanS).^2);

LambaRo = numeratorLambdaRo/denominatorLambdaRo;

我不确定在cv::Mat对象的上下文中矩阵运算符的功能.

I am not entirely sure about the capability of matrix operators in the context of cv::Mat objects.

推荐答案

将meanT,meanS声明为double或cv :: Scalar,您可以从矩阵中减去它.您也许可以拆分您的操作:

declare meanT, meanS as double or cv::Scalar and you can just substract it from your matrix. You can maybe split your operations :

rowProjectionT -= meanT;
rowProjectionS -= meanS;
numeratoLambdaRo = cv::sum(rowProjectionT*rowProjectionS.t()); // transpose 1 of the vector so that multiplication is equivalent to dot product.

cv::Mat rowProjTSquare = rowProjectionT*rowProjectionT.t();
cv::Mat rowProjSSquare = rowProjectionS*rowProjectionS.t();
denominatorLambdaRo = sqrt(cv::sum(rowProjTSquare*rowProjSSquare));

这篇关于从OpenCV中的cv :: Mat对象中减去固定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆