blob: 4f0639b64bc6925d0a587f9e6f31363a5f5d5936 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016-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 */
24#include "arm_compute/runtime/NEON/functions/NELaplacianPyramid.h"
25
26#include "arm_compute/core/Error.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "arm_compute/core/IPyramid.h"
28#include "arm_compute/core/TensorInfo.h"
29#include "arm_compute/core/Validate.h"
30#include "arm_compute/runtime/NEON/functions/NEArithmeticSubtraction.h"
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000031#include "arm_compute/runtime/NEON/functions/NEDepthConvertLayer.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032#include "arm_compute/runtime/NEON/functions/NEGaussian5x5.h"
33#include "arm_compute/runtime/NEON/functions/NEGaussianPyramid.h"
34#include "arm_compute/runtime/Tensor.h"
35
36using namespace arm_compute;
37
Moritz Pflanzerf4af76e2017-09-06 07:42:43 +010038NELaplacianPyramid::NELaplacianPyramid() // NOLINT
39 : _num_levels(0),
40 _gaussian_pyr_function(),
41 _convf(),
42 _subf(),
43 _gauss_pyr(),
44 _conv_pyr(),
45 _depth_function()
Anthony Barbier6ff3b192017-09-04 18:44:23 +010046{
47}
48
49void NELaplacianPyramid::run()
50{
51 ARM_COMPUTE_ERROR_ON_MSG(0 == _num_levels, "Unconfigured function");
52
53 // Compute Gaussian Pyramid
54 _gaussian_pyr_function.run();
55
56 for(unsigned int i = 0; i < _num_levels; ++i)
57 {
58 // Apply Gaussian filter to gaussian pyramid image
59 _convf[i].run();
60 }
61
62 for(unsigned int i = 0; i < _num_levels; ++i)
63 {
64 // Compute laplacian image
65 _subf[i].run();
66 }
67
68 _depth_function.run();
69}
70
71void NELaplacianPyramid::configure(const ITensor *input, IPyramid *pyramid, ITensor *output, BorderMode border_mode, uint8_t constant_border_value)
72{
73 ARM_COMPUTE_ERROR_ON(nullptr == pyramid);
74 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
75 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::S16);
76 ARM_COMPUTE_ERROR_ON(0 == pyramid->info()->num_levels());
77 ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != pyramid->info()->width());
78 ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != pyramid->info()->height());
79 ARM_COMPUTE_ERROR_ON(output->info()->dimension(0) != pyramid->get_pyramid_level(pyramid->info()->num_levels() - 1)->info()->dimension(0));
80 ARM_COMPUTE_ERROR_ON(output->info()->dimension(1) != pyramid->get_pyramid_level(pyramid->info()->num_levels() - 1)->info()->dimension(1));
81
82 _num_levels = pyramid->info()->num_levels();
83
84 // Create and initialize the gaussian pyramid and the convoluted pyramid
85 PyramidInfo pyramid_info;
86 pyramid_info.init(_num_levels, 0.5f, pyramid->info()->tensor_shape(), arm_compute::Format::U8);
87
88 _gauss_pyr.init(pyramid_info);
89 _conv_pyr.init(pyramid_info);
90
91 // Create Gaussian Pyramid function
92 _gaussian_pyr_function.configure(input, &_gauss_pyr, border_mode, constant_border_value);
93
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010094 _convf.resize(_num_levels);
95 _subf.resize(_num_levels);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096
97 for(unsigned int i = 0; i < _num_levels; ++i)
98 {
99 _convf[i].configure(_gauss_pyr.get_pyramid_level(i), _conv_pyr.get_pyramid_level(i), border_mode, constant_border_value);
100 _subf[i].configure(_gauss_pyr.get_pyramid_level(i), _conv_pyr.get_pyramid_level(i), pyramid->get_pyramid_level(i), ConvertPolicy::WRAP);
101 }
102
103 _depth_function.configure(_conv_pyr.get_pyramid_level(_num_levels - 1), output, ConvertPolicy::WRAP, 0);
104
105 _gauss_pyr.allocate();
106 _conv_pyr.allocate();
107}