blob: 566847453b5cd9b2a30c4c2ad739b5eb5741ccda [file] [log] [blame]
John Richardson2d008a42018-03-22 13:48:41 +00001/*
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 "LaplacianPyramid.h"
25
26#include "tests/validation/reference/ArithmeticSubtraction.h"
27#include "tests/validation/reference/DepthConvertLayer.h"
28#include "tests/validation/reference/Gaussian5x5.h"
29#include "tests/validation/reference/GaussianPyramidHalf.h"
30
31namespace arm_compute
32{
33namespace test
34{
35namespace validation
36{
37namespace reference
38{
39template <typename T, typename U>
40std::vector<SimpleTensor<U>> laplacian_pyramid(const SimpleTensor<T> &src, SimpleTensor<U> &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value)
41{
42 std::vector<SimpleTensor<T>> pyramid_conv;
43 std::vector<SimpleTensor<U>> pyramid_dst;
44
45 // First, a Gaussian pyramid with SCALE_PYRAMID_HALF is created
46 std::vector<SimpleTensor<T>> gaussian_level_pyramid = reference::gaussian_pyramid_half(src, border_mode, constant_border_value, num_levels);
47
48 // For each level i, the corresponding image Ii is blurred with Gaussian 5x5
49 // filter, and the difference between the two images is the corresponding
50 // level Li of the Laplacian pyramid
51 for(size_t i = 0; i < num_levels; ++i)
52 {
53 const SimpleTensor<T> level_filtered = reference::gaussian5x5(gaussian_level_pyramid[i], border_mode, constant_border_value);
54 pyramid_conv.push_back(level_filtered);
55
56 const SimpleTensor<U> level_sub = reference::arithmetic_subtraction<T, T, U>(gaussian_level_pyramid[i], level_filtered, dst.data_type(), ConvertPolicy::WRAP);
57 pyramid_dst.push_back(level_sub);
58 }
59
60 // Return the lowest resolution image and the pyramid
61 dst = depth_convert<T, U>(pyramid_conv[num_levels - 1], DataType::S16, ConvertPolicy::WRAP, 0);
62
63 return pyramid_dst;
64}
65
66template std::vector<SimpleTensor<int16_t>> laplacian_pyramid(const SimpleTensor<uint8_t> &src, SimpleTensor<int16_t> &dst, size_t num_levels, BorderMode border_mode, uint8_t constant_border_value);
67} // namespace reference
68} // namespace validation
69} // namespace test
70} // namespace arm_compute