how to modify values of Mat according to some condition in opencv?

Naah. to do that, just one line:

cv::Mat img = imread('your image path');
img.setTo(0,img>50);

as simple as that.


What you want is to truncate the image with cv::threshold.

The following should do what you require:

cv::threshold(dst, dst, 50, 0, CV_THRESH_TOZERO_INV);

this is the function definition

double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)

http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=threshold#threshold