Aly
Aly

Reputation: 16255

OpenCV:Whats the easiest way to divide a Mat by a Scalar

I think it's pretty much in the title, obviously I can iterate through and divide. But I assume there is an inbuilt way. I saw cvConvertScale but this does not work with type cv::Mat.

Upvotes: 17

Views: 26551

Answers (1)

cedrou
cedrou

Reputation: 2790

I know the scaling operation for a multiplication by a scalar:

cv::Mat M;
float alpha;
cv::Mat Result = M * alpha;

Let's try this:

cv::Mat Result = M / alpha;

Or:

float beta = 1.0f / alpha;
cv::Mat Result = M * beta;   

Upvotes: 26

Related Questions