What function can be used in opencv as max () in matlab

In MATLAB:

max(image,0)

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

+4
source share
2 answers

Actually the same syntax works:

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

Or if you want to 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 docs :

cv :: max

+8
source

You can use something like:

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

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

+4
source

Source: https://habr.com/ru/post/1547385/


All Articles