From 7655a67384895868c0afa72bfda9a9b2fcfdf323 Mon Sep 17 00:00:00 2001 From: Moritz Pflanzer Date: Sat, 23 Sep 2017 11:57:33 +0100 Subject: COMPMID-507: Move Sobel to new validation Change-Id: Ic0a9dbd8e646abbf8d9ea52e497a5fe60e499cc7 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/88883 Tested-by: Kaizen Reviewed-by: Anthony Barbier --- tests/validation/CPP/Utils.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'tests/validation/CPP/Utils.h') diff --git a/tests/validation/CPP/Utils.h b/tests/validation/CPP/Utils.h index 557d85f204..2d879c129b 100644 --- a/tests/validation/CPP/Utils.h +++ b/tests/validation/CPP/Utils.h @@ -47,9 +47,34 @@ T tensor_elem_at(const SimpleTensor &in, Coordinates coord, BorderMode border template T bilinear_policy(const SimpleTensor &in, Coordinates id, float xn, float yn, BorderMode border_mode, T constant_border_value); -template -void apply_2d_spatial_filter(Coordinates coord, const SimpleTensor &in, SimpleTensor &out, const TensorShape &filter_shape, const T2 *filter_itr, float scale, BorderMode border_mode, - T1 constant_border_value = 0); +/* Apply 2D spatial filter on a single element of @p in at coordinates @p coord + * + * - filter sizes have to be odd number + * - Row major order of filter assumed + * - TO_ZERO rounding policy assumed + * - SATURATE convert policy assumed + */ +template +void apply_2d_spatial_filter(Coordinates coord, const SimpleTensor &src, SimpleTensor &dst, const TensorShape &filter_shape, const V *filter_itr, double scale, BorderMode border_mode, + T constant_border_value = T(0)) +{ + double val = 0.; + const int x = coord.x(); + const int y = coord.y(); + for(int j = y - static_cast(filter_shape[1] / 2); j <= y + static_cast(filter_shape[1] / 2); ++j) + { + for(int i = x - static_cast(filter_shape[0] / 2); i <= x + static_cast(filter_shape[0] / 2); ++i) + { + coord.set(0, i); + coord.set(1, j); + val += static_cast(*filter_itr) * tensor_elem_at(src, coord, border_mode, constant_border_value); + ++filter_itr; + } + } + coord.set(0, x); + coord.set(1, y); + dst[coord2index(src.shape(), coord)] = saturate_cast(support::cpp11::trunc(val * scale)); +} RawTensor transpose(const RawTensor &src, int chunk_width = 1); } // namespace validation -- cgit v1.2.1