VisionCpp  0.0.1
OP_AniDiff.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_AniDiff.hpp
21 /// \brief It applies a simplified version of the anisotropic diffusion
22 
23 namespace visioncpp {
24 /// \brief This functor applies anisotropic diffusion for one channel
26  /// \brief This functor applies a simplified version of the anisotropic
27  /// diffusion for one channel
28  /// \param nbr - An image with one channel
29  /// \return float - Return the anisotropic diffusion in one channel
30  template <typename T>
31  float operator()(T nbr) {
32  float out = 0;
33  float sum_w = 0;
34 
35  for (int i = -1; i <= 1; i++) {
36  for (int j = -1; j <= 1; j++) {
37  float w =
38  exp((-30.0f) * cl::sycl::fabs(nbr.at(nbr.I_c, nbr.I_r) -
39  nbr.at(nbr.I_c + i, nbr.I_r + j)));
40  sum_w += w;
41  out += w * nbr.at(nbr.I_c + i, nbr.I_r + j);
42  }
43  }
44  return out / sum_w;
45  }
46 };
47 
48 /// \brief This functor applies anisotropic diffusion for 3 channels
49 struct OP_AniDiff {
50  /// \brief This functor applies a simplified version of the anisotropic
51  /// diffusion for 3 channels
52  /// \param nbr - An image with three channels
53  /// \return float - Returns the anisotropic diffusion in 3 channels
54  template <typename T>
55  typename T::PixelType operator()(T nbr) {
56  using Type = typename T::PixelType::data_type;
57 
58  cl::sycl::float4 out(0, 0, 0, 0);
59  cl::sycl::float4 sum_w(0, 0, 0, 0);
60 
61  for (int i = -1; i <= 1; i++) {
62  for (int j = -1; j <= 1; j++) {
63  cl::sycl::float4 p1(nbr.at(nbr.I_c, nbr.I_r)[0],
64  nbr.at(nbr.I_c, nbr.I_r)[1],
65  nbr.at(nbr.I_c, nbr.I_r)[2], 0);
66  cl::sycl::float4 p2(nbr.at(nbr.I_c + i, nbr.I_r + j)[0],
67  nbr.at(nbr.I_c + i, nbr.I_r + j)[1],
68  nbr.at(nbr.I_c + i, nbr.I_r + j)[2], 0);
69  cl::sycl::float4 w = exp((-30.0f) * cl::sycl::fabs(p1 - p2));
70  sum_w += w;
71  out += w * p2;
72  }
73  }
74  out = out / sum_w;
75  return typename T::PixelType(static_cast<Type>(out.x()),
76  static_cast<Type>(out.y()),
77  static_cast<Type>(out.z()));
78  }
79 };
80 }
VisionCpp namespace.
Definition: sycl/device.hpp:24
This functor applies anisotropic diffusion for one channel.
Definition: OP_AniDiff.hpp:25
float operator()(T nbr)
This functor applies a simplified version of the anisotropic diffusion for one channel.
Definition: OP_AniDiff.hpp:31
This functor applies anisotropic diffusion for 3 channels.
Definition: OP_AniDiff.hpp:49
T::PixelType operator()(T nbr)
This functor applies a simplified version of the anisotropic diffusion for 3 channels.
Definition: OP_AniDiff.hpp:55