Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef __ARM_COMPUTE_NENONLINEARFILTERKERNEL_H__ |
| 25 | #define __ARM_COMPUTE_NENONLINEARFILTERKERNEL_H__ |
| 26 | |
| 27 | #include "arm_compute/core/NEON/INEKernel.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | |
| 30 | #include <cstdint> |
| 31 | |
| 32 | namespace arm_compute |
| 33 | { |
| 34 | class ITensor; |
| 35 | |
| 36 | /** Interface for the kernel to apply a non-linear filter */ |
| 37 | class NENonLinearFilterKernel : public INEKernel |
| 38 | { |
| 39 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 40 | const char *name() const override |
| 41 | { |
| 42 | return "NENonLinearFilterKernel"; |
| 43 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 44 | /** Default constructor */ |
| 45 | NENonLinearFilterKernel(); |
| 46 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 47 | NENonLinearFilterKernel(NENonLinearFilterKernel &) = delete; |
| 48 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 49 | NENonLinearFilterKernel &operator=(NENonLinearFilterKernel &) = delete; |
| 50 | /** Allow instances of this class to be moved */ |
| 51 | NENonLinearFilterKernel(NENonLinearFilterKernel &&) = default; |
| 52 | /** Allow instances of this class to be moved */ |
| 53 | NENonLinearFilterKernel &operator=(NENonLinearFilterKernel &&) = default; |
| 54 | /** Set the source, destination and border mode of the kernel |
| 55 | * |
| 56 | * @param[in] input Source tensor. Data type supported: U8 |
| 57 | * @param[out] output Destination tensor. Data type supported: U8 |
| 58 | * @param[in] function Non linear function to perform |
| 59 | * @param[in] mask_size Mask size. Supported sizes: 3, 5 |
| 60 | * @param[in] pattern Mask pattern |
| 61 | * @param[in] mask The given mask. Will be used only if pattern is specified to PATTERN_OTHER |
| 62 | * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant. |
| 63 | */ |
| 64 | void configure(const ITensor *input, ITensor *output, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, bool border_undefined); |
| 65 | |
| 66 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 67 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | BorderSize border_size() const override; |
| 69 | |
| 70 | private: |
| 71 | /** Fill mask with the corresponding given pattern. |
| 72 | * |
| 73 | * @param[in,out] mask Mask to be filled according to pattern |
| 74 | * @param[in] cols Columns (width) of mask |
| 75 | * @param[in] rows Rows (height) of mask |
| 76 | * @param[in] pattern Pattern to fill the mask according to |
| 77 | */ |
| 78 | void fill_mask(uint8_t *mask, int cols, int rows, MatrixPattern pattern); |
| 79 | /** Apply a median filter when given mask pattern is defined as box. |
| 80 | * |
| 81 | * @param[in] win Window to apply the filter on. |
| 82 | */ |
| 83 | template <int mask_w, int mask_h> |
| 84 | void median_filter_box(const Window &win); |
| 85 | /** Apply a min filter when given mask pattern is defined as box. |
| 86 | * |
| 87 | * @param[in] win Window to apply the filter on. |
| 88 | */ |
| 89 | template <int mask_w, int mask_h> |
| 90 | void min_filter_box(const Window &win); |
| 91 | /** Apply a max filter when given mask pattern is defined as box. |
| 92 | * |
| 93 | * @param[in] win Window to apply the filter on. |
| 94 | */ |
| 95 | template <int mask_w, int mask_h> |
| 96 | void max_filter_box(const Window &win); |
| 97 | /** Apply a median filter when given mask pattern is defined as cross. |
| 98 | * |
| 99 | * @param[in] win Window to apply the filter on. |
| 100 | */ |
| 101 | template <int mask_w, int mask_h> |
| 102 | void median_filter_cross(const Window &win); |
| 103 | /** Apply a min filter when given mask pattern is defined as cross. |
| 104 | * |
| 105 | * @param[in] win Window to apply the filter on. |
| 106 | */ |
| 107 | template <int mask_w, int mask_h> |
| 108 | void min_filter_cross(const Window &win); |
| 109 | /** Apply a max filter when given mask pattern is defined as cross. |
| 110 | * |
| 111 | * @param[in] win Window to apply the filter on. |
| 112 | */ |
| 113 | template <int mask_w, int mask_h> |
| 114 | void max_filter_cross(const Window &win); |
| 115 | /** Apply a median filter when given mask pattern is defined as disk. |
| 116 | * |
| 117 | * @param[in] win Window to apply the filter on. |
| 118 | */ |
| 119 | template <int mask_w, int mask_h> |
| 120 | void median_filter_disk(const Window &win); |
| 121 | /** Apply a min filter when given mask pattern is defined as disk. |
| 122 | * |
| 123 | * @param[in] win Window to apply the filter on. |
| 124 | */ |
| 125 | template <int mask_w, int mask_h> |
| 126 | void min_filter_disk(const Window &win); |
| 127 | /** Apply a max filter when given mask pattern is defined as disk. |
| 128 | * |
| 129 | * @param[in] win Window to apply the filter on. |
| 130 | */ |
| 131 | template <int mask_w, int mask_h> |
| 132 | void max_filter_disk(const Window &win); |
| 133 | /** Apply a non-linear filter when given mask has user-defined pattern. |
| 134 | * |
| 135 | * @param[in] win Window to apply the filter on. |
| 136 | */ |
| 137 | template <int mask_w, int mask_h> |
| 138 | void non_linear_filter_generic(const Window &win); |
| 139 | |
| 140 | private: |
| 141 | unsigned int _border_width; |
| 142 | const ITensor *_input; |
| 143 | ITensor *_output; |
| 144 | const uint8_t *_mask; |
| 145 | MatrixPattern _pattern; |
| 146 | NonLinearFilterFunction _function; |
| 147 | unsigned int _func_idx; |
| 148 | BorderSize _border_size; |
| 149 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 150 | } // namespace arm_compute |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 151 | #endif /*__ARM_COMPUTE_NENONLINEARFILTERKERNEL_H__ */ |