Compute Library  18.03
canny.cl File Reference
#include "helpers.h"

Go to the source code of this file.

Macros

#define EDGE   255
 
#define hysteresis_local_stack_L1   8
 
#define hysteresis_local_stack_L2   16
 
#define check_pixel(early_test, x_pos, y_pos, x_cur, y_cur)
 Check whether pixel is valid. More...
 

Functions

__kernel void combine_gradients_L1 (__global uchar *src1_ptr, uint src1_stride_x, uint src1_step_x, uint src1_stride_y, uint src1_step_y, uint src1_offset_first_element_in_bytes, __global uchar *src2_ptr, uint src2_stride_x, uint src2_step_x, uint src2_stride_y, uint src2_step_y, uint src2_offset_first_element_in_bytes, __global uchar *grad_ptr, uint grad_stride_x, uint grad_step_x, uint grad_stride_y, uint grad_step_y, uint grad_offset_first_element_in_bytes, __global uchar *angle_ptr, uint angle_stride_x, uint angle_step_x, uint angle_stride_y, uint angle_step_y, uint angle_offset_first_element_in_bytes)
 Calculate the magnitude and phase from horizontal and vertical result of sobel result. More...
 
__kernel void combine_gradients_L2 (__global uchar *src1_ptr, uint src1_stride_x, uint src1_step_x, uint src1_stride_y, uint src1_step_y, uint src1_offset_first_element_in_bytes, __global uchar *src2_ptr, uint src2_stride_x, uint src2_step_x, uint src2_stride_y, uint src2_step_y, uint src2_offset_first_element_in_bytes, __global uchar *grad_ptr, uint grad_stride_x, uint grad_step_x, uint grad_stride_y, uint grad_step_y, uint grad_offset_first_element_in_bytes, __global uchar *angle_ptr, uint angle_stride_x, uint angle_step_x, uint angle_stride_y, uint angle_step_y, uint angle_offset_first_element_in_bytes)
 Calculate the gradient and angle from horizontal and vertical result of sobel result. More...
 
__kernel void suppress_non_maximum (__global uchar *grad_ptr, uint grad_stride_x, uint grad_step_x, uint grad_stride_y, uint grad_step_y, uint grad_offset_first_element_in_bytes, __global uchar *angle_ptr, uint angle_stride_x, uint angle_step_x, uint angle_stride_y, uint angle_step_y, uint angle_offset_first_element_in_bytes, __global uchar *non_max_ptr, uint non_max_stride_x, uint non_max_step_x, uint non_max_stride_y, uint non_max_step_y, uint non_max_offset_first_element_in_bytes, uint lower_thr)
 Perform non maximum suppression. More...
 
kernel void hysteresis (__global uchar *src_ptr, uint src_stride_x, uint src_step_x, uint src_stride_y, uint src_step_y, uint src_offset_first_element_in_bytes, __global uchar *out_ptr, uint out_stride_x, uint out_step_x, uint out_stride_y, uint out_step_y, uint out_offset_first_element_in_bytes, __global uchar *visited_ptr, uint visited_stride_x, uint visited_step_x, uint visited_stride_y, uint visited_step_y, uint visited_offset_first_element_in_bytes, __global uchar *recorded_ptr, uint recorded_stride_x, uint recorded_step_x, uint recorded_stride_y, uint recorded_step_y, uint recorded_offset_first_element_in_bytes, __global uchar *l1_stack_ptr, uint l1_stack_stride_x, uint l1_stack_step_x, uint l1_stack_stride_y, uint l1_stack_step_y, uint l1_stack_offset_first_element_in_bytes, __global uchar *l1_stack_counter_ptr, uint l1_stack_counter_stride_x, uint l1_stack_counter_step_x, uint l1_stack_counter_stride_y, uint l1_stack_counter_step_y, uint l1_stack_counter_offset_first_element_in_bytes, uint low_thr, uint up_thr, int width, int height)
 Perform hysteresis. More...
 

Variables

__constant short4 neighbours_coords []
 Array that holds the relative coordinates offset for the neighbouring pixels. More...
 

Macro Definition Documentation

