Compute Library
 21.02
NECannyEdge.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-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_NECANNYEDGE_H
25 #define ARM_COMPUTE_NECANNYEDGE_H
26 
27 #include "arm_compute/core/Types.h"
32 
33 #include <cstdint>
34 #include <memory>
35 
36 namespace arm_compute
37 {
38 class ITensor;
39 class NEGradientKernel;
40 class NEFillBorderKernel;
41 class NEEdgeNonMaxSuppressionKernel;
42 class NEEdgeTraceKernel;
43 
44 /** Basic function to execute canny edge on Neon. This function calls the following Neon kernels and functions:
45  *
46  * -# @ref NEFillBorderKernel (if border_mode == REPLICATE or border_mode == CONSTANT)
47  * -# @ref NESobel3x3 (if gradient_size == 3) or
48  * @ref NESobel5x5 (if gradient_size == 5) or
49  * @ref NESobel7x7 (if gradient_size == 7)
50  * -# @ref NEGradientKernel
51  * -# @ref NEEdgeNonMaxSuppressionKernel
52  * -# @ref NEEdgeTraceKernel
53  *
54  * @deprecated This function is deprecated and is intended to be removed in 21.05 release
55  *
56  *
57  */
58 class NECannyEdge : public IFunction
59 {
60 public:
61  /** Constructor
62  *
63  * Initialize Sobel kernel to nullptr.
64  *
65  * @param[in] memory_manager (Optional) Memory manager.
66  */
67  NECannyEdge(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
68  /** Prevent instances of this class from being copied (As this class contains pointers) */
69  NECannyEdge(const NECannyEdge &) = delete;
70  /** Prevent instances of this class from being copied (As this class contains pointers) */
71  NECannyEdge &operator=(const NECannyEdge &) = delete;
72  /** Default destructor */
73  ~NECannyEdge();
74  /** Initialise the function's source, destination, thresholds, gradient size, normalization type and border mode.
75  *
76  * @param[in, out] input Source tensor. Data type supported: U8. (Written to only for @p border_mode != UNDEFINED)
77  * @param[out] output Destination tensor. Data type supported: U8.
78  * @param[in] upper_thr Upper threhold used for the hysteresis
79  * @param[in] lower_thr Lower threshold used for the hysteresis.
80  * @param[in] gradient_size Gradient size (3, 5 or 7)
81  * @param[in] norm_type Normalization type. If 1, L1-Norm otherwise L2-Norm
82  * @param[in] border_mode Border mode to use for the convolution.
83  * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
84  */
85  void configure(ITensor *input, ITensor *output, int32_t upper_thr, int32_t lower_thr, int32_t gradient_size, int32_t norm_type, BorderMode border_mode, uint8_t constant_border_value = 0);
86 
87  // Inherited methods overridden:
88  void run() override;
89 
90 private:
91  MemoryGroup _memory_group; /**< Function's memory group */
92  std::unique_ptr<IFunction> _sobel; /**< Pointer to Sobel kernel */
93  std::unique_ptr<NEGradientKernel> _gradient; /**< Gradient kernel */
94  std::unique_ptr<NEEdgeNonMaxSuppressionKernel> _non_max_suppr; /**< Non-Maxima suppression kernel */
95  std::unique_ptr<NEEdgeTraceKernel> _edge_trace; /**< Edge tracing kernel */
96  std::unique_ptr<NEFillBorderKernel> _border_mag_gradient; /**< Fill border on magnitude tensor kernel */
97  std::unique_ptr<NEFillBorderKernel> _border_edge_trace; /**< Fill border before edge trace */
98  Tensor _gx; /**< Source tensor - Gx component */
99  Tensor _gy; /**< Source tensor - Gy component */
100  Tensor _magnitude; /**< Source tensor - Magnitude */
101  Tensor _phase; /**< Source tensor - Phase */
102  Tensor _nonmax; /**< Source tensor - Non-Maxima suppressed */
103  ITensor *_output; /**< Output tensor provided by the user. */
104 };
105 }
106 #endif /* ARM_COMPUTE_NECANNYEDGE_H */
BorderMode
Methods available to handle borders.
Definition: Types.h:265
Base class for all functions.
Definition: IFunction.h:30
NECannyEdge(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Constructor.
Definition: NECannyEdge.cpp:48
Interface for Neon tensor.
Definition: ITensor.h:36
void run() override
Run the kernels contained in the function.
Copyright (c) 2017-2021 Arm Limited.
void configure(ITensor *input, ITensor *output, int32_t upper_thr, int32_t lower_thr, int32_t gradient_size, int32_t norm_type, BorderMode border_mode, uint8_t constant_border_value=0)
Initialise the function&#39;s source, destination, thresholds, gradient size, normalization type and bord...
Definition: NECannyEdge.cpp:65
~NECannyEdge()
Default destructor.
Basic function to execute canny edge on Neon.
Definition: NECannyEdge.h:58
Basic implementation of the tensor interface.
Definition: Tensor.h:37
NECannyEdge & operator=(const NECannyEdge &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...