File: adaptive_bilateral_filter.cpp

package info (click to toggle)
opencv 2.4.9.1%2Bdfsg-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 126,800 kB
  • ctags: 62,729
  • sloc: xml: 509,055; cpp: 490,794; lisp: 23,208; python: 21,174; java: 19,317; ansic: 1,038; sh: 128; makefile: 72
file content (64 lines) | stat: -rw-r--r-- 2,013 bytes parent folder | download | duplicates (3)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// This sample shows the difference of adaptive bilateral filter and bilateral filter.
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/ocl/ocl.hpp"

using namespace cv;
using namespace std;


int main( int argc, const char** argv )
{
    const char* keys =
        "{ i | input   |          | specify input image }"
        "{ k | ksize   |     11   | specify kernel size }"
        "{ s | sSpace  |     3    | specify sigma space }"
        "{ c | sColor  |     30   | specify max color }"
        "{ h | help    | false    | print help message }";

    CommandLineParser cmd(argc, argv, keys);
    if (cmd.get<bool>("help"))
    {
        cout << "Usage : adaptive_bilateral_filter [options]" << endl;
        cout << "Available options:" << endl;
        cmd.printParams();
        return EXIT_SUCCESS;
    }

    string src_path = cmd.get<string>("i");
    int ks = cmd.get<int>("k");
    const char * winName[] = {"input", "ABF OpenCL", "BF OpenCL"};

    Mat src = imread(src_path);
    if (src.empty())
    {
        cout << "error read image: " << src_path << endl;
        return EXIT_FAILURE;
    }

    double sigmaSpace = cmd.get<int>("s");

    // sigma for checking pixel values. This is used as is in the "normal" bilateral filter,
    // and it is used as an upper clamp on the adaptive case.
    double sigmacolor = cmd.get<int>("c");

    ocl::oclMat dsrc(src), dABFilter, dBFilter;
    Size ksize(ks, ks);

    // ksize is the total width/height of neighborhood used to calculate local variance.
    // sigmaSpace is not a priori related to ksize/2.
    ocl::adaptiveBilateralFilter(dsrc, dABFilter, ksize, sigmaSpace, sigmacolor);
    ocl::bilateralFilter(dsrc, dBFilter, ks, sigmacolor, sigmaSpace);
    Mat abFilter = dABFilter, bFilter = dBFilter;

    ocl::finish();

    imshow(winName[0], src);
    imshow(winName[1], abFilter);
    imshow(winName[2], bFilter);

    waitKey();

    return EXIT_SUCCESS;
}