#define check_pixel (   early_test,
  x_pos,
  y_pos,
  x_cur,
  y_cur 
)
Value:
{ \
if(!early_test) \
{ \
/* Number of elements in the local stack 1, points to next available entry */ \
c = *((__global char *)offset(&l1_stack_counter, x_cur, y_cur)); \
\
if(c > (hysteresis_local_stack_L1 - 1)) /* Stack level 1 is full */ \
goto pop_stack; \
\
/* The pixel that has already been recorded is ignored */ \
if(!atomic_or((__global uint *)offset(&recorded, x_pos, y_pos), 1)) \
{ \
l1_ptr[c] = (short2)(x_pos, y_pos); \
*((__global char *)offset(&l1_stack_counter, x_cur, y_cur)) += 1; \
} \
} \
}
#define hysteresis_local_stack_L1
Definition: canny.cl:228
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:301

Check whether pixel is valid.

Skip the pixel if the early_test fails. Otherwise, it tries to add the pixel coordinate to the stack, and proceed to popping the stack instead if the stack is full

Parameters
[in]early_testBoolean condition based on the minv check and visited buffer check
[in]x_posX-coordinate of pixel that is going to be recorded, has to be within the boundary
[in]y_posY-coordinate of pixel that is going to be recorded, has to be within the boundary
[in]x_curX-coordinate of current central pixel
[in]y_curY-coordinate of current central pixel

Definition at line 242 of file canny.cl.

Referenced by hysteresis().

#define EDGE   255

Definition at line 227 of file canny.cl.

Referenced by hysteresis().

#define hysteresis_local_stack_L1   8

Definition at line 228 of file canny.cl.

Referenced by hysteresis().

#define hysteresis_local_stack_L2   16

Definition at line 229 of file canny.cl.

Referenced by hysteresis().

Function Documentation

__kernel void combine_gradients_L1 ( __global uchar *  src1_ptr,
uint  src1_stride_x,
uint  src1_step_x,
uint  src1_stride_y,
uint  src1_step_y,
uint  src1_offset_first_element_in_bytes,
__global uchar *  src2_ptr,
uint  src2_stride_x,
uint  src2_step_x,
uint  src2_stride_y,
uint  src2_step_y,
uint  src2_offset_first_element_in_bytes,
__global uchar *  grad_ptr,
uint  grad_stride_x,
uint  grad_step_x,
uint  grad_stride_y,
uint  grad_step_y,
uint  grad_offset_first_element_in_bytes,
__global uchar *  angle_ptr,
uint  angle_stride_x,
uint  angle_step_x,
uint  angle_stride_y,
uint  angle_step_y,
uint  angle_offset_first_element_in_bytes 
)

Calculate the magnitude and phase from horizontal and vertical result of sobel result.

Note
The calculation of gradient uses level 1 normalisation.
Attention
The input and output data types need to be passed at compile time using -DDATA_TYPE_IN and -DDATA_TYPE_OUT: e.g. -DDATA_TYPE_IN=uchar -DDATA_TYPE_OUT=short
Parameters
[in]src1_ptrPointer to the source image (Vertical result of Sobel). Supported data types: S16, S32
[in]src1_stride_xStride of the source image in X dimension (in bytes)
[in]src1_step_xsrc1_stride_x * number of elements along X processed per workitem(in bytes)
[in]src1_stride_yStride of the source image in Y dimension (in bytes)
[in]src1_step_ysrc1_stride_y * number of elements along Y processed per workitem(in bytes)
[in]src1_offset_first_element_in_bytesThe offset of the first element in the source image
[in]src2_ptrPointer to the source image (Vertical result of Sobel). Supported data types: S16, S32
[in]src2_stride_xStride of the source image in X dimension (in bytes)
[in]src2_step_xsrc2_stride_x * number of elements along X processed per workitem(in bytes)
[in]src2_stride_yStride of the source image in Y dimension (in bytes)
[in]src2_step_ysrc2_stride_y * number of elements along Y processed per workitem(in bytes)
[in]src2_offset_first_element_in_bytesThe offset of the first element in the source image
[out]grad_ptrPointer to the gradient output. Supported data types: U16, U32
[in]grad_stride_xStride of the source image in X dimension (in bytes)
[in]grad_step_xgrad_stride_x * number of elements along X processed per workitem(in bytes)
[in]grad_stride_yStride of the source image in Y dimension (in bytes)
[in]grad_step_ygrad_stride_y * number of elements along Y processed per workitem(in bytes)
[in]grad_offset_first_element_in_bytesThe offset of the first element of the output
[out]angle_ptrPointer to the angle output. Supported data types: U8
[in]angle_stride_xStride of the source image in X dimension (in bytes)
[in]angle_step_xangle_stride_x * number of elements along X processed per workitem(in bytes)
[in]angle_stride_yStride of the source image in Y dimension (in bytes)
[in]angle_step_yangle_stride_y * number of elements along Y processed per workitem(in bytes)
[in]angle_offset_first_element_in_bytesThe offset of the first element of the output

