Search code examples
javaandroidopencvmat

OpenCV replacing specific pixel values with another value in java


i read about how to replace specific pixel values in Opebcv c++ is like the code below

Mat src;
// ... src is CV_32S

double oldVal = 0.0;
double newVal = Double.MIN_VALUE;

src.setTo(newVal, src == oldVal); 

but after i read more i found out that logical operator on Mat don't work on java. so how can i do something similar to the code above because i need Mat that don't have zero to be divisor.

edit 1: cv::threshold wouldn't work becasue my mat is CV_32S, so the number could be negative numbers


Solution

  • You may need to look into OpenCV compare API, to check for equality of each element of matrix with a scalar using CMP_EQ flag and which would yield you a binary mask that can be later used as second param in src.setTo()