blob: b7e0ffbcf1d0dba7eca7b8a64f6f97eb8321718d [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 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_NECANNYEDGE_H__
25#define __ARM_COMPUTE_NECANNYEDGE_H__
26
27#include "arm_compute/core/NEON/kernels/NECannyEdgeKernel.h"
28#include "arm_compute/core/NEON/kernels/NEFillBorderKernel.h"
29#include "arm_compute/core/Types.h"
30#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas658039b2017-09-15 16:30:50 +010031#include "arm_compute/runtime/IMemoryManager.h"
32#include "arm_compute/runtime/MemoryGroup.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033#include "arm_compute/runtime/Tensor.h"
34
35#include <cstdint>
36#include <memory>
37
38namespace arm_compute
39{
40class ITensor;
41
42/** Basic function to execute canny edge on NEON. This function calls the following NEON kernels and functions:
43 *
44 * -# @ref NEFillBorderKernel (if border_mode == REPLICATE or border_mode == CONSTANT)
45 * -# @ref NESobel3x3 (if gradient_size == 3) or
46 * @ref NESobel5x5 (if gradient_size == 5) or
47 * @ref NESobel7x7 (if gradient_size == 7)
48 * -# @ref NEGradientKernel
49 * -# @ref NEEdgeNonMaxSuppressionKernel
50 * -# @ref NEEdgeTraceKernel
51 *
52 */
53class NECannyEdge : public IFunction
54{
55public:
56 /** Constructor
57 *
58 * Initialize Sobel kernel to nullptr.
59 */
Georgios Pinitas658039b2017-09-15 16:30:50 +010060 NECannyEdge(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010061 /** Prevent instances of this class from being copied (As this class contains pointers) */
62 NECannyEdge(const NECannyEdge &) = delete;
63 /** Prevent instances of this class from being copied (As this class contains pointers) */
64 NECannyEdge &operator=(const NECannyEdge &) = delete;
65 /** Initialise the function's source, destination, thresholds, gradient size, normalization type and border mode.
66 *
67 * @param[in, out] input Source tensor. Data type supported: U8. (Written to only for @p border_mode != UNDEFINED)
68 * @param[out] output Destination tensor. Data type supported: U8.
69 * @param[in] upper_thr Upper threhold used for the hysteresis
70 * @param[in] lower_thr Lower threshold used for the hysteresis.
71 * @param[in] gradient_size Gradient size (3, 5 or 7)
72 * @param[in] norm_type Normalization type. If 1, L1-Norm otherwise L2-Norm
73 * @param[in] border_mode Border mode to use for the convolution.
74 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
75 * @param[in] use_fp16 (Optional) If true the FP16 kernels will be used. If false F32 kernels are used.
76 *
77 */
78 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,
79 bool use_fp16 = false);
80
81 // Inherited methods overridden:
82 void run() override;
83
84private:
Georgios Pinitas658039b2017-09-15 16:30:50 +010085 MemoryGroup _memory_group; /**< Function's memory group */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086 std::unique_ptr<IFunction> _sobel; /**< Pointer to Sobel kernel */
87 std::unique_ptr<INEKernel> _gradient; /**< Gradient kernel */
88 NEEdgeNonMaxSuppressionKernel _non_max_suppr; /**< Non-Maxima suppression kernel */
89 NEEdgeTraceKernel _edge_trace; /**< Edge tracing kernel */
90 NEFillBorderKernel _border_mag_gradient; /**< Fill border on magnitude tensor kernel */
91 NEFillBorderKernel _border_edge_trace; /**< Fill border before edge trace */
92 Tensor _gx; /**< Source tensor - Gx component */
93 Tensor _gy; /**< Source tensor - Gy component */
94 Tensor _magnitude; /**< Source tensor - Magnitude */
95 Tensor _phase; /**< Source tensor - Phase */
96 Tensor _nonmax; /**< Source tensor - Non-Maxima suppressed */
97 ITensor *_output; /**< Output tensor provided by the user. */
98};
99}
100#endif /* __ARM_COMPUTE_NECANNYEDGE_H */