divide的使用

Performs per-element division of two arrays or a scalar by an array.

C++:  void  divide (InputArray  src1, InputArray  src2, OutputArray  dst, double  scale=1, int  dtype=-1 )
C++:  void  divide (double  scale, InputArray  src2, OutputArray  dst, int  dtype=-1 )
Python:   cv2. divide (src1, src2 [, dst [, scale [, dtype ] ] ] ) → dst
Python:   cv2. divide (scale, src2 [, dst [, dtype ] ] ) → dst
C:  void  cvDiv (const CvArr*  src1, const CvArr*  src2, CvArr*  dst, double  scale=1 )
Python:   cv. Div (src1, src2, dst, scale ) → None
Parameters:
  • src1 – First source array.
  • src2 – Second source array of the same size and type as src1 .
  • scale – Scalar factor.
  • dst – Destination array of the same size and type as src2 .
  • dtype – Optional depth of the destination array. If it is -1dst will have depth src2.depth(). In case of an array-by-array division, you can only pass -1 when src1.depth()==src2.depth().

The functions divide divide one array by another:

\texttt{dst(I) = saturate(src1(I)*scale/src2(I))}

or a scalar by an array when there is no src1 :

\texttt{dst(I) = saturate(scale/src2(I))}

When src2(I) is zero, dst(I) will also be zero. Different channels of multi-channel arrays are processed independently.


同样,也能实现一个矩阵除以一个数,eg:

Mat concatenateMat(vector<Mat> &vec){
int height = vec[0].rows;
int width = vec[0].cols;
Mat res = Mat::zeros(height * width, vec.size(), CV_64FC1);

for(int i=0; i<vec.size(); i++){

Mat img(height, width, CV_64FC1);
vec[i].convertTo(img, CV_64FC1);
// reshape(int cn, int rows=0), cn is num of channels.
Mat ptmat = img.reshape(0, height * width);
Rect roi = cv::Rect(i, 0, ptmat.cols, ptmat.rows);
Mat subView = res(roi);  //!  res(roi) creates a matrix header for a part of the bigger matrix
ptmat.copyTo(subView);
}

divide(res, 255.0, res);   //归一化到[0,1]范围
return res;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值