VisionCpp  0.0.1
OP_SepFilter.hpp
Go to the documentation of this file.
1 // This file is part of VisionCpp, a lightweight C++ template library
2 // for computer vision and image processing.
3 //
4 // Copyright (C) 2016 Codeplay Software Limited. All Rights Reserved.
5 //
6 // Contact: visioncpp@codeplay.com
7 //
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 //
12 // http://www.apache.org/licenses/LICENSE-2.0
13 //
14 // Unless required by applicable law or agreed to in writing, software
15 // distributed under the License is distributed on an "AS IS" BASIS,
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 // See the License for the specific language governing permissions and
18 // limitations under the License.
19 
20 /// \file OP_SepFilter.hpp
21 /// \brief This file applies Separable filter convolution
22 
23 namespace visioncpp {
24 /// \struct OP_SepFilterRow
25 /// \brief Separable filter for rows.
26 /// If the number of channel is different in your case feel free to write your
27 /// own.
29  /// \param nbr - where NeighbourT is pixel type
30  /// \param fltr - filter array
31  /// \return NeighbourT::PixelType
32  template <typename NeighbourT, typename FilterT>
33  typename NeighbourT::PixelType operator()(NeighbourT& nbr, FilterT& fltr) {
34  int i, i2;
35  int hs_r = (fltr.rows / 2);
36  auto out = nbr.at(nbr.I_c, nbr.I_r - 1) * fltr.at(0, 0);
37  for (i2 = -hs_r + 1, i = 1; i2 <= hs_r; i2++, i++) {
38  out += nbr.at(nbr.I_c, nbr.I_r + i2) * fltr.at(0, i);
39  }
40  return out;
41  }
42 };
43 
44 /// \struct OP_SepFilterCol
45 /// \brief Separable filter for cols.
47  /// \param nbr - where NeighbourT is pixel type
48  /// \param fltr - filter array
49  /// \return NeighbourT::PixelType
50  template <typename NeighbourT, typename FilterT>
51  typename NeighbourT::PixelType operator()(NeighbourT& nbr, FilterT& fltr) {
52  int i, i2;
53  int hs_c = (fltr.cols / 2);
54  auto out = nbr.at(nbr.I_c - 1, nbr.I_r) * fltr.at(0, 0);
55  for (i2 = -hs_c + 1, i = 1; i2 <= hs_c; i2++, i++) {
56  out += nbr.at(nbr.I_c + i2, nbr.I_r) * fltr.at(i, 0);
57  }
58  return out;
59  }
60 };
61 }
VisionCpp namespace.
Definition: sycl/device.hpp:24
Separable filter for cols.
NeighbourT::PixelType operator()(NeighbourT &nbr, FilterT &fltr)
Separable filter for rows.
NeighbourT::PixelType operator()(NeighbourT &nbr, FilterT &fltr)