blob: b08646de0d463ead5175fd79471dd3645a630dab [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyrouebcebf12020-10-21 00:04:14 +01002 * Copyright (c) 2017-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_NECANNYEDGE_H
25#define ARM_COMPUTE_NECANNYEDGE_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/Types.h"
28#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas658039b2017-09-15 16:30:50 +010029#include "arm_compute/runtime/IMemoryManager.h"
30#include "arm_compute/runtime/MemoryGroup.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include "arm_compute/runtime/Tensor.h"
32
33#include <cstdint>
34#include <memory>
35
36namespace arm_compute
37{
38class ITensor;
Michalis Spyrouebcebf12020-10-21 00:04:14 +010039class NEGradientKernel;
40class NEFillBorderKernel;
41class NEEdgeNonMaxSuppressionKernel;
42class NEEdgeTraceKernel;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010043
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 */
55class NECannyEdge : public IFunction
56{
57public:
58 /** Constructor
59 *
60 * Initialize Sobel kernel to nullptr.
Alex Gildayc357c472018-03-21 13:54:09 +000061 *
62 * @param[in] memory_manager (Optional) Memory manager.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063 */
Georgios Pinitas658039b2017-09-15 16:30:50 +010064 NECannyEdge(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065 /** Prevent instances of this class from being copied (As this class contains pointers) */
66 NECannyEdge(const NECannyEdge &) = delete;
67 /** Prevent instances of this class from being copied (As this class contains pointers) */
68 NECannyEdge &operator=(const NECannyEdge &) = delete;
Michalis Spyrouebcebf12020-10-21 00:04:14 +010069 /** Default destructor */
70 ~NECannyEdge();
Anthony Barbier6ff3b192017-09-04 18:44:23 +010071 /** Initialise the function's source, destination, thresholds, gradient size, normalization type and border mode.
72 *
73 * @param[in, out] input Source tensor. Data type supported: U8. (Written to only for @p border_mode != UNDEFINED)
74 * @param[out] output Destination tensor. Data type supported: U8.
75 * @param[in] upper_thr Upper threhold used for the hysteresis
76 * @param[in] lower_thr Lower threshold used for the hysteresis.
77 * @param[in] gradient_size Gradient size (3, 5 or 7)
78 * @param[in] norm_type Normalization type. If 1, L1-Norm otherwise L2-Norm
79 * @param[in] border_mode Border mode to use for the convolution.
80 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010081 */
Georgios Pinitas09d34512018-08-30 16:02:11 +010082 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);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010083
84 // Inherited methods overridden:
85 void run() override;
86
87private:
Michalis Spyrouebcebf12020-10-21 00:04:14 +010088 MemoryGroup _memory_group; /**< Function's memory group */
89 std::unique_ptr<IFunction> _sobel; /**< Pointer to Sobel kernel */
90 std::unique_ptr<NEGradientKernel> _gradient; /**< Gradient kernel */
91 std::unique_ptr<NEEdgeNonMaxSuppressionKernel> _non_max_suppr; /**< Non-Maxima suppression kernel */
92 std::unique_ptr<NEEdgeTraceKernel> _edge_trace; /**< Edge tracing kernel */
93 std::unique_ptr<NEFillBorderKernel> _border_mag_gradient; /**< Fill border on magnitude tensor kernel */
94 std::unique_ptr<NEFillBorderKernel> _border_edge_trace; /**< Fill border before edge trace */
95 Tensor _gx; /**< Source tensor - Gx component */
96 Tensor _gy; /**< Source tensor - Gy component */
97 Tensor _magnitude; /**< Source tensor - Magnitude */
98 Tensor _phase; /**< Source tensor - Phase */
99 Tensor _nonmax; /**< Source tensor - Non-Maxima suppressed */
100 ITensor *_output; /**< Output tensor provided by the user. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100101};
102}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000103#endif /* ARM_COMPUTE_NECANNYEDGE_H */