-
Notifications
You must be signed in to change notification settings - Fork 0
/
openCVtrilateralFilter.h
109 lines (84 loc) · 3.36 KB
/
openCVtrilateralFilter.h
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Targeter - target identification software for EUCALL workpackage 6
// Licensed under the GPL License. See LICENSE file in the project root for full license information.
// Copyright(C) 2017 David Watts
#ifndef FILE_openCVtrilateralFilter_h
#define FILE_openCVtrilateralFilter_h
#include <math.h>
#include <opencv/cxcore.h>
#include <vector>
using std::vector;
class OpenCVtrilateralFilter
{
public:
OpenCVtrilateralFilter(){;};
~OpenCVtrilateralFilter(){;};
// Types for filter
enum{TYPE_LUT, TYPE_FAST};
bool trilateralFilter(cv::Mat& input, cv::Mat& output, const float sigmaC, const float epsilon,
const int filterType = TYPE_FAST);
cv::Mat trilateralFilter(cv::Mat& input, const float sigmaC, const float epsilon, const int filterType = TYPE_FAST)
{
cv::Mat output = cv::Mat( input.rows, input.cols, input.depth(), cv::Scalar(1));
if ( trilateralFilter(input, output, sigmaC, epsilon, filterType) )
{
return output;
}
};
private:
//Computes X and Y gradients of the input image
void computeGradients(
cv::Mat& inputImg, // inputs
cv::Mat& xGradient, cv::Mat& yGradient); // outputs
// Compute image magnitude
void computeMagnitude(
cv::Mat& xGradient, cv::Mat& yGradient, // inputs
cv::Mat& gradientMagnitude); // output
//Finds the adaptive neighborhood size (stack level)
//from the min-max gradient stack
void setAdaptiveNeighbourHood(
cv::Mat& gradientMagnitude, // inputs
const float sigmaR, const int maxLevel,
cv::Mat& adaptiveNeighbourhood ); // output
//Builds the stack of min-max image gradient magnitudes
void buildMinMaxImageStack(
cv::Mat& gradientMagnitude, // input
vector<cv::Mat> minStack, vector<cv::Mat> maxStack ); // outputs
// Fast-Trilateral functions
//Bilaterally filters gradients pX and pY
void BilateralGradientFilter(
cv::Mat& xGradient, cv::Mat& yGradient, // inputs
cv::Mat& gradientMagnitude, const float sigmaC,
const float sigmaR, const float epsilon,
cv::Mat& xGradientSmooth, cv::Mat& yGradientSmooth ); // outputs
//Filters the detail signal and computes the final output image
void DetailBilateralFilter(
cv::Mat& inputImage, cv::Mat& adaptiveRegion, //inputs
cv::Mat& xGradientSmooth, cv::Mat& yGradientSmooth,
const float sigmaC, const float sigmaR,
const int maxDomainSize, const float epsilon,
cv::Mat& outputImg); // output
// LUT-Trilateral functions
void BilateralGradientFilterLUT(
cv::Mat& xGradient, cv::Mat& yGradient, // inputs
cv::Mat& gradientMagnitude,
const float sigmaC, const float sigmaR,
cv::Mat& xGradientSmooth, cv::Mat& yGradientSmooth ); // outputs
void DetailBilateralFilterLUT(
cv::Mat& inputImage, cv::Mat& adaptiveRegion, // inputs
cv::Mat& xGradientSmooth, cv::Mat& yGradientSmooth,
const float sigmaC, const float sigmaR, const int maxDomainSize,
cv::Mat& outputImg); // output
inline float getNorm(float g1, float g2)
{
return (float) sqrt( (float) ( pow(g1,2) + pow(g2,2) ) );
}
inline int log2(int input, bool roundUp = false)
{
float temp = log10( float(input) ) / log10(2.f);
if (roundUp)
return int( ceil(temp) );
else
return int( temp );
}
};
#endif // FILE_openCVtrilateralFilter_h