VisionCpp  0.0.1
OP_Median.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_Median.hpp
21 /// \brief It applies the median filter in an image. It gets the median value
22 /// of a neighbour after sorted
23 
24 namespace visioncpp {
25 /// \brief User defined functionality for the kernel
26 namespace custom {
27 template <typename T>
28 void bubbleSort(T &a, int N) {
29  bool swapp = true;
30  while (swapp) {
31  swapp = false;
32  for (size_t i = 0; i < N - 1; i++) {
33  if (a[i] > a[i + 1]) {
34  a[i] += a[i + 1];
35  a[i + 1] = a[i] - a[i + 1];
36  a[i] -= a[i + 1];
37  swapp = true;
38  }
39  }
40  }
41 }
42 }
43 
44 /// \brief This functor implements a median filter
45 struct OP_Median {
46  /// \brief This functor implements median filter
47  /// \param nbr - Input image
48  /// \return float - Returns the image with median filter applied
49  template <typename T>
50  T operator()(T nbr) {
51  int size = 5;
52  int bound = size / 2;
53  float v[25];
54  int k = 0;
55  for (int i = -bound; i <= bound; i++) {
56  for (int j = -bound; j <= bound; j++) {
57  v[k++] = nbr.at(nbr.I_c + i, nbr.I_r + j);
58  }
59  }
61  return v[size * size / 2];
62  }
63 };
64 }
void bubbleSort(T &a, int N)
Definition: OP_Median.hpp:28
VisionCpp namespace.
Definition: sycl/device.hpp:24
@ size
number of backends.
This functor implements a median filter.
Definition: OP_Median.hpp:45
T operator()(T nbr)
This functor implements median filter.
Definition: OP_Median.hpp:50