GuidedFilter

Implementation of the Guided Image Filtering algorithm in OpenCL

Published on April 11, 2015

Categories: robotics, image-processing

Tags: c++, library, filtering, smoothing, opencl, images, point_clouds

Website: https://github.com/nlamprian/GuidedFilter

GuidedFilter is an implementation of the Guided Filter algorithm in OpenCL. The Guided Filter is an image filter with many applications. It has a non-approximate algorithm which is O(1) in the filter window size. It has excellent performance characteristics which makes it a great alternative to the popular Bilateral Filter.

Applications of the Guided Filter include Detail Enhancement and HDR Compression, Flash/No-Flash Denoising, Matting/Guided Feathering, Haze Removal, and Joint Upsampling. But the most basic and important application of the filter, and the one that interests me, is the Edge-Preserving Smoothing. The Guided Filter gives great results and doesn’t suffer from gradient reversal artifacts that can be introduced by the Bilateral Filter.

The Guided Filter can operate on RGB images, as well as Depth images. The GuidedFilter repository contains two applications that let one examine the effects of the filter interactively, on both these cases. The following videos demonstrate the applications.

Guided Image Filtering on Kinect RGB stream with OpenCL:

Guided Image Filtering on Kinect RGB and Depth streams with OpenCL:

It’s very easy to apply the Guided Filter in your own applications. A consistent API has been adopted across all operations supported by the project. You configure and initialize an object associated with an algorithm, write your data on a device buffer, execute the kernel(s), and get back the results. Below is a dummy example to showcase the workflow. For more details, take a look at the examples in the repository.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <CLUtils.hpp>
#include <GuidedFilter/algorithms.hpp>

using namespace clutils;
using namespace cl_algo;

int main(int argc, char **argv) {
  // Setup the OpenCL environment
  CLEnv env(kernel_files);  // Initializes a basic environment
  env.addQueue(0, 0);  // Adds a second queue

  // Configure kernel execution parameters
  CLEnvInfo<2> info(0, 0, 0, { 0, 1 }, 0);
  const GF::GuidedFilterConfig C = GF::GuidedFilterConfig::I_EQ_P;
  GF::GuidedFilter<C> gf(env, info);
  gf.init(width, height, radius, eps);

  // Copy data to device
  gf.write(GF::GuidedFilter<C>::Memory::D_IN, data);

  // Execute kernels
  gf.run();

  // Copy results to host
  cl_float *results = (cl_float *) gf.read();

  return 0;
}

You can find the complete documentation at guided-filter.nlamprian.me. The source code is available on GitHub.