John Richardson | 417d14f | 2018-05-22 17:14:50 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018 Arm Limited. |
John Richardson | 417d14f | 2018-05-22 17:14:50 +0100 | [diff] [blame] | 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 Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 27 | #include "tests/validation/reference/ArithmeticOperations.h" |
John Richardson | 417d14f | 2018-05-22 17:14:50 +0100 | [diff] [blame] | 28 | #include "tests/validation/reference/DepthConvertLayer.h" |
| 29 | #include "tests/validation/reference/Scale.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace test |
| 34 | { |
| 35 | namespace validation |
| 36 | { |
| 37 | namespace reference |
| 38 | { |
| 39 | template <typename T, typename U> |
| 40 | SimpleTensor<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 Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 48 | tmp_pyramid[last_level] = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, low_res, pyramid[last_level], data_type, ConvertPolicy::SATURATE); |
John Richardson | 417d14f | 2018-05-22 17:14:50 +0100 | [diff] [blame] | 49 | |
| 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 Pinitas | cbf39c6 | 2018-09-10 15:07:45 +0100 | [diff] [blame] | 59 | tmp_pyramid[i] = reference::arithmetic_operation(reference::ArithmeticOperation::ADD, tmp_pyramid[i], pyramid[i], data_type, ConvertPolicy::SATURATE); |
John Richardson | 417d14f | 2018-05-22 17:14:50 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | return reference::depth_convert<T, U>(tmp_pyramid[0], DataType::U8, ConvertPolicy::SATURATE, 0); |
| 63 | } |
| 64 | |
| 65 | template 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 |