Compute Library
 21.02
NENonLinearFilterKernel Class Reference

Interface for the kernel to apply a non-linear filter. More...

#include <NENonLinearFilterKernel.h>

Collaboration diagram for NENonLinearFilterKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NENonLinearFilterKernel ()
 Default constructor. More...
 
 NENonLinearFilterKernel (NENonLinearFilterKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NENonLinearFilterKerneloperator= (NENonLinearFilterKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NENonLinearFilterKernel (NENonLinearFilterKernel &&)=default
 Allow instances of this class to be moved. More...
 
NENonLinearFilterKerneloperator= (NENonLinearFilterKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NENonLinearFilterKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, bool border_undefined)
 Set the source, destination and border mode of the kernel. 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

Interface for the kernel to apply a non-linear filter.

Definition at line 37 of file NENonLinearFilterKernel.h.

Constructor & Destructor Documentation

◆ NENonLinearFilterKernel() [1/3]

Default constructor.

Definition at line 345 of file NENonLinearFilterKernel.cpp.

Referenced by NENonLinearFilterKernel::name().

346  : _border_width(0), _input(nullptr), _output(nullptr), _mask(nullptr), _pattern(MatrixPattern::BOX), _function(NonLinearFilterFunction::MIN), _func_idx(0), _border_size()
347 {
348 }

◆ NENonLinearFilterKernel() [2/3]

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

◆ NENonLinearFilterKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NENonLinearFilterKernel()

Default destructor.

Referenced by NENonLinearFilterKernel::name().

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 350 of file NENonLinearFilterKernel.cpp.

Referenced by NENonLinearFilterKernel::configure(), and NENonLinearFilterKernel::name().

351 {
352  return _border_size;
353 }

◆ configure()

void configure ( const ITensor input,
ITensor output,
NonLinearFilterFunction  function,
unsigned int  mask_size,
MatrixPattern  pattern,
const uint8_t *  mask,
bool  border_undefined 
)

Set the source, destination and border mode of the kernel.

Parameters
[in]inputSource tensor. Data type supported: U8
[out]outputDestination tensor. Data type supported: U8
[in]functionNon linear function to perform
[in]mask_sizeMask size. Supported sizes: 3, 5
[in]patternMask pattern
[in]maskThe given mask. Will be used only if pattern is specified to PATTERN_OTHER
[in]border_undefinedTrue if the border mode is undefined. False if it's replicate or constant.

Definition at line 355 of file NENonLinearFilterKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, NENonLinearFilterKernel::border_size(), arm_compute::BOX, ITensor::buffer(), arm_compute::calculate_max_window(), caffe_mnist_image_extractor::cols, arm_compute::CROSS, arm_compute::DISK, arm_compute::mlgo::parser::end(), arm_compute::execute_window_loop(), arm_compute::test::validation::fill(), ITensor::info(), arm_compute::test::validation::input, BorderSize::left, arm_compute::MAX, arm_compute::MEDIAN, arm_compute::MIN, num_elems_processed_per_iteration, Iterator::offset(), ITensorInfo::offset_element_in_bytes(), arm_compute::OTHER, Iterator::ptr(), ITensor::ptr_to_element(), caffe_mnist_image_extractor::rows, sort5(), sort9(), BorderSize::top, arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

Referenced by NENonLinearFilterKernel::name().

357 {
360  ARM_COMPUTE_ERROR_ON(3 != mask_size && 5 != mask_size);
361  ARM_COMPUTE_ERROR_ON(MatrixPattern::OTHER == pattern && nullptr == mask);
362 
363  // Set class variables
364  _border_size = BorderSize(mask_size / 2);
365  _input = input;
366  _output = output;
367  _mask = mask;
368  _pattern = pattern;
369  _function = function;
370 
371  // Configure kernel window
372  const unsigned int num_elems_processed_per_iteration = (MatrixPattern::OTHER == pattern) ? 1 : 8;
373  constexpr unsigned int num_elems_read_per_iteration = 16;
374 
375  Window win = calculate_max_window(*input->info(), num_elems_processed_per_iteration, border_undefined, border_size());
376  AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
378  AccessWindowRectangle(input->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, mask_size),
379  output_access);
380  output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
381 
382  INEKernel::configure(win);
383 
384  // Define function index
385  _func_idx = (3 == mask_size) ? 0 : 1;
386 
387  if(MatrixPattern::OTHER != pattern)
388  {
389  _func_idx = (_func_idx) * 3 + static_cast<unsigned int>(function);
390  }
391 }
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)
BorderSize border_size() const override
The size of the border for that kernel.
1 channel, 1 U8 per channel
#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
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
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
Any other matrix pattern.