Definition at line 57 of file canny.cl.

References arm_compute::test::fixed_point_arithmetic::detail::abs(), CONVERT_SAT, CONVERT_TO_IMAGE_STRUCT, DATA_TYPE_OUT, Image::ptr, and VEC_DATA_TYPE.

62 {
63  // Construct images
64  Image src1 = CONVERT_TO_IMAGE_STRUCT(src1);
65  Image src2 = CONVERT_TO_IMAGE_STRUCT(src2);
66  Image grad = CONVERT_TO_IMAGE_STRUCT(grad);
67  Image angle = CONVERT_TO_IMAGE_STRUCT(angle);
68 
69  // Load sobel horizontal and vertical values
70  VEC_DATA_TYPE(DATA_TYPE_IN, 4)
71  h = vload4(0, (__global DATA_TYPE_IN *)src1.ptr);
72  VEC_DATA_TYPE(DATA_TYPE_IN, 4)
73  v = vload4(0, (__global DATA_TYPE_IN *)src2.ptr);
74 
75  /* Calculate the gradient, using level 1 normalisation method */
77  m = CONVERT_SAT((abs(h) + abs(v)), VEC_DATA_TYPE(DATA_TYPE_OUT, 4));
78 
79  /* Calculate the angle */
80  float4 p = atan2pi(convert_float4(v), convert_float4(h));
81 
82  /* Remap angle to range [0, 256) */
83  p = select(p, p + 2, p < 0.0f) * 128.0f;
84 
85  /* Store results */
86  vstore4(m, 0, (__global DATA_TYPE_OUT *)grad.ptr);
87  vstore4(convert_uchar4_sat_rte(p), 0, angle.ptr);
88 }
#define CONVERT_SAT(a, b)
#define CONVERT_TO_IMAGE_STRUCT(name)
Definition: helpers.h:102
Structure to hold Image information.
Definition: helpers.h:140
#define VEC_DATA_TYPE(type, size)
Definition: fixed_point.h:93
#define DATA_TYPE_OUT
fixed_point< T > abs(fixed_point< T > x)
Definition: FixedPoint.h:914
__kernel void combine_gradients_L2 ( __global uchar *  src1_ptr,
uint  src1_stride_x,
uint  src1_step_x,
uint  src1_stride_y,
uint  src1_step_y,
uint  src1_offset_first_element_in_bytes,
__global uchar *  src2_ptr,
uint  src2_stride_x,
uint  src2_step_x,
uint  src2_stride_y,
uint  src2_step_y,
uint  src2_offset_first_element_in_bytes,
__global uchar *  grad_ptr,
uint  grad_stride_x,
uint  grad_step_x,
uint  grad_stride_y,
uint  grad_step_y,
uint  grad_offset_first_element_in_bytes,
__global uchar *  angle_ptr,
uint  angle_stride_x,
uint  angle_step_x,
uint  angle_stride_y,
uint  angle_step_y,
uint  angle_offset_first_element_in_bytes 
)

Calculate the gradient and angle from horizontal and vertical result of sobel result.

