MerveMeriç
MerveMeriç

Reputation: 73

Which function can I use in opencv as max() in matlab

In MATLAB:

max(image,0)

sets the negative values to zero. Is there any available function in OpenCV to do the same?

Upvotes: 4

Views: 2316

Answers (2)

Amro
Amro

Reputation: 124563

Actually the exact same syntax works:

Mat im = cv::imread("...");
Mat im_capped = cv::max(im, 0);

Or if you want give it a matrix of zeros of the same size:

Mat thresh(im.size(), im.type(), Scalar::all(0));
Mat im_capped = cv::max(im, thresh);

According to the docs:

cv::max

Upvotes: 8

Яois
Яois

Reputation: 3858

You can use something like:

Mat im = ReadSomeImage(...);
Mat masked = im.setTo(0,im<0); /// <<<

setTo(0,im<0) does what you need.

Upvotes: 4

Related Questions