◆ name()

◆ operator=() [1/2]

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

Referenced by NENonLinearFilterKernel::name().

◆ operator=() [2/2]

NENonLinearFilterKernel& operator= ( NENonLinearFilterKernel &&  )
default

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 941 of file NENonLinearFilterKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::BOX, arm_compute::CROSS, arm_compute::DISK, arm_compute::OTHER, and IKernel::window().

Referenced by NENonLinearFilterKernel::name().

942 {
946 
947  using NonLinearFilterFunction = void (NENonLinearFilterKernel::*)(const Window & window);
948 
949  // Function table for BOX pattern
950  static const std::array<NonLinearFilterFunction, 6> func_table_box =
951  {
952  {
953  &NENonLinearFilterKernel::median_filter_box<3, 3>,
954  &NENonLinearFilterKernel::min_filter_box<3, 3>,
955  &NENonLinearFilterKernel::max_filter_box<3, 3>,
956  &NENonLinearFilterKernel::median_filter_box<5, 5>,
957  &NENonLinearFilterKernel::min_filter_box<5, 5>,
958  &NENonLinearFilterKernel::max_filter_box<5, 5>,
959  }
960  };
961 
962  // Function table for CROSS pattern
963  static const std::array<NonLinearFilterFunction, 6> func_table_cross =
964  {
965  {
966  &NENonLinearFilterKernel::median_filter_cross<3, 3>,
967  &NENonLinearFilterKernel::min_filter_cross<3, 3>,
968  &NENonLinearFilterKernel::max_filter_cross<3, 3>,
969  &NENonLinearFilterKernel::median_filter_cross<5, 5>,
970  &NENonLinearFilterKernel::min_filter_cross<5, 5>,
971  &NENonLinearFilterKernel::max_filter_cross<5, 5>,
972  }
973  };
974 
975  // Function table for DISK pattern
976  static const std::array<NonLinearFilterFunction, 6> func_table_disk =
977  {
978  {
979  &NENonLinearFilterKernel::median_filter_box<3, 3>,
980  &NENonLinearFilterKernel::min_filter_box<3, 3>,
981  &NENonLinearFilterKernel::max_filter_box<3, 3>,
982  &NENonLinearFilterKernel::median_filter_disk<5, 5>,
983  &NENonLinearFilterKernel::min_filter_disk<5, 5>,
984  &NENonLinearFilterKernel::max_filter_disk<5, 5>,
985  }
986  };
987 
988  // Function table for OTHER pattern
989  static const std::array<NonLinearFilterFunction, 2> func_table_generic =
990  {
991  {
992  &NENonLinearFilterKernel::non_linear_filter_generic<3, 3>,
993  &NENonLinearFilterKernel::non_linear_filter_generic<5, 5>,
994  }
995  };
996 
997  switch(_pattern)
998  {
999  case MatrixPattern::BOX:
1000  ARM_COMPUTE_ERROR_ON(_func_idx >= func_table_box.size());
1001  (this->*func_table_box[_func_idx])(window);
1002  break;
1003  case MatrixPattern::CROSS:
1004  ARM_COMPUTE_ERROR_ON(_func_idx >= func_table_cross.size());
1005  (this->*func_table_cross[_func_idx])(window);
1006  break;
1007  case MatrixPattern::DISK:
1008  ARM_COMPUTE_ERROR_ON(_func_idx >= func_table_disk.size());
1009  (this->*func_table_disk[_func_idx])(window);
1010  break;
1011  case MatrixPattern::OTHER:
1012  default:
1013  ARM_COMPUTE_ERROR_ON(_func_idx >= func_table_generic.size());
1014  (this->*func_table_generic[_func_idx])(window);
1015  break;
1016  }
1017 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Cross pattern matrix.
Any other matrix pattern.
NonLinearFilterFunction
Available non linear functions.
Definition: Types.h:513
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

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