I have a matrix of negative and positive integers. I want to set negative elements to 0 and positive elements to 1. I do not want to set each element individually.
Is there any function/combination of functions in OpenCv that can perform this?
Look at the function threshhold. Also, this tutorial explains how to get a binary image by applying a fixed-level threshold to each array element.
cv::Mat source_array, binary_output;
cv::threshold(source_array, binary_output, 0, 1, cv::THRESH_BINARY);
What you're doing is called thresholding. The answer depends on what language you're using. Below are a few examples.
cv::threshold(m, m, 0, 1, cv::THRESH_BINARY);
cvThreshold(m, m, 0, 1, THRESH_BINARY);
m = m > 0
cv.Threshold(m, m, 0, 1, cv.CV_THRESH_BINARY)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With