Matte modification of the matrix element: negative to 0, positive to 1

I have a matrix of negative and positive integers. I want to set the negative elements to 0 and the positive elements to 1. I do not want to set each element separately.

Is there any function / combination of functions in OpenCv that can accomplish this?

+5
source share
2 answers

Take a look at the threshhold function . In addition, this tutorial explains how to get a binary image by applying a fixed-level threshold to each element of the array.

cv::Mat source_array, binary_output;
cv::threshold(source_array, binary_output, 0, 1, cv::THRESH_BINARY); 
+4
source

, , . , . .

++

cv::threshold(m, m, 0, 1, cv::THRESH_BINARY);

cvThreshold(m, m, 0, 1, THRESH_BINARY);

Python (numpy, cv2)

m = m > 0

Python (cv)

cv.Threshold(m, m, 0, 1, cv.CV_THRESH_BINARY)
+1

All Articles