Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 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 | #include "arm_compute/runtime/CL/functions/CLLaplacianPyramid.h" |
| 25 | |
| 26 | #include "arm_compute/core/Error.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #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/CL/CLTensor.h" |
| 31 | #include "arm_compute/runtime/CL/functions/CLArithmeticSubtraction.h" |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 32 | #include "arm_compute/runtime/CL/functions/CLDepthConvertLayer.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 33 | #include "arm_compute/runtime/CL/functions/CLGaussian5x5.h" |
| 34 | #include "arm_compute/runtime/CL/functions/CLGaussianPyramid.h" |
Moritz Pflanzer | d0ae8b8 | 2017-06-29 14:51:57 +0100 | [diff] [blame] | 35 | #include "support/ToolchainSupport.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | |
| 37 | using namespace arm_compute; |
| 38 | |
Moritz Pflanzer | f4af76e | 2017-09-06 07:42:43 +0100 | [diff] [blame] | 39 | CLLaplacianPyramid::CLLaplacianPyramid() // NOLINT |
| 40 | : _num_levels(0), |
| 41 | _gaussian_pyr_function(), |
| 42 | _convf(), |
| 43 | _subf(), |
| 44 | _depth_function(), |
| 45 | _gauss_pyr(), |
| 46 | _conv_pyr() |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | { |
| 48 | } |
| 49 | |
| 50 | void CLLaplacianPyramid::configure(ICLTensor *input, CLPyramid *pyramid, ICLTensor *output, BorderMode border_mode, uint8_t constant_border_value) |
| 51 | { |
| 52 | ARM_COMPUTE_ERROR_ON(nullptr == pyramid); |
| 53 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8); |
| 54 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::S16); |
| 55 | ARM_COMPUTE_ERROR_ON(0 == pyramid->info()->num_levels()); |
| 56 | ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != pyramid->info()->width()); |
| 57 | ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != pyramid->info()->height()); |
| 58 | ARM_COMPUTE_ERROR_ON(output->info()->dimension(0) != pyramid->get_pyramid_level(pyramid->info()->num_levels() - 1)->info()->dimension(0)); |
| 59 | ARM_COMPUTE_ERROR_ON(output->info()->dimension(1) != pyramid->get_pyramid_level(pyramid->info()->num_levels() - 1)->info()->dimension(1)); |
| 60 | |
| 61 | _num_levels = pyramid->info()->num_levels(); |
| 62 | |
| 63 | // Create and initialize the gaussian pyramid and the convoluted pyramid |
| 64 | PyramidInfo pyramid_info; |
| 65 | pyramid_info.init(_num_levels, 0.5f, pyramid->info()->tensor_shape(), arm_compute::Format::U8); |
| 66 | |
| 67 | _gauss_pyr.init(pyramid_info); |
| 68 | _conv_pyr.init(pyramid_info); |
| 69 | |
| 70 | // Create Gaussian Pyramid function |
| 71 | _gaussian_pyr_function.configure(input, &_gauss_pyr, border_mode, constant_border_value); |
| 72 | |
Moritz Pflanzer | d0ae8b8 | 2017-06-29 14:51:57 +0100 | [diff] [blame] | 73 | _convf = arm_compute::support::cpp14::make_unique<CLGaussian5x5[]>(_num_levels); |
| 74 | _subf = arm_compute::support::cpp14::make_unique<CLArithmeticSubtraction[]>(_num_levels); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 75 | |
| 76 | for(unsigned int i = 0; i < _num_levels; ++i) |
| 77 | { |
| 78 | _convf[i].configure(_gauss_pyr.get_pyramid_level(i), _conv_pyr.get_pyramid_level(i), border_mode, constant_border_value); |
| 79 | _subf[i].configure(_gauss_pyr.get_pyramid_level(i), _conv_pyr.get_pyramid_level(i), pyramid->get_pyramid_level(i), ConvertPolicy::WRAP); |
| 80 | } |
| 81 | |
| 82 | _depth_function.configure(_conv_pyr.get_pyramid_level(_num_levels - 1), output, ConvertPolicy::WRAP, 0); |
| 83 | |
| 84 | _gauss_pyr.allocate(); |
| 85 | _conv_pyr.allocate(); |
| 86 | } |
| 87 | |
| 88 | void CLLaplacianPyramid::run() |
| 89 | { |
| 90 | ARM_COMPUTE_ERROR_ON_MSG(0 == _num_levels, "Unconfigured function"); |
| 91 | |
| 92 | _gaussian_pyr_function.run(); // compute gaussian pyramid |
| 93 | |
| 94 | for(unsigned int i = 0; i < _num_levels; ++i) |
| 95 | { |
| 96 | _convf[i].run(); // convolute gaussian pyramid |
| 97 | } |
| 98 | |
| 99 | for(unsigned int i = 0; i < _num_levels; ++i) |
| 100 | { |
| 101 | _subf[i].run(); // compute laplacian image |
| 102 | } |
| 103 | |
| 104 | _depth_function.run(); |
| 105 | } |