VisionCpp  0.0.1
OP_Filter2D.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_Filter2D.hpp
21 /// \brief This file apply the general convolution
22 
23 namespace visioncpp {
24 /// \struct OP_Filter2D
25 /// \brief Applying the general convolution for 3 channel Image.
26 /// If the number of channel is different in your case feel free to write your
27 /// own.
28 struct OP_Filter2D {
29  /// \param nbr
30  /// \param fltr
31  /// \return NeighbourT::PixelType
32  template <typename NeighbourT, typename FilterT>
33  typename NeighbourT::PixelType operator()(NeighbourT& nbr, FilterT& fltr) {
34  int i, i2, j, j2;
35  int hs_c = (fltr.cols / 2);
36  int hs_r = (fltr.rows / 2);
37  typename NeighbourT::PixelType out{};
38  for (i2 = -hs_c, i = 0; i2 <= hs_c; i2++, i++)
39  for (j2 = -hs_r, j = 0; j2 <= hs_r; j2++, j++)
40  out += nbr.at(nbr.I_c + i2, nbr.I_r + j2) * fltr.at(i, j);
41  return out;
42  }
43 };
44 
45 /// \struct OP_Filter2D_One
46 /// \brief Applying the general convolution for 1 channel Image.
47 /// If the number of channel is different in your case feel free to write your
48 /// own.
50  /// \param nbr
51  /// \param fltr
52  /// \return float
53  template <typename NeighbourT, typename FilterT>
54  float operator()(NeighbourT& nbr, FilterT& fltr) {
55  int i, i2, j, j2;
56  int hs_c = (fltr.cols / 2);
57  int hs_r = (fltr.rows / 2);
58  float out = 0;
59  for (i2 = -hs_c, i = 0; i2 <= hs_c; i2++, i++)
60  for (j2 = -hs_r, j = 0; j2 <= hs_r; j2++, j++)
61  out += (nbr.at(nbr.I_c + i2, nbr.I_r + j2) * fltr.at(i, j));
62  return out;
63  }
64 };
65 }
VisionCpp namespace.
Definition: sycl/device.hpp:24
Applying the general convolution for 1 channel Image.
Definition: OP_Filter2D.hpp:49
float operator()(NeighbourT &nbr, FilterT &fltr)
Definition: OP_Filter2D.hpp:54
Applying the general convolution for 3 channel Image.
Definition: OP_Filter2D.hpp:28
NeighbourT::PixelType operator()(NeighbourT &nbr, FilterT &fltr)
Definition: OP_Filter2D.hpp:33