blob: 3cef12e8ec038f552181dc7398959417cdf2d5b8 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyrouebcebf12020-10-21 00:04:14 +01002 * Copyright (c) 2016-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NENONLINEARFILTERKERNEL_H
25#define ARM_COMPUTE_NENONLINEARFILTERKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Types.h"
Michalis Spyrouebcebf12020-10-21 00:04:14 +010028#include "src/core/NEON/INEKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029
30#include <cstdint>
31
32namespace arm_compute
33{
34class ITensor;
35
36/** Interface for the kernel to apply a non-linear filter */
37class NENonLinearFilterKernel : public INEKernel
38{
39public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000040 const char *name() const override
41 {
42 return "NENonLinearFilterKernel";
43 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010044 /** 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;
Michalis Spyrouebcebf12020-10-21 00:04:14 +010054 /** Default destructor */
55 ~NENonLinearFilterKernel() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056 /** Set the source, destination and border mode of the kernel
57 *
58 * @param[in] input Source tensor. Data type supported: U8
59 * @param[out] output Destination tensor. Data type supported: U8
60 * @param[in] function Non linear function to perform
61 * @param[in] mask_size Mask size. Supported sizes: 3, 5
62 * @param[in] pattern Mask pattern
63 * @param[in] mask The given mask. Will be used only if pattern is specified to PATTERN_OTHER
64 * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant.
65 */
66 void configure(const ITensor *input, ITensor *output, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, bool border_undefined);
67
68 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010069 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 BorderSize border_size() const override;
71
72private:
73 /** Fill mask with the corresponding given pattern.
74 *
75 * @param[in,out] mask Mask to be filled according to pattern
76 * @param[in] cols Columns (width) of mask
77 * @param[in] rows Rows (height) of mask
78 * @param[in] pattern Pattern to fill the mask according to
79 */
80 void fill_mask(uint8_t *mask, int cols, int rows, MatrixPattern pattern);
81 /** Apply a median filter when given mask pattern is defined as box.
82 *
83 * @param[in] win Window to apply the filter on.
84 */
85 template <int mask_w, int mask_h>
86 void median_filter_box(const Window &win);
87 /** Apply a min filter when given mask pattern is defined as box.
88 *
89 * @param[in] win Window to apply the filter on.
90 */
91 template <int mask_w, int mask_h>
92 void min_filter_box(const Window &win);
93 /** Apply a max filter when given mask pattern is defined as box.
94 *
95 * @param[in] win Window to apply the filter on.
96 */
97 template <int mask_w, int mask_h>
98 void max_filter_box(const Window &win);
99 /** Apply a median filter when given mask pattern is defined as cross.
100 *
101 * @param[in] win Window to apply the filter on.
102 */
103 template <int mask_w, int mask_h>
104 void median_filter_cross(const Window &win);
105 /** Apply a min filter when given mask pattern is defined as cross.
106 *
107 * @param[in] win Window to apply the filter on.
108 */
109 template <int mask_w, int mask_h>
110 void min_filter_cross(const Window &win);
111 /** Apply a max filter when given mask pattern is defined as cross.
112 *
113 * @param[in] win Window to apply the filter on.
114 */
115 template <int mask_w, int mask_h>
116 void max_filter_cross(const Window &win);
117 /** Apply a median filter when given mask pattern is defined as disk.
118 *
119 * @param[in] win Window to apply the filter on.
120 */
121 template <int mask_w, int mask_h>
122 void median_filter_disk(const Window &win);
123 /** Apply a min filter when given mask pattern is defined as disk.
124 *
125 * @param[in] win Window to apply the filter on.
126 */
127 template <int mask_w, int mask_h>
128 void min_filter_disk(const Window &win);
129 /** Apply a max filter when given mask pattern is defined as disk.
130 *
131 * @param[in] win Window to apply the filter on.
132 */
133 template <int mask_w, int mask_h>
134 void max_filter_disk(const Window &win);
135 /** Apply a non-linear filter when given mask has user-defined pattern.
136 *
137 * @param[in] win Window to apply the filter on.
138 */
139 template <int mask_w, int mask_h>
140 void non_linear_filter_generic(const Window &win);
141
142private:
143 unsigned int _border_width;
144 const ITensor *_input;
145 ITensor *_output;
146 const uint8_t *_mask;
147 MatrixPattern _pattern;
148 NonLinearFilterFunction _function;
149 unsigned int _func_idx;
150 BorderSize _border_size;
151};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100152} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000153#endif /*ARM_COMPUTE_NENONLINEARFILTERKERNEL_H */