Reputation: 73
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
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:
Upvotes: 8
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