Note
The calculation of gradient uses level 2 normalisation
Attention
The input and output data types need to be passed at compile time using -DDATA_TYPE_IN and -DDATA_TYPE_OUT: e.g. -DDATA_TYPE_IN=uchar -DDATA_TYPE_OUT=short
Parameters
[in]src1_ptrPointer to the source image (Vertical result of Sobel). Supported data types: S16, S32
[in]src1_stride_xStride of the source image in X dimension (in bytes)
[in]src1_step_xsrc1_stride_x * number of elements along X processed per workitem(in bytes)
[in]src1_stride_yStride of the source image in Y dimension (in bytes)
[in]src1_step_ysrc1_stride_y * number of elements along Y processed per workitem(in bytes)
[in]src1_offset_first_element_in_bytesThe offset of the first element in the source image
[in]src2_ptrPointer to the source image (Vertical result of Sobel). Supported data types: S16, S32
[in]src2_stride_xStride of the source image in X dimension (in bytes)
[in]src2_step_xsrc2_stride_x * number of elements along X processed per workitem(in bytes)
[in]src2_stride_yStride of the source image in Y dimension (in bytes)
[in]src2_step_ysrc2_stride_y * number of elements along Y processed per workitem(in bytes)
[in]src2_offset_first_element_in_bytesThe offset of the first element in the source image
[out]grad_ptrPointer to the gradient output. Supported data types: U16, U32
[in]grad_stride_xStride of the source image in X dimension (in bytes)
[in]grad_step_xgrad_stride_x * number of elements along X processed per workitem(in bytes)
[in]grad_stride_yStride of the source image in Y dimension (in bytes)
[in]grad_step_ygrad_stride_y * number of elements along Y processed per workitem(in bytes)
[in]grad_offset_first_element_in_bytesThe offset of the first element of the output
[out]angle_ptrPointer to the angle output. Supported data types: U8
[in]angle_stride_xStride of the source image in X dimension (in bytes)
[in]angle_step_xangle_stride_x * number of elements along X processed per workitem(in bytes)
[in]angle_stride_yStride of the source image in Y dimension (in bytes)
[in]angle_step_yangle_stride_y * number of elements along Y processed per workitem(in bytes)
[in]angle_offset_first_element_in_bytesThe offset of the first element of the output

Definition at line 121 of file canny.cl.

References CONVERT_SAT_ROUND, CONVERT_TO_IMAGE_STRUCT, DATA_TYPE_OUT, Image::ptr, and VEC_DATA_TYPE.

126 {
127  // Construct images
128  Image src1 = CONVERT_TO_IMAGE_STRUCT(src1);
129  Image src2 = CONVERT_TO_IMAGE_STRUCT(src2);
130  Image grad = CONVERT_TO_IMAGE_STRUCT(grad);
131  Image angle = CONVERT_TO_IMAGE_STRUCT(angle);
132 
133  // Load sobel horizontal and vertical values
134  float4 h = convert_float4(vload4(0, (__global DATA_TYPE_IN *)src1.ptr));
135  float4 v = convert_float4(vload4(0, (__global DATA_TYPE_IN *)src2.ptr));
136 
137  /* Calculate the gradient, using level 2 normalisation method */
138  float4 m = sqrt(h * h + v * v);
139 
140  /* Calculate the angle */
141  float4 p = atan2pi(v, h);
142 
143  /* Remap angle to range [0, 256) */
144  p = select(p, p + 2, p < 0.0f) * 128.0f;
145 
146  /* Store results */
147  vstore4(CONVERT_SAT_ROUND(m, VEC_DATA_TYPE(DATA_TYPE_OUT, 4), rte), 0, (__global DATA_TYPE_OUT *)grad.ptr);
148  vstore4(convert_uchar4_sat_rte(p), 0, angle.ptr);
149 }
#define CONVERT_TO_IMAGE_STRUCT(name)
Definition: helpers.h:102
Structure to hold Image information.
Definition: helpers.h:140
__global uchar * ptr
Pointer to the starting postion of the buffer.
Definition: helpers.h:142
#define CONVERT_SAT_ROUND(x, type, round)
Definition: helpers.h:58
#define VEC_DATA_TYPE(type, size)
Definition: fixed_point.h:93
#define DATA_TYPE_OUT
kernel void hysteresis ( __global uchar *  src_ptr,
uint  src_stride_x,
uint  src_step_x,
uint  src_stride_y,
uint  src_step_y,
uint  src_offset_first_element_in_bytes,
__global uchar *  out_ptr,
uint  out_stride_x,
uint  out_step_x,
uint  out_stride_y,
uint  out_step_y,
uint  out_offset_first_element_in_bytes,
__global uchar *  visited_ptr,
uint  visited_stride_x,
uint  visited_step_x,
uint  visited_stride_y,
uint  visited_step_y,
uint  visited_offset_first_element_in_bytes,
__global uchar *  recorded_ptr,
uint  recorded_stride_x,
uint  recorded_step_x,
uint  recorded_stride_y,
uint  recorded_step_y,
uint  recorded_offset_first_element_in_bytes,
__global uchar *  l1_stack_ptr,
uint  l1_stack_stride_x,
uint  l1_stack_step_x,
uint  l1_stack_stride_y,
uint  l1_stack_step_y,
uint  l1_stack_offset_first_element_in_bytes,
__global uchar *  l1_stack_counter_ptr,
uint  l1_stack_counter_stride_x,
uint  l1_stack_counter_step_x,
uint  l1_stack_counter_stride_y,
uint  l1_stack_counter_step_y,
uint  l1_stack_counter_offset_first_element_in_bytes,
uint  low_thr,
uint  up_thr,
int  width,
int  height 
)

