Compute Library
 21.02
NECannyEdgeKernel.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2021 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_NECANNYEDGEKERNEL_H
25 #define ARM_COMPUTE_NECANNYEDGEKERNEL_H
26 
28 
29 #include <cstdint>
30 
31 namespace arm_compute
32 {
33 class ITensor;
34 
35 /** Computes magnitude and quantised phase from inputs gradients. */
37 {
38 public:
39  const char *name() const override
40  {
41  return "NEGradientKernel";
42  }
43  /** Default constructor */
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 */
53  /** Default destructor */
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:
69  void run(const Window &window, const ThreadInfo &info) override;
70 
71 protected:
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 
88 /** 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  */
96 {
97 public:
98  const char *name() const override
99  {
100  return "NEEdgeNonMaxSuppressionKernel";
101  }
102  /** Default constructor */
104  /** Prevent instances of this class from being copied (As this class contains pointers) */
106  /** Prevent instances of this class from being copied (As this class contains pointers) */
108  /** Allow instances of this class to be moved */
110  /** Allow instances of this class to be moved */
112  /** Default destructor */
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:
127  void run(const Window &window, const ThreadInfo &info) override;
128  BorderSize border_size() const override;
129 
130 private:
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 */
153 {
154 public:
155  const char *name() const override
156  {
157  return "NEEdgeTraceKernel";
158  }
159  /** Default constructor */
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 */
169  /** Default destructor */
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:
180  void run(const Window &window, const ThreadInfo &info) override;
181  BorderSize border_size() const override;
182  bool is_parallelisable() const override;
183 
184 private:
185  ITensor *_input; /**< Source tensor */
186  ITensor *_output; /**< Destination tensor */
187 };
188 } // namespace arm_compute
189 #endif /* ARM_COMPUTE_NECANNYEDGEKERNEL_H */
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
NEGradientKernel & operator=(const NEGradientKernel &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
Computes magnitude and quantised phase from inputs gradients.
Container for 2D border size.
Definition: Types.h:273
Common interface for all kernels implemented in C++.
Definition: ICPPKernel.h:38
const char * name() const override
Name of the kernel.
SimpleTensor< uint8_t > phase(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, PhaseType phase_type)
Definition: Phase.cpp:35
Interface for Neon tensor.
Definition: ITensor.h:36
Neon kernel to perform Edge tracing.
Copyright (c) 2017-2021 Arm Limited.
virtual void configure(const ITensor *gx, const ITensor *gy, ITensor *magnitude, ITensor *phase, int32_t norm_type)
Initialise the kernel&#39;s sources, destinations and border mode.
Neon kernel to perform Non-Maxima suppression for Canny Edge.
virtual bool is_parallelisable() const
Indicates whether or not the kernel is parallelisable.
Definition: IKernel.cpp:41
const char * name() const override
Name of the kernel.
~NEGradientKernel()
Default destructor.
const char * name() const override
Name of the kernel.
virtual BorderSize border_size() const
The size of the border for that kernel.
Definition: IKernel.cpp:46
NEGradientKernel()
Default constructor.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
Information about executing thread and CPU.
Definition: CPPTypes.h:235
Describe a multidimensional execution window.
Definition: Window.h:39
SimpleTensor< T > magnitude(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, MagnitudeType magnitude_type)
Definition: Magnitude.cpp:35