blob: 1979c5bd2b340cc0cb384f28aec45af71c3b1f57 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyrouf4643372019-11-29 16:17:13 +00002 * Copyright (c) 2016-2019 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_NECANNYEDGEKERNEL_H
25#define ARM_COMPUTE_NECANNYEDGEKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/NEON/INEKernel.h"
28
29#include <cstdint>
30
31namespace arm_compute
32{
33class ITensor;
34
35/** Computes magnitude and quantised phase from inputs gradients. */
36class NEGradientKernel : public INEKernel
37{
38public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000039 const char *name() const override
40 {
41 return "NEGradientKernel";
42 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043 /** Default constructor */
44 NEGradientKernel();
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 NEGradientKernel(const NEGradientKernel &) = delete;
47 /** Prevent instances of this class from being copied (As this class contains pointers) */
48 NEGradientKernel &operator=(const NEGradientKernel &) = delete;
49 /** Allow instances of this class to be moved */
50 NEGradientKernel(NEGradientKernel &&) = default;
51 /** Allow instances of this class to be moved */
52 NEGradientKernel &operator=(NEGradientKernel &&) = default;
53 /** Default destructor */
54 virtual ~NEGradientKernel() = default;
55
56 /** Initialise the kernel's sources, destinations and border mode.
57 *
58 * @note gx, gy and magnitude must all be the same size (either 16 or 32)
59 *
60 * @param[in] gx Source tensor - Gx component. Data type supported: S16/S32.
61 * @param[in] gy Source tensor - Gy component. Data type supported: same as @p gx.
62 * @param[out] magnitude Destination tensor - Magnitude. Data type supported: U16 (if the data type of @p gx is S16) / U32 (if the data type of @p gx is S32).
63 * @param[out] phase Destination tensor - Quantized phase. Data type supported: U8.
64 * @param[in] norm_type Normalization type. If 1, L1-Norm otherwise L2-Norm
65 */
66 virtual void configure(const ITensor *gx, const ITensor *gy, ITensor *magnitude, ITensor *phase, int32_t norm_type);
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
71protected:
72 /** Common signature for all the specialised gradient functions
73 *
74 * @param[in] gx_ptr Pointer to the first input tensor.
75 * @param[in] gy_ptr Pointer to the second input tensor.
76 * @param[out] magnitude_ptr Pointer to the first output tensor
77 * @param[out] phase_ptr Pointer to the second output tensor
78 */
79 using GradientFunction = void(const void *__restrict gx_ptr, const void *__restrict gy_ptr, void *__restrict magnitude_ptr, void *__restrict phase_ptr);
80
81 GradientFunction *_func; /**< Gradient function to use for the particular tensor types passed to configure() */
82 const ITensor *_gx; /**< Source tensor - Gx component */
83 const ITensor *_gy; /**< Source tensor - Gy component */
84 ITensor *_magnitude; /**< Destination tensor - Magnitude */
85 ITensor *_phase; /**< Destination tensor - Quantized phase */
86};
87
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088/** NEON kernel to perform Non-Maxima suppression for Canny Edge.
89 *
90 * @note This kernel is meant to be used alongside CannyEdge and performs a non-maxima suppression using magnitude and phase of input
91 * to characterize points as possible edges. Thus, at the end, each point will be set to EDGE, NO_EDGE or MAYBE.
92 *
93 * @note Hysteresis is computed in @ref NEEdgeTraceKernel
94 */
95class NEEdgeNonMaxSuppressionKernel : public INEKernel
96{
97public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000098 const char *name() const override
99 {
100 return "NEEdgeNonMaxSuppressionKernel";
101 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100102 /** Default constructor */
103 NEEdgeNonMaxSuppressionKernel();
104 /** Prevent instances of this class from being copied (As this class contains pointers) */
105 NEEdgeNonMaxSuppressionKernel(const NEEdgeNonMaxSuppressionKernel &) = delete;
106 /** Prevent instances of this class from being copied (As this class contains pointers) */
107 NEEdgeNonMaxSuppressionKernel &operator=(const NEEdgeNonMaxSuppressionKernel &) = delete;
108 /** Allow instances of this class to be moved */
109 NEEdgeNonMaxSuppressionKernel(NEEdgeNonMaxSuppressionKernel &&) = default;
110 /** Allow instances of this class to be moved */
111 NEEdgeNonMaxSuppressionKernel &operator=(NEEdgeNonMaxSuppressionKernel &&) = default;
112 /** Default destructor */
113 ~NEEdgeNonMaxSuppressionKernel() = default;
114
115 /** Initialise the kernel's sources, destination and border mode.
116 *
117 * @param[in] magnitude Source tensor - Magnitude. Data type supported: U16/U32.
118 * @param[in] phase Source tensor - Quantized phase. Data type supported: U8.
119 * @param[out] output Output tensor. Data type supported: U8. It will be filled with 0 for "no edge", 127 for "maybe", 255 for "edge"
120 * @param[in] upper_thr Upper threshold used for the hysteresis
121 * @param[in] lower_thr Lower threshold used for the hysteresis
122 * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant.
123 */
124 void configure(const ITensor *magnitude, const ITensor *phase, ITensor *output, int32_t upper_thr, int32_t lower_thr, bool border_undefined);
125
126 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100127 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100128 BorderSize border_size() const override;
129
130private:
131 /** Common signature for all the specialised non-maxima suppression functions
132 *
133 * @param[in] magnitude_ptr Pointer to the first input tensor.
134 * @param[in] phase_ptr Pointer to the second input tensor.
135 * @param[out] output_ptr Pointer to the output tensor
136 * @param[in] stride_mag Stride of the magnitude tensor
137 * @param[in] upper_thr Upper threshold used for the hysteresis
138 * @param[in] lower_thr Lower threshold used for the hysteresis
139 */
140 using EdgeNonMaxSupprFunction = void(const void *__restrict magnitude_ptr, const void *__restrict phase_ptr, void *__restrict output_ptr, const uint32_t stride_mag, const int32_t upper_thr,
141 const int32_t lower_thr);
142
143 EdgeNonMaxSupprFunction *_func; /**< Non-Maxima suppression function to use for the particular tensor types passed to configure() */
144 const ITensor *_magnitude; /**< Source tensor - Magnitude */
145 const ITensor *_phase; /**< Source tensor - Quantized phase */
146 ITensor *_output; /**< Destination tensor */
147 int32_t _lower_thr; /**< Lower threshold used for the hysteresis */
148 int32_t _upper_thr; /**< Upper threshold used for the hysteresis */
149};
150
151/** NEON kernel to perform Edge tracing */
152class NEEdgeTraceKernel : public INEKernel
153{
154public:
Anthony Barbiere8a49832018-01-18 10:04:05 +0000155 const char *name() const override
156 {
157 return "NEEdgeTraceKernel";
158 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100159 /** Default constructor */
160 NEEdgeTraceKernel();
161 /** Prevent instances of this class from being copied (As this class contains pointers) */
162 NEEdgeTraceKernel(const NEEdgeTraceKernel &) = delete;
163 /** Prevent instances of this class from being copied (As this class contains pointers) */
164 NEEdgeTraceKernel &operator=(const NEEdgeTraceKernel &) = delete;
165 /** Allow instances of this class to be moved */
166 NEEdgeTraceKernel(NEEdgeTraceKernel &&) = default;
167 /** Allow instances of this class to be moved */
168 NEEdgeTraceKernel &operator=(NEEdgeTraceKernel &&) = default;
169 /** Default constructor */
170 ~NEEdgeTraceKernel() = default;
171
172 /** Initialise the kernel's source, destination and border mode.
173 *
174 * @param[in,out] input Source tensor. Data type supported: U8. Must contain 0 for "no edge", 127 for "maybe", 255 for "edge"
175 * @param[in,out] output Destination tensor. Data type supported: U8. Must be initialized to 0 (No edge).
176 */
177 void configure(ITensor *input, ITensor *output);
178
179 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100180 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100181 BorderSize border_size() const override;
182 bool is_parallelisable() const override;
183
184private:
185 ITensor *_input; /**< Source tensor */
186 ITensor *_output; /**< Destination tensor */
187};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100188} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000189#endif /* ARM_COMPUTE_NECANNYEDGEKERNEL_H */