Perform hysteresis.

Attention
The input data_type needs to be passed at compile time using -DDATA_TYPE_IN: e.g. -DDATA_TYPE_IN=short
Parameters
[in]src_ptrPointer to the input image. Supported data types: U8
[in]src_stride_xStride of the source image in X dimension (in bytes)
[in]src_step_xsrc_stride_x * number of elements along X processed per workitem(in bytes)
[in]src_stride_yStride of the source image in Y dimension (in bytes)
[in]src_step_ysrc_stride_y * number of elements along Y processed per workitem(in bytes)
[in]src_offset_first_element_in_bytesThe offset of the first element of the output
[out]out_ptrPointer to the output image. Supported data types: U8
[in]out_stride_xStride of the source image in X dimension (in bytes)
[in]out_step_xout_stride_x * number of elements along X processed per workitem(in bytes)
[in]out_stride_yStride of the source image in Y dimension (in bytes)
[in]out_step_yout_stride_y * number of elements along Y processed per workitem(in bytes)
[in]out_offset_first_element_in_bytesThe offset of the first element of the output
[out]visited_ptrPointer to the visited buffer, where pixels are marked as visited. Supported data types: U32
[in]visited_stride_xStride of the source image in X dimension (in bytes)
[in]visited_step_xvisited_stride_x * number of elements along X processed per workitem(in bytes)
[in]visited_stride_yStride of the source image in Y dimension (in bytes)
[in]visited_step_yvisited_stride_y * number of elements along Y processed per workitem(in bytes)
[in]visited_offset_first_element_in_bytesThe offset of the first element of the output
[out]recorded_ptrPointer to the recorded buffer, where pixels are marked as recorded. Supported data types: U32
[in]recorded_stride_xStride of the source image in X dimension (in bytes)
[in]recorded_step_xrecorded_stride_x * number of elements along X processed per workitem(in bytes)
[in]recorded_stride_yStride of the source image in Y dimension (in bytes)
[in]recorded_step_yrecorded_stride_y * number of elements along Y processed per workitem(in bytes)
[in]recorded_offset_first_element_in_bytesThe offset of the first element of the output
[out]l1_stack_ptrPointer to the l1 stack of a pixel. Supported data types: S32
[in]l1_stack_stride_xStride of the source image in X dimension (in bytes)
[in]l1_stack_step_xl1_stack_stride_x * number of elements along X processed per workitem(in bytes)
[in]l1_stack_stride_yStride of the source image in Y dimension (in bytes)
[in]l1_stack_step_yl1_stack_stride_y * number of elements along Y processed per workitem(in bytes)
[in]l1_stack_offset_first_element_in_bytesThe offset of the first element of the output
[out]l1_stack_counter_ptrPointer to the l1 stack counters of an image. Supported data types: U8
[in]l1_stack_counter_stride_xStride of the source image in X dimension (in bytes)
[in]l1_stack_counter_step_xl1_stack_counter_stride_x * number of elements along X processed per workitem(in bytes)
[in]l1_stack_counter_stride_yStride of the source image in Y dimension (in bytes)
[in]l1_stack_counter_step_yl1_stack_counter_stride_y * number of elements along Y processed per workitem(in bytes)
[in]l1_stack_counter_offset_first_element_in_bytesThe offset of the first element of the output
[in]low_thrThe lower threshold
[in]up_thrThe upper threshold
[in]widthThe width of the image.
[in]heightThe height of the image

