Compute Library
 21.02
NEEdgeNonMaxSuppressionKernel Class Reference

Neon kernel to perform Non-Maxima suppression for Canny Edge. More...

#include <NECannyEdgeKernel.h>

Collaboration diagram for NEEdgeNonMaxSuppressionKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEEdgeNonMaxSuppressionKernel ()
 Default constructor. More...
 
 NEEdgeNonMaxSuppressionKernel (const NEEdgeNonMaxSuppressionKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEEdgeNonMaxSuppressionKerneloperator= (const NEEdgeNonMaxSuppressionKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEEdgeNonMaxSuppressionKernel (NEEdgeNonMaxSuppressionKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEEdgeNonMaxSuppressionKerneloperator= (NEEdgeNonMaxSuppressionKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEEdgeNonMaxSuppressionKernel ()
 Default destructor. More...
 
void configure (const ITensor *magnitude, const ITensor *phase, ITensor *output, int32_t upper_thr, int32_t lower_thr, bool border_undefined)
 Initialise the kernel's sources, destination and border mode. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
BorderSize border_size () const override
 The size of the border for that kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Detailed Description

Neon kernel to perform Non-Maxima suppression for Canny Edge.

Note
This kernel is meant to be used alongside CannyEdge and performs a non-maxima suppression using magnitude and phase of input to characterize points as possible edges. Thus, at the end, each point will be set to EDGE, NO_EDGE or MAYBE.
Hysteresis is computed in NEEdgeTraceKernel

Definition at line 95 of file NECannyEdgeKernel.h.

Constructor & Destructor Documentation

◆ NEEdgeNonMaxSuppressionKernel() [1/3]

Default constructor.

Definition at line 959 of file NECannyEdgeKernel.cpp.

960  : _func(nullptr), _magnitude(nullptr), _phase(nullptr), _output(nullptr), _lower_thr(0), _upper_thr(0)
961 {
962 }

◆ NEEdgeNonMaxSuppressionKernel() [2/3]

Prevent instances of this class from being copied (As this class contains pointers)

◆ NEEdgeNonMaxSuppressionKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEEdgeNonMaxSuppressionKernel()

Default destructor.

Referenced by NEGradientKernel::run().

Member Function Documentation

◆ border_size()

BorderSize border_size ( ) const
overridevirtual

The size of the border for that kernel.

Returns
The width in number of elements of the border.

Reimplemented from IKernel.

Definition at line 964 of file NECannyEdgeKernel.cpp.

Referenced by NEEdgeNonMaxSuppressionKernel::configure().

965 {
966  return BorderSize(1);
967 }

◆ configure()

void configure ( const ITensor magnitude,
const ITensor phase,
ITensor output,
int32_t  upper_thr,
int32_t  lower_thr,
bool  border_undefined 
)

Initialise the kernel's sources, destination and border mode.

Parameters
[in]magnitudeSource tensor - Magnitude. Data type supported: U16/U32.
[in]phaseSource tensor - Quantized phase. Data type supported: U8.
[out]outputOutput tensor. Data type supported: U8. It will be filled with 0 for "no edge", 127 for "maybe", 255 for "edge"
[in]upper_thrUpper threshold used for the hysteresis
[in]lower_thrLower threshold used for the hysteresis
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 969 of file NECannyEdgeKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES, ARM_COMPUTE_ERROR_ON_NULLPTR, NEEdgeNonMaxSuppressionKernel::border_size(), arm_compute::calculate_max_window(), ITensorInfo::data_type(), ITensor::info(), BorderSize::left, arm_compute::test::validation::reference::magnitude(), num_elems_processed_per_iteration, arm_compute::test::validation::reference::phase(), arm_compute::set_format_if_unknown(), arm_compute::set_shape_if_empty(), ITensorInfo::tensor_shape(), BorderSize::top, arm_compute::U16, arm_compute::U32, arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

971 {
973 
974  set_shape_if_empty(*output->info(), magnitude->info()->tensor_shape());
975 
977  set_format_if_unknown(*output->info(), Format::U8);
978 
984 
985  _magnitude = magnitude;
986  _phase = phase;
987  _output = output;
988 
989  switch(_magnitude->info()->data_type())
990  {
991  case DataType::U16:
992  _func = &non_max_suppression_U16_U8_U8;
993  break;
994  case DataType::U32:
995  _func = &non_max_suppression_U32_U8_U8;
996  break;
997  default:
998  ARM_COMPUTE_ERROR("Unsupported data type!");
999  }
1000 
1001  // Set thresholds
1002  _lower_thr = lower_thr;
1003  _upper_thr = upper_thr;
1004 
1005  constexpr unsigned int num_elems_processed_per_iteration = 8;
1006  constexpr unsigned int num_elems_read_per_iteration = 10;
1007  constexpr unsigned int num_rows_read_per_iteration = 3;
1008 
1009  // Configure kernel window
1010  Window win = calculate_max_window(*_magnitude->info(), Steps(num_elems_processed_per_iteration), border_undefined, border_size());
1011 
1012  AccessWindowRectangle mag_access(_magnitude->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, num_rows_read_per_iteration);
1013  AccessWindowHorizontal phase_access(_phase->info(), 0, num_elems_processed_per_iteration);
1014  AccessWindowHorizontal output_access(_output->info(), 0, num_elems_processed_per_iteration);
1015 
1016  update_window_and_padding(win, mag_access, phase_access, output_access);
1017 
1018  output_access.set_valid_region(win, _magnitude->info()->valid_region(), border_undefined, border_size());
1019 
1020  INEKernel::configure(win);
1021 }
bool set_format_if_unknown(ITensorInfo &info, Format format)
Set the format, data type and number of channels to the specified value if the current data type is u...
unsigned int top
top of the border
Definition: Types.h:375
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 U8 per channel
virtual DataType data_type() const =0
Data type used for each element of the tensor.
SimpleTensor< uint8_t > phase(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, PhaseType phase_type)
Definition: Phase.cpp:35
1 channel, 1 U16 per channel
BorderSize border_size() const override
The size of the border for that kernel.
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
1 channel, 1 U32 per channel
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:543
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:441
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
unsigned int left
left of the border
Definition: Types.h:378
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
unsigned int num_elems_processed_per_iteration
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
SimpleTensor< T > magnitude(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, MagnitudeType magnitude_type)
Definition: Magnitude.cpp:35

◆ name()

const char* name ( ) const
inlineoverridevirtual

◆ operator=() [1/2]

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Reimplemented from ICPPKernel.

Definition at line 1023 of file NECannyEdgeKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::data_size_from_type(), ITensorInfo::data_type(), arm_compute::execute_window_loop(), ITensor::info(), arm_compute::test::validation::reference::magnitude(), arm_compute::test::validation::reference::phase(), Iterator::ptr(), ITensorInfo::strides_in_bytes(), IKernel::window(), and NEEdgeTraceKernel::~NEEdgeTraceKernel().

1024 {
1028  ARM_COMPUTE_ERROR_ON(_func == nullptr);
1029  Iterator magnitude(_magnitude, window);
1030  Iterator phase(_phase, window);
1031  Iterator output(_output, window);
1032 
1033  const size_t input1_stride = _magnitude->info()->strides_in_bytes()[1];
1034  const size_t input1_stride_ushort = input1_stride / data_size_from_type(_magnitude->info()->data_type());
1035 
1036  execute_window_loop(window, [&](const Coordinates &)
1037  {
1038  (*_func)(magnitude.ptr(), phase.ptr(), output.ptr(), input1_stride_ushort, _lower_thr, _upper_thr);
1039  },
1040  magnitude, phase, output);
1041 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
SimpleTensor< uint8_t > phase(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, PhaseType phase_type)
Definition: Phase.cpp:35
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
size_t data_size_from_type(DataType data_type)
The size in bytes of the data type.
Definition: Utils.h:106
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
Definition: Helpers.inl:77
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
SimpleTensor< T > magnitude(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, MagnitudeType magnitude_type)
Definition: Magnitude.cpp:35
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

The documentation for this class was generated from the following files: