Compute Library
 21.02
NELaplacianPyramid.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2020 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  */
25 
26 #include "arm_compute/core/Error.h"
37 
38 namespace arm_compute
39 {
41 
43  : _num_levels(0),
44  _gaussian_pyr_function(),
45  _convf(),
46  _subf(),
47  _gauss_pyr(),
48  _conv_pyr(),
49  _depth_function()
50 {
51 }
52 
54 {
55  ARM_COMPUTE_ERROR_ON_MSG(0 == _num_levels, "Unconfigured function");
56 
57  // Compute Gaussian Pyramid
58  _gaussian_pyr_function.run();
59 
60  for(unsigned int i = 0; i < _num_levels; ++i)
61  {
62  // Apply Gaussian filter to gaussian pyramid image
63  _convf[i].run();
64  }
65 
66  for(unsigned int i = 0; i < _num_levels; ++i)
67  {
68  // Compute laplacian image
69  _subf[i].run();
70  }
71 
72  _depth_function.run();
73 }
74 
75 void NELaplacianPyramid::configure(const ITensor *input, IPyramid *pyramid, ITensor *output, BorderMode border_mode, uint8_t constant_border_value)
76 {
77  ARM_COMPUTE_ERROR_ON(nullptr == pyramid);
80  ARM_COMPUTE_ERROR_ON(0 == pyramid->info()->num_levels());
81  ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != pyramid->info()->width());
82  ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != pyramid->info()->height());
83  ARM_COMPUTE_ERROR_ON(output->info()->dimension(0) != pyramid->get_pyramid_level(pyramid->info()->num_levels() - 1)->info()->dimension(0));
84  ARM_COMPUTE_ERROR_ON(output->info()->dimension(1) != pyramid->get_pyramid_level(pyramid->info()->num_levels() - 1)->info()->dimension(1));
85 
86  _num_levels = pyramid->info()->num_levels();
87 
88  // Create and initialize the gaussian pyramid and the convoluted pyramid
89  PyramidInfo pyramid_info;
90  pyramid_info.init(_num_levels, 0.5f, pyramid->info()->tensor_shape(), arm_compute::Format::U8);
91 
92  _gauss_pyr.init(pyramid_info);
93  _conv_pyr.init(pyramid_info);
94 
95  // Create Gaussian Pyramid function
96  _gaussian_pyr_function.configure(input, &_gauss_pyr, border_mode, constant_border_value);
97 
98  _convf.resize(_num_levels);
99  _subf.resize(_num_levels);
100 
101  for(unsigned int i = 0; i < _num_levels; ++i)
102  {
103  _convf[i].configure(_gauss_pyr.get_pyramid_level(i), _conv_pyr.get_pyramid_level(i), border_mode, constant_border_value);
104  _subf[i].configure(_gauss_pyr.get_pyramid_level(i), _conv_pyr.get_pyramid_level(i), pyramid->get_pyramid_level(i), ConvertPolicy::WRAP);
105  }
106 
107  _depth_function.configure(_conv_pyr.get_pyramid_level(_num_levels - 1), output, ConvertPolicy::WRAP, 0);
108 
109  _gauss_pyr.allocate();
110  _conv_pyr.allocate();
111 }
112 } // namespace arm_compute
BorderMode
Methods available to handle borders.
Definition: Types.h:265
const TensorShape & tensor_shape() const
Return the TensorShape of the o-th level tensor.
Definition: PyramidInfo.cpp:92
virtual const PyramidInfo * info() const =0
Interface to be implemented by the child class to return the Pyramid&#39;s metadata.
void run() override final
Run the kernels contained in the function.
void configure(const ITensor *input, IPyramid *pyramid, BorderMode border_mode, uint8_t constant_border_value) override
Initialise the function&#39;s source, destinations and border mode.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
Tensor * get_pyramid_level(size_t index) const override
Retrieves a level of the pyramid as a ITensor pointer.
Definition: Pyramid.cpp:112
1 channel, 1 U8 per channel
void init(size_t num_levels, float scale, size_t width, size_t height, Format format)
Initialize pyramid&#39;s metadata for 2D tensors.
Definition: PyramidInfo.cpp:50
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Interface for Neon tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
void configure(const ITensor *input, IPyramid *pyramid, ITensor *output, BorderMode border_mode, uint8_t constant_border_value)
Initialise the function&#39;s source, destinations and border mode.
Interface for pyramid data-object.
Definition: IPyramid.h:36
virtual ITensor * get_pyramid_level(size_t index) const =0
Retrieves a level of the pyramid as a ITensor pointer.
void init(const PyramidInfo &info)
Initialize pyramid data-object using the given Pyramid&#39;s metadata.
Definition: Pyramid.cpp:35
void run() override
Run the kernels contained in the function.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
~NELaplacianPyramid()
Default destructor.
void allocate()
Allocate the planes in the pyramid.
Definition: Pyramid.cpp:99
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
Store the Pyramid&#39;s metadata.
Definition: PyramidInfo.h:35
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void configure(const ITensor *input, ITensor *output, ConvertPolicy policy, uint32_t shift=0)
Initialize the function&#39;s source, destination.
size_t width() const
Return the width of the 0th level tensor.
Definition: PyramidInfo.cpp:82
size_t num_levels() const
Return the number of the pyramid levels.
Definition: PyramidInfo.cpp:77
void run() override
Run the kernels contained in the function.
size_t height() const
Return the height of the 0th level tensor.
Definition: PyramidInfo.cpp:87