Compute Library
 19.08
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...
 
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...
 
- 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 343 of file NENonLinearFilterKernel.cpp.

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

References arm_compute::BOX, and MIN.

◆ 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.

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

349 {
350  return _border_size;
351 }

Referenced by NENonLinearFilterKernel::configure().

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

355 {
358  ARM_COMPUTE_ERROR_ON(3 != mask_size && 5 != mask_size);
359  ARM_COMPUTE_ERROR_ON(MatrixPattern::OTHER == pattern && nullptr == mask);
360 
361  // Set class variables
362  _border_size = BorderSize(mask_size / 2);
363  _input = input;
364  _output = output;
365  _mask = mask;
366  _pattern = pattern;
367  _function = function;
368 
369  // Configure kernel window
370  const unsigned int num_elems_processed_per_iteration = (MatrixPattern::OTHER == pattern) ? 1 : 8;
371  constexpr unsigned int num_elems_read_per_iteration = 16;
372 
373  Window win = calculate_max_window(*input->info(), num_elems_processed_per_iteration, border_undefined, border_size());
374  AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
376  AccessWindowRectangle(input->info(), -border_size().left, -border_size().top, num_elems_read_per_iteration, mask_size),
377  output_access);
378  output_access.set_valid_region(win, input->info()->valid_region(), border_undefined, border_size());
379 
380  INEKernel::configure(win);
381 
382  // Define function index
383  _func_idx = (3 == mask_size) ? 0 : 1;
384 
385  if(MatrixPattern::OTHER != pattern)
386  {
387  _func_idx = (_func_idx) * 3 + static_cast<unsigned int>(function);
388  }
389 }
unsigned int top
top of the border
Definition: Types.h:339
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:337
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: Helpers.h:402
unsigned int left
left of the border
Definition: Types.h:342
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
Any other matrix pattern.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, NENonLinearFilterKernel::border_size(), arm_compute::calculate_max_window(), ITensor::info(), BorderSize::left, arm_compute::OTHER, BorderSize::top, arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 40 of file NENonLinearFilterKernel.h.

41  {
42  return "NENonLinearFilterKernel";
43  }

◆ operator=() [1/2]

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

◆ 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.

Implements ICPPKernel.

Definition at line 939 of file NENonLinearFilterKernel.cpp.

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

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::test::validation::info, arm_compute::OTHER, and IKernel::window().


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