Is there an equivalent of 'smoothstep' function in opencv (java)?It is commonly used in opengl/glsl and is available as a standard built-in function in many other standard image-processing libraries.May be we can implement it using combination of threshold/clamping functions. What is the best or most efficient way to use smoothstep function with opencv mat objects?
Here is a sample code:-
float smoothstep(float edge0, float edge1, float x) {
// Scale, bias and saturate x to 0..1 range
x = clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
// Evaluate polynomial
return x * x * (3 - 2 * x);
}
float clamp(float x, float lowerlimit, float upperlimit) {
if (x < lowerlimit)
x = lowerlimit;
if (x > upperlimit)
x = upperlimit;
return x;
}
Imgproc.GaussianBlur(mskmat, mskmat,new org.opencv.core.Size(3,3), 0);
Utils.matToBitmap(mskmat,bitmap);
save(bitmap,"mask");
//Smoothing
mskmat.convertTo(mskmat,CV_32F);
for (int i=0; i<mskmat.rows(); i++)
{
for (int j=0; j<mskmat.cols(); j++)
{
double[] data = mskmat.get(i, j); //Stores element in an array
for (int k = 0; k < 1; k++) //Runs for the available number of channels
{
data[k] = 255.0f * smoothstep(0.3f,0.5f, (float)data[k]/255.0f); //Pixel modification done here
}
Log.d("Value", Arrays.toString(data));
mskmat.put(i, j, data); //Puts element back into matrix
}
}
mskmat.convertTo(mskmat,CV_8U);
Utils.matToBitmap(mskmat,bitmap);
save(bitmap,"smoothmask");
However this method seems to be too slow and output is not as good as the standard smoothstep function.