Definition at line 306 of file canny.cl.

References arm_compute::test::validation::c, check_pixel, CONVERT_TO_IMAGE_STRUCT_NO_STEP, EDGE, hysteresis_local_stack_L1, hysteresis_local_stack_L2, arm_compute::test::fixed_point_arithmetic::detail::max(), arm_compute::test::fixed_point_arithmetic::detail::min(), offset(), Image::ptr, arm_compute::test::validation::src, Image::stride_x, Image::stride_y, and VEC_DATA_TYPE.

317 {
318  // Create images
321  Image visited = CONVERT_TO_IMAGE_STRUCT_NO_STEP(visited);
322  Image recorded = CONVERT_TO_IMAGE_STRUCT_NO_STEP(recorded);
323  Image l1_stack = CONVERT_TO_IMAGE_STRUCT_NO_STEP(l1_stack);
324  Image l1_stack_counter = CONVERT_TO_IMAGE_STRUCT_NO_STEP(l1_stack_counter);
325 
326  // Index
327  int x = get_global_id(0);
328  int y = get_global_id(1);
329 
330  // Load value
331  DATA_TYPE_IN val = *((__global DATA_TYPE_IN *)offset(&src, x, y));
332 
333  // If less than upper threshold set to NO_EDGE and return
334  if(val <= up_thr)
335  {
336  *offset(&out, x, y) = 0;
337  return;
338  }
339 
340  // Init local stack 2
341  short2 stack_L2[hysteresis_local_stack_L2] = { 0 };
342  int L2_counter = 0;
343 
344  // Perform recursive hysteresis
345  while(true)
346  {
347  // Get L1 stack pointer
348  __global short2 *l1_ptr = (__global short2 *)(l1_stack.ptr + y * l1_stack.stride_y + x * hysteresis_local_stack_L1 * l1_stack.stride_x);
349 
350  // If the pixel has already been visited, proceed with the items in the stack instead
351  if(atomic_or((__global uint *)offset(&visited, x, y), 1) != 0)
352  {
353  goto pop_stack;
354  }
355 
356  // Set strong edge
357  *offset(&out, x, y) = EDGE;
358 
359  // If it is the top of stack l2, we don't need check the surrounding pixels
360  if(L2_counter > (hysteresis_local_stack_L2 - 1))
361  {
362  goto pop_stack2;
363  }
364 
365  // Points to the start of the local stack;
366  char c;
367 
368  VEC_DATA_TYPE(DATA_TYPE_IN, 4)
369  x_tmp;
370  uint4 v_tmp;
371 
372  // Get direction pixel indices
373  int N = max(y - 1, 0), S = min(y + 1, height - 2), W = max(x - 1, 0), E = min(x + 1, width - 2);
374 
375  // Check 8 pixels around for week edges where low_thr < val <= up_thr
376  x_tmp = vload4(0, (__global DATA_TYPE_IN *)offset(&src, W, N));
377  v_tmp = vload4(0, (__global uint *)offset(&visited, W, N));
378  check_pixel(((x_tmp.s0 <= low_thr) || v_tmp.s0 || (x_tmp.s0 > up_thr)), W, N, x, y); // NW
379  check_pixel(((x_tmp.s1 <= low_thr) || v_tmp.s1 || (x_tmp.s1 > up_thr)), x, N, x, y); // N
380  check_pixel(((x_tmp.s2 <= low_thr) || v_tmp.s2 || (x_tmp.s2 > up_thr)), E, N, x, y); // NE
381 
382  x_tmp = vload4(0, (__global DATA_TYPE_IN *)offset(&src, W, y));
383  v_tmp = vload4(0, (__global uint *)offset(&visited, W, y));
384  check_pixel(((x_tmp.s0 <= low_thr) || v_tmp.s0 || (x_tmp.s0 > up_thr)), W, y, x, y); // W
385  check_pixel(((x_tmp.s2 <= low_thr) || v_tmp.s2 || (x_tmp.s2 > up_thr)), E, y, x, y); // E
386 
387  x_tmp = vload4(0, (__global DATA_TYPE_IN *)offset(&src, W, S));
388  v_tmp = vload4(0, (__global uint *)offset(&visited, W, S));
389  check_pixel(((x_tmp.s0 <= low_thr) || v_tmp.s0 || (x_tmp.s0 > up_thr)), W, S, x, y); // SW
390  check_pixel(((x_tmp.s1 <= low_thr) || v_tmp.s1 || (x_tmp.s1 > up_thr)), x, S, x, y); // S
391  check_pixel(((x_tmp.s2 <= low_thr) || v_tmp.s2 || (x_tmp.s2 > up_thr)), E, S, x, y); // SE
392 
393 #undef check_pixel
394 
395 pop_stack:
396  c = *((__global char *)offset(&l1_stack_counter, x, y));
397 
398  if(c >= 1)
399  {
400  *((__global char *)offset(&l1_stack_counter, x, y)) -= 1;
401  int2 l_c = convert_int2(l1_ptr[c - 1]);
402 
403  // Push the current position into level 2 stack
404  stack_L2[L2_counter].x = x;
405  stack_L2[L2_counter].y = y;
406 
407  x = l_c.x;
408  y = l_c.y;
409 
410  L2_counter++;
411 
412  continue;
413  }
414 
415  if(L2_counter > 0)
416  {
417  goto pop_stack2;
418  }
419  else
420  {
421  return;
422  }
423 
424 pop_stack2:
425  L2_counter--;
426  x = stack_L2[L2_counter].x;
427  y = stack_L2[L2_counter].y;
428  };
429 }
#define hysteresis_local_stack_L1
Definition: canny.cl:228
fixed_point< T > min(fixed_point< T > x, fixed_point< T > y)
Definition: FixedPoint.h:884
#define CONVERT_TO_IMAGE_STRUCT_NO_STEP(name)
Definition: helpers.h:105
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:301
#define EDGE
Definition: canny.cl:227
Structure to hold Image information.
Definition: helpers.h:140
__global uchar * ptr
Pointer to the starting postion of the buffer.
Definition: helpers.h:142
#define VEC_DATA_TYPE(type, size)
Definition: fixed_point.h:93
#define check_pixel(early_test, x_pos, y_pos, x_cur, y_cur)
Check whether pixel is valid.
Definition: canny.cl:242
#define hysteresis_local_stack_L2
Definition: canny.cl:229
fixed_point< T > max(fixed_point< T > x, fixed_point< T > y)
Definition: FixedPoint.h:889
int stride_y
Stride of the image in Y dimension (in bytes)
Definition: helpers.h:145
convolution configure & src
int stride_x
Stride of the image in X dimension (in bytes)
Definition: helpers.h:144
__kernel void suppress_non_maximum ( __global uchar *  grad_ptr,
uint  grad_stride_x,
uint  grad_step_x,
uint  grad_stride_y,
uint  grad_step_y,
uint  grad_offset_first_element_in_bytes,
__global uchar *  angle_ptr,
uint  angle_stride_x,
uint  angle_step_x,
uint  angle_stride_y,
uint  angle_step_y,
uint  angle_offset_first_element_in_bytes,
__global uchar *  non_max_ptr,
uint  non_max_stride_x,
uint  non_max_step_x,
uint  non_max_stride_y,
uint  non_max_step_y,
uint  non_max_offset_first_element_in_bytes,
uint  lower_thr 
)

