Added clamp() for THRESH_TRUNC mode
This commit is contained in:
parent
eba1be711c
commit
4612b4b827
@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
__kernel void threshold(__global const uchar * srcptr, int src_step, int src_offset,
|
__kernel void threshold(__global const uchar * srcptr, int src_step, int src_offset,
|
||||||
__global uchar * dstptr, int dst_step, int dst_offset, int rows, int cols,
|
__global uchar * dstptr, int dst_step, int dst_offset, int rows, int cols,
|
||||||
T1 thresh, T1 max_val)
|
T1 thresh, T1 max_val, T1 min_val)
|
||||||
{
|
{
|
||||||
int gx = get_global_id(0);
|
int gx = get_global_id(0);
|
||||||
int gy = get_global_id(1);
|
int gy = get_global_id(1);
|
||||||
@ -67,15 +67,15 @@ __kernel void threshold(__global const uchar * srcptr, int src_step, int src_off
|
|||||||
__global T * dst = (__global T *)(dstptr + dst_index);
|
__global T * dst = (__global T *)(dstptr + dst_index);
|
||||||
|
|
||||||
#ifdef THRESH_BINARY
|
#ifdef THRESH_BINARY
|
||||||
dst[0] = sdata > (T)(thresh) ? (T)(max_val) : (T)(0);
|
dst[0] = sdata > (thresh) ? (T)(max_val) : (T)(0);
|
||||||
#elif defined THRESH_BINARY_INV
|
#elif defined THRESH_BINARY_INV
|
||||||
dst[0] = sdata > (T)(thresh) ? (T)(0) : (T)(max_val);
|
dst[0] = sdata > (thresh) ? (T)(0) : (T)(max_val);
|
||||||
#elif defined THRESH_TRUNC
|
#elif defined THRESH_TRUNC
|
||||||
dst[0] = sdata > (T)(thresh) ? (T)(thresh) : sdata;
|
dst[0] = clamp(sdata, (T)min_val, (T)(thresh));
|
||||||
#elif defined THRESH_TOZERO
|
#elif defined THRESH_TOZERO
|
||||||
dst[0] = sdata > (T)(thresh) ? sdata : (T)(0);
|
dst[0] = sdata > (thresh) ? sdata : (T)(0);
|
||||||
#elif defined THRESH_TOZERO_INV
|
#elif defined THRESH_TOZERO_INV
|
||||||
dst[0] = sdata > (T)(thresh) ? (T)(0) : sdata;
|
dst[0] = sdata > (thresh) ? (T)(0) : sdata;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -847,9 +847,13 @@ static bool ocl_threshold( InputArray _src, OutputArray _dst, double & thresh, d
|
|||||||
if (depth <= CV_32S)
|
if (depth <= CV_32S)
|
||||||
thresh = cvFloor(thresh);
|
thresh = cvFloor(thresh);
|
||||||
|
|
||||||
|
const double min_vals[] = { 0, CHAR_MIN, 0, SHRT_MIN, INT_MIN, -FLT_MAX, -DBL_MAX, 0 };
|
||||||
|
double min_val = min_vals[depth];
|
||||||
|
|
||||||
k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::WriteOnly(dst, cn, kercn),
|
k.args(ocl::KernelArg::ReadOnlyNoSize(src), ocl::KernelArg::WriteOnly(dst, cn, kercn),
|
||||||
ocl::KernelArg::Constant(Mat(1, 1, depth, Scalar::all(thresh))),
|
ocl::KernelArg::Constant(Mat(1, 1, depth, Scalar::all(thresh))),
|
||||||
ocl::KernelArg::Constant(Mat(1, 1, depth, Scalar::all(maxval))));
|
ocl::KernelArg::Constant(Mat(1, 1, depth, Scalar::all(maxval))),
|
||||||
|
ocl::KernelArg::Constant(Mat(1, 1, depth, Scalar::all(min_val))));
|
||||||
|
|
||||||
size_t globalsize[2] = { dst.cols * cn / kercn, dst.rows };
|
size_t globalsize[2] = { dst.cols * cn / kercn, dst.rows };
|
||||||
return k.run(2, globalsize, NULL, false);
|
return k.run(2, globalsize, NULL, false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user