blob: ede0294a7307b452c7bf3c6d310e5f875392e0c5 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
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
32namespace arm_compute
33{
34class ITensor;
35
36/** Interface for the kernel to apply a non-linear filter */
37class NENonLinearFilterKernel : public INEKernel
38{
39public:
40 /** Default constructor */
41 NENonLinearFilterKernel();
42 /** Prevent instances of this class from being copied (As this class contains pointers) */
43 NENonLinearFilterKernel(NENonLinearFilterKernel &) = delete;
44 /** Prevent instances of this class from being copied (As this class contains pointers) */
45 NENonLinearFilterKernel &operator=(NENonLinearFilterKernel &) = delete;
46 /** Allow instances of this class to be moved */
47 NENonLinearFilterKernel(NENonLinearFilterKernel &&) = default;
48 /** Allow instances of this class to be moved */
49 NENonLinearFilterKernel &operator=(NENonLinearFilterKernel &&) = default;
50 /** Set the source, destination and border mode of the kernel
51 *
52 * @param[in] input Source tensor. Data type supported: U8
53 * @param[out] output Destination tensor. Data type supported: U8
54 * @param[in] function Non linear function to perform
55 * @param[in] mask_size Mask size. Supported sizes: 3, 5
56 * @param[in] pattern Mask pattern
57 * @param[in] mask The given mask. Will be used only if pattern is specified to PATTERN_OTHER
58 * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant.
59 */
60 void configure(const ITensor *input, ITensor *output, NonLinearFilterFunction function, unsigned int mask_size, MatrixPattern pattern, const uint8_t *mask, bool border_undefined);
61
62 // Inherited methods overridden:
63 void run(const Window &window) override;
64 BorderSize border_size() const override;
65
66private:
67 /** Fill mask with the corresponding given pattern.
68 *
69 * @param[in,out] mask Mask to be filled according to pattern
70 * @param[in] cols Columns (width) of mask
71 * @param[in] rows Rows (height) of mask
72 * @param[in] pattern Pattern to fill the mask according to
73 */
74 void fill_mask(uint8_t *mask, int cols, int rows, MatrixPattern pattern);
75 /** Apply a median filter when given mask pattern is defined as box.
76 *
77 * @param[in] win Window to apply the filter on.
78 */
79 template <int mask_w, int mask_h>
80 void median_filter_box(const Window &win);
81 /** Apply a min 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 min_filter_box(const Window &win);
87 /** Apply a max 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 max_filter_box(const Window &win);
93 /** Apply a median filter when given mask pattern is defined as cross.
94 *
95 * @param[in] win Window to apply the filter on.
96 */
97 template <int mask_w, int mask_h>
98 void median_filter_cross(const Window &win);
99 /** Apply a min 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 min_filter_cross(const Window &win);
105 /** Apply a max 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 max_filter_cross(const Window &win);
111 /** Apply a median filter when given mask pattern is defined as disk.
112 *
113 * @param[in] win Window to apply the filter on.
114 */
115 template <int mask_w, int mask_h>
116 void median_filter_disk(const Window &win);
117 /** Apply a min 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 min_filter_disk(const Window &win);
123 /** Apply a max 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 max_filter_disk(const Window &win);
129 /** Apply a non-linear filter when given mask has user-defined pattern.
130 *
131 * @param[in] win Window to apply the filter on.
132 */
133 template <int mask_w, int mask_h>
134 void non_linear_filter_generic(const Window &win);
135
136private:
137 unsigned int _border_width;
138 const ITensor *_input;
139 ITensor *_output;
140 const uint8_t *_mask;
141 MatrixPattern _pattern;
142 NonLinearFilterFunction _function;
143 unsigned int _func_idx;
144 BorderSize _border_size;
145};
146}
147#endif /*__ARM_COMPUTE_NENONLINEARFILTERKERNEL_H__ */