Perform non maximum suppression.

Attention
The input and output data types need to be passed at compile time using -DDATA_TYPE_IN and -DDATA_TYPE_OUT: e.g. -DDATA_TYPE_IN=uchar -DDATA_TYPE_OUT=short
Parameters
[in]grad_ptrPointer to the gradient output. Supported data types: S16, S32
[in]grad_stride_xStride of the source image in X dimension (in bytes)
[in]grad_step_xgrad_stride_x * number of elements along X processed per workitem(in bytes)
[in]grad_stride_yStride of the source image in Y dimension (in bytes)
[in]grad_step_ygrad_stride_y * number of elements along Y processed per workitem(in bytes)
[in]grad_offset_first_element_in_bytesThe offset of the first element of the output
[in]angle_ptrPointer to the angle output. Supported data types: U8
[in]angle_stride_xStride of the source image in X dimension (in bytes)
[in]angle_step_xangle_stride_x * number of elements along X processed per workitem(in bytes)
[in]angle_stride_yStride of the source image in Y dimension (in bytes)
[in]angle_step_yangle_stride_y * number of elements along Y processed per workitem(in bytes)
[in]angle_offset_first_element_in_bytesTThe offset of the first element of the output
[out]non_max_ptrPointer to the non maximum suppressed output. Supported data types: U16, U32
[in]non_max_stride_xStride of the source image in X dimension (in bytes)
[in]non_max_step_xnon_max_stride_x * number of elements along X processed per workitem(in bytes)
[in]non_max_stride_yStride of the source image in Y dimension (in bytes)
[in]non_max_step_ynon_max_stride_y * number of elements along Y processed per workitem(in bytes)
[in]non_max_offset_first_element_in_bytesThe offset of the first element of the output
[in]lower_thrThe low threshold

