Regarding your specific request:
set 50all pixels< 50
using matrix expressions and setTois simple:
Mat m = ...
m.setTo(50, m < 50);
OpenCV , cv:: threshold .
, , , 255 > th :
double th = 100.0;
Mat m = ...
Mat thresh;
threshold(m, thresh, th, 255, THRESH_BINARY);
double th = 100.0;
Mat m = ...
Mat thresh = m > th;
, 255 < th, :
double th = 100.0;
Mat m = ...
Mat thresh;
threshold(m, thresh, th, 255, THRESH_BINARY_INV); // <-- using INVerted threshold
:
double th = 100.0;
Mat m = ...
Mat thresh = m <= th;
, threshold , CV_8U.