Compute Library
 19.08
CLLaplacianReconstruct Class Reference

Basic function to execute laplacian reconstruction. More...

#include <CLLaplacianReconstruct.h>

Collaboration diagram for CLLaplacianReconstruct:
[legend]

Public Member Functions

 CLLaplacianReconstruct ()
 Constructor. More...
 
void configure (const CLPyramid *pyramid, ICLTensor *input, ICLTensor *output, BorderMode border_mode, uint8_t constant_border_value)
 Initialise the function's source, destinations and border mode. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Detailed Description

Basic function to execute laplacian reconstruction.

This function calls the following OpenCL kernels and functions:

  1. CLArithmeticAddition
  2. CLScale
  3. CLDepthConvertLayer

This function reconstructs the original image from a Laplacian Image Pyramid.

The input image is added to the last level of the Laplacian pyramid L(n-2), the resulting image is upsampled to the resolution of the next pyramid level.

I(n-2) = upsample( input + L(n-1)

For each pyramid level i, except i=0 and i=n-1: I(i-1) = upsample(I(i) + L(i))

output = I(0) + L(0)

Definition at line 60 of file CLLaplacianReconstruct.h.

Constructor & Destructor Documentation

◆ CLLaplacianReconstruct()

Constructor.

Definition at line 37 of file CLLaplacianReconstruct.cpp.

38  : _tmp_pyr(),
39  _addf(),
40  _scalef(),
41  _depthf()
42 {
43 }

Member Function Documentation

◆ configure()

void configure ( const CLPyramid pyramid,
ICLTensor input,
ICLTensor output,
BorderMode  border_mode,
uint8_t  constant_border_value 
)

Initialise the function's source, destinations and border mode.

The Output image must have the same size as the first level of the pyramid. The Input image must have the same size as the last level of the pyramid.

The idea is to reconstuct the original hi-res image from a low-res representation of it and the laplacian pyramid.

Parameters
[in]pyramidLaplacian pyramid tensors, Data types supported at each level: S16.
[in]inputSource tensor. Data types supported: S16.
[out]outputOutput tensor. Data types supported: U8.
[in]border_modeBorder mode to use for the convolution.
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Definition at line 45 of file CLLaplacianReconstruct.cpp.

46 {
47  ARM_COMPUTE_ERROR_ON(nullptr == pyramid);
48  ARM_COMPUTE_ERROR_ON(input == output);
53  ARM_COMPUTE_ERROR_ON(output->info()->dimension(0) != pyramid->get_pyramid_level(0)->info()->dimension(0));
54  ARM_COMPUTE_ERROR_ON(output->info()->dimension(1) != pyramid->get_pyramid_level(0)->info()->dimension(1));
55  ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != pyramid->get_pyramid_level(pyramid->info()->num_levels() - 1)->info()->dimension(0));
56  ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != pyramid->get_pyramid_level(pyramid->info()->num_levels() - 1)->info()->dimension(1));
57 
58  const size_t num_levels = pyramid->info()->num_levels();
59 
60  // Create and initialize the tmp pyramid: I(n-2) = upsample( input + Laplace(n-1) )
61  PyramidInfo pyramid_info;
62  pyramid_info.init(num_levels, 0.5f, output->info()->tensor_shape(), arm_compute::Format::S16);
63  _tmp_pyr.init(pyramid_info);
64 
65  // Allocate add and scale functions. Level 0 does not need to be scaled.
66  _addf.resize(num_levels);
67  _scalef.resize(num_levels - 1);
68 
69  const size_t last_level = num_levels - 1;
70 
71  _addf[last_level].configure(input, pyramid->get_pyramid_level(last_level), _tmp_pyr.get_pyramid_level(last_level), ConvertPolicy::SATURATE);
72 
73  // Scale levels n-1 to 1, and add levels n-2 to 0
74  for(size_t l = 0; l < last_level; ++l)
75  {
76  _scalef[l].configure(_tmp_pyr.get_pyramid_level(l + 1), _tmp_pyr.get_pyramid_level(l), arm_compute::InterpolationPolicy::NEAREST_NEIGHBOR, border_mode, constant_border_value);
77  _addf[l].configure(_tmp_pyr.get_pyramid_level(l), pyramid->get_pyramid_level(l), _tmp_pyr.get_pyramid_level(l), ConvertPolicy::SATURATE);
78  }
79 
80  // Convert level 0 from S16 to U8
81  _depthf.configure(_tmp_pyr.get_pyramid_level(0), output, ConvertPolicy::SATURATE, 0);
82 
83  _tmp_pyr.allocate();
84 }
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
Definition: CLTensor.cpp:35
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
1 channel, 1 U8 per channel
size_t dimension(size_t index) const override
Return the size of the requested dimension.
Definition: TensorInfo.h:223
const PyramidInfo * info() const override
Interface to be implemented by the child class to return the Pyramid's metadata.
Definition: CLPyramid.cpp:118
void init(size_t num_levels, float scale, size_t width, size_t height, Format format)
Initialize pyramid'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:337
Output values are defined to match the source pixel whose center is nearest to the sample position.
size_t num_dimensions() const override
The number of dimensions of the tensor (rank)
Definition: TensorInfo.h:244
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void init(const PyramidInfo &info)
Initialize pyramid data-object using the given Pyramid's metadata.
Definition: CLPyramid.cpp:42
void allocate()
Allocate the planes in the pyramid.
Definition: CLPyramid.cpp:110
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
1 channel, 1 S16 per channel
void configure(const ICLTensor *input, ICLTensor *output, ConvertPolicy policy, uint32_t shift)
Initialize the function's source, destination.
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
Store the Pyramid's metadata.
Definition: PyramidInfo.h:35
CLTensor * get_pyramid_level(size_t index) const override
Retrieves a level of the pyramid as a ITensor pointer.
Definition: CLPyramid.cpp:123
size_t num_levels() const
Return the number of the pyramid levels.
Definition: PyramidInfo.cpp:77

References CLPyramid::allocate(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, arm_compute::test::validation::border_mode, CLDepthConvertLayer::configure(), ITensorInfo::dimension(), TensorInfo::dimension(), CLPyramid::get_pyramid_level(), ITensor::info(), CLTensor::info(), CLPyramid::info(), arm_compute::test::validation::info, CLPyramid::init(), PyramidInfo::init(), arm_compute::NEAREST_NEIGHBOR, ITensorInfo::num_dimensions(), TensorInfo::num_dimensions(), PyramidInfo::num_levels(), arm_compute::S16, arm_compute::SATURATE, ITensorInfo::tensor_shape(), and arm_compute::U8.

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For NEON kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 86 of file CLLaplacianReconstruct.cpp.

87 {
88  ARM_COMPUTE_ERROR_ON_MSG(_addf.empty(), "Unconfigured function");
89 
90  const size_t last_level = _tmp_pyr.info()->num_levels() - 1;
91 
92  _addf[last_level].run();
93 
94  // Run l = [last_level - 1, 0]
95  for(size_t l = last_level; l-- > 0;)
96  {
97  _scalef[l].run();
98  _addf[l].run();
99  }
100 
101  _depthf.run();
102 }
const PyramidInfo * info() const override
Interface to be implemented by the child class to return the Pyramid's metadata.
Definition: CLPyramid.cpp:118
void run() override final
Run the kernels contained in the function.
size_t num_levels() const
Return the number of the pyramid levels.
Definition: PyramidInfo.cpp:77
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328

References ARM_COMPUTE_ERROR_ON_MSG, CLPyramid::info(), PyramidInfo::num_levels(), and ICLSimpleFunction::run().


The documentation for this class was generated from the following files: