blob: ef14355bc89211c878aa2047df60feeb4ca9777e [file] [log] [blame]
John Richardson417d14f2018-05-22 17:14:50 +01001/*
2 * Copyright (c) 2018 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 "LaplacianReconstruct.h"
25
26#include "arm_compute/core/Types.h"
Georgios Pinitascbf39c62018-09-10 15:07:45 +010027#include "tests/validation/reference/ArithmeticOperations.h"
John Richardson417d14f2018-05-22 17:14:50 +010028#include "tests/validation/reference/DepthConvertLayer.h"
29#include "tests/validation/reference/Scale.h"
30
31namespace arm_compute
32{
33namespace test
34{
35namespace validation
36{
37namespace reference
38{
39template <typename T, typename U>
40SimpleTensor<U> laplacian_reconstruct(const std::vector<SimpleTensor<T>> &pyramid, const SimpleTensor<T> &low_res, BorderMode border_mode, T constant_border_value)
41{
42 std::vector<SimpleTensor<T>> tmp_pyramid(pyramid);
43
44 const size_t last_level = pyramid.size() - 1;
45 const DataType data_type = low_res.data_type();
46
47 // input + L(n-1)
Georgios Pinitascbf39c62018-09-10 15:07:45 +010048 tmp_pyramid[last_level] = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, low_res, pyramid[last_level], data_type, ConvertPolicy::SATURATE);
John Richardson417d14f2018-05-22 17:14:50 +010049
50 // Scale levels n-1 to 1, and add levels n-2 to 0
51 for(size_t i = last_level; i-- > 0;)
52 {
53 const float scale_x = static_cast<float>(tmp_pyramid[i].shape().x()) / tmp_pyramid[i + 1].shape().x();
54 const float scale_y = static_cast<float>(tmp_pyramid[i].shape().y()) / tmp_pyramid[i + 1].shape().y();
55
56 tmp_pyramid[i] = reference::scale(tmp_pyramid[i + 1], scale_x, scale_y, InterpolationPolicy::NEAREST_NEIGHBOR,
57 border_mode, constant_border_value, SamplingPolicy::CENTER, false);
58
Georgios Pinitascbf39c62018-09-10 15:07:45 +010059 tmp_pyramid[i] = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, tmp_pyramid[i], pyramid[i], data_type, ConvertPolicy::SATURATE);
John Richardson417d14f2018-05-22 17:14:50 +010060 }
61
62 return reference::depth_convert<T, U>(tmp_pyramid[0], DataType::U8, ConvertPolicy::SATURATE, 0);
63}
64
65template SimpleTensor<uint8_t> laplacian_reconstruct(const std::vector<SimpleTensor<int16_t>> &pyramid, const SimpleTensor<int16_t> &low_res, BorderMode border_mode, int16_t constant_border_value);
66} // namespace reference
67} // namespace validation
68} // namespace test
69} // namespace arm_compute