summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMukund Sivaraman <muks@banu.com>2014-10-09 16:16:01 +0530
committerMukund Sivaraman <muks@banu.com>2014-10-09 16:16:01 +0530
commit8feb4eb0f2e19bbace2e5e6fd348dd44b168d7aa (patch)
tree10f91f043a7441c30007a12a080b017185c1a5fa
parent345a5f3119271f228b4f4571e2af19c7c27ad16e (diff)
sobel: Bring OpenCL implementation closer to the C one
There is still the case of removing the sobel radius and access out of rect bounds.
-rw-r--r--opencl/edge-sobel.cl17
-rw-r--r--opencl/edge-sobel.cl.h17
2 files changed, 16 insertions, 18 deletions
diff --git a/opencl/edge-sobel.cl b/opencl/edge-sobel.cl
index c41a290b..f6ca9d13 100644
--- a/opencl/edge-sobel.cl
+++ b/opencl/edge-sobel.cl
@@ -32,23 +32,22 @@ kernel void kernel_edgesobel(global float4 *in,
if (horizontal)
{
hor_grad +=
- - 1.0f * pix_fl + 1.0f * pix_fr
- - 2.0f * pix_ml + 2.0f * pix_mr
- - 1.0f * pix_bl + 1.0f * pix_br;
+ (-1.0f * pix_fl + 1.0f * pix_fr) +
+ (-2.0f * pix_ml + 2.0f * pix_mr) +
+ (-1.0f * pix_bl + 1.0f * pix_br);
}
if (vertical)
{
ver_grad +=
- - 1.0f * pix_fl - 2.0f * pix_fm
- - 1.0f * pix_fr + 1.0f * pix_bl
- + 2.0f * pix_bm + 1.0f * pix_br;
+ ( 1.0f * pix_fl) + ( 2.0f * pix_fm) + ( 1.0f * pix_fr) +
+ (-1.0f * pix_bl) + (-2.0f * pix_bm) + (-1.0f * pix_br);
}
if (horizontal && vertical)
{
- gradient = sqrt(
- hor_grad * hor_grad +
- ver_grad * ver_grad) / 1.41f;
+ /* sqrt(32.0) = 5.656854249492381 */
+ gradient = sqrt(hor_grad * hor_grad +
+ ver_grad * ver_grad) / 5.656854249492381;
}
else
{
diff --git a/opencl/edge-sobel.cl.h b/opencl/edge-sobel.cl.h
index 2dc5b0c6..5f6fe7c6 100644
--- a/opencl/edge-sobel.cl.h
+++ b/opencl/edge-sobel.cl.h
@@ -33,23 +33,22 @@ static const char* edge_sobel_cl_source =
" if (horizontal) \n"
" { \n"
" hor_grad += \n"
-" - 1.0f * pix_fl + 1.0f * pix_fr \n"
-" - 2.0f * pix_ml + 2.0f * pix_mr \n"
-" - 1.0f * pix_bl + 1.0f * pix_br; \n"
+" (-1.0f * pix_fl + 1.0f * pix_fr) + \n"
+" (-2.0f * pix_ml + 2.0f * pix_mr) + \n"
+" (-1.0f * pix_bl + 1.0f * pix_br); \n"
" } \n"
" if (vertical) \n"
" { \n"
" ver_grad += \n"
-" - 1.0f * pix_fl - 2.0f * pix_fm \n"
-" - 1.0f * pix_fr + 1.0f * pix_bl \n"
-" + 2.0f * pix_bm + 1.0f * pix_br; \n"
+" ( 1.0f * pix_fl) + ( 2.0f * pix_fm) + ( 1.0f * pix_fr) + \n"
+" (-1.0f * pix_bl) + (-2.0f * pix_bm) + (-1.0f * pix_br); \n"
" } \n"
" \n"
" if (horizontal && vertical) \n"
" { \n"
-" gradient = sqrt( \n"
-" hor_grad * hor_grad + \n"
-" ver_grad * ver_grad) / 1.41f; \n"
+" /* sqrt(32.0) = 5.656854249492381 */ \n"
+" gradient = sqrt(hor_grad * hor_grad + \n"
+" ver_grad * ver_grad) / 5.656854249492381; \n"
" } \n"
" else \n"
" { \n"