Definition at line 191 of file canny.cl.

References CONVERT_TO_IMAGE_STRUCT, DATA_TYPE_OUT, offset(), and Image::ptr.

196 {
197  // Construct images
198  Image grad = CONVERT_TO_IMAGE_STRUCT(grad);
199  Image angle = CONVERT_TO_IMAGE_STRUCT(angle);
200  Image non_max = CONVERT_TO_IMAGE_STRUCT(non_max);
201 
202  // Get gradient and angle
203  DATA_TYPE_IN gradient = *((__global DATA_TYPE_IN *)grad.ptr);
204  uchar an = convert_ushort(*angle.ptr);
205 
206  if(gradient <= lower_thr)
207  {
208  return;
209  }
210 
211  // Divide the whole round into 8 directions
212  uchar ang = 127 - an;
213  DATA_TYPE_OUT q_an = (ang + 16) >> 5;
214 
215  // Find the two pixels in the perpendicular direction
216  short2 x_p = neighbours_coords[q_an].s02;
217  short2 y_p = neighbours_coords[q_an].s13;
218  DATA_TYPE_IN g1 = *((global DATA_TYPE_IN *)offset(&grad, x_p.x, y_p.x));
219  DATA_TYPE_IN g2 = *((global DATA_TYPE_IN *)offset(&grad, x_p.y, y_p.y));
220 
221  if((gradient > g1) && (gradient > g2))
222  {
223  *((global DATA_TYPE_OUT *)non_max.ptr) = gradient;
224  }
225 }
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:301
__constant short4 neighbours_coords[]
Array that holds the relative coordinates offset for the neighbouring pixels.
Definition: canny.cl:153
#define CONVERT_TO_IMAGE_STRUCT(name)
Definition: helpers.h:102
Structure to hold Image information.
Definition: helpers.h:140
__global uchar * ptr
Pointer to the starting postion of the buffer.
Definition: helpers.h:142
#define DATA_TYPE_OUT

Variable Documentation

__constant short4 neighbours_coords[]
Initial value:
=
{
{ -1, 0, 1, 0 },
{ -1, 1, 1, -1 },
{ 0, 1, 0, -1 },
{ 1, 1, -1, -1 },
{ 1, 0, -1, 0 },
{ 1, -1, -1, 1 },
{ 0, 1, 0, -1 },
{ -1, -1, 1, 1 },
{ -1, 0, 1, 0 },
}

Array that holds the relative coordinates offset for the neighbouring pixels.

Definition at line 153 of file canny.cl.