18 #ifndef PIC_FILTERING_FILTER_BILATERAL_2DS_HPP 19 #define PIC_FILTERING_FILTER_BILATERAL_2DS_HPP 23 #include "../base.hpp" 24 #include "../util/string.hpp" 25 #include "../util/std_util.hpp" 27 #include "../filtering/filter.hpp" 28 #include "../util/precomputed_gaussian.hpp" 29 #include "../point_samplers/sampler_random_m.hpp" 110 bool Write(std::string filename);
117 bool Read(std::string filename);
150 if(imgEdge == NULL) {
163 static inline float getK(
int kernelSize)
166 float ret = 0.4055f / (0.6437f * float(kernelSize) - 1.1083f) + 0.7347
f;
167 ret = (ret > 0.0f) ? ret : 3.0
f;
177 static inline float getK2(
int kernelSize)
179 float ret = 0.3233f / (0.5053f * float(kernelSize) - 0.8272f) + 0.7366
f;
180 ret = (ret > 0.0f) ? ret : 2.5
f;
189 for(
int i = 0; i < 6; i++) {
190 float sigma_s = powf(2.0
f,
float(i));
194 int nMaxSamples = nSamplesDiv2 * nSamplesDiv2;
195 int oldNSamples = -1;
197 printf(
"Compute kernel sigma_s: %f\n",
sigma_s);
199 for(
int j = 1; j <= 16; j++) {
200 printf(
"Multiplier: %d\n", j);
238 this->
sigma_r_sq_2 = this->sigma_r * this->sigma_r * 2.0f;
285 std::mt19937 m(
seed);
287 for(
int j = box->
y0; j < box->y1; j++) {
288 for(
int i = box->
x0; i < box->x1; i++) {
289 float *dst_data = (*dst )(i, j);
290 float *edge_data = (*edge)(i, j);
298 for(
int k = 0; k <
nSamples; k += 2) {
309 float *edge_data_ci_cj = (*edge)(ci, cj);
314 float acc_delta_range_sq =
Arrayf::distanceSq(edge_data_ci_cj, edge_data, edgeChannels);
321 float weight = G1 * G2;
324 float *base_data_ci_cj = (*base)(ci, cj);
327 for(
int l = 0; l < channels; l++) {
328 dst_data[l] += base_data_ci_cj[l] * weight;
336 float *base_data = (*base)(i, j);
359 return ms->
Read(filename);
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
std::string fromNumberToString(T num)
fromNumberToString converts a number into a string.
Definition: string.hpp:102
static int getKernelSize(float sigma)
KernelSize computes the size of a kernel in pixel give its sigma.
Definition: precomputed_gaussian.hpp:121
int channels
Definition: image.hpp:80
T * delete_s(T *data)
delete_s
Definition: std_util.hpp:123
bool Write(std::string name)
Write saves into an existing file.
Definition: sampler_random_m.hpp:217
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
PIC_INLINE long lround(double x)
lround rounds double numbers properly.
Definition: math.hpp:229
The MRSamplers class.
Definition: sampler_random_m.hpp:34
bool Write(std::string filename)
Write.
Definition: filter_bilateral_2ds.hpp:344
The Filter class.
Definition: filter.hpp:50
PrecomputedGaussian * pg
Definition: filter_bilateral_2ds.hpp:40
virtual Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter.hpp:390
static float getK(int kernelSize)
getK
Definition: filter_bilateral_2ds.hpp:163
float * coeff
Definition: precomputed_gaussian.hpp:67
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_bilateral_2ds.hpp:264
Vec< 2, int > Vec2i
Vec2i.
Definition: vec.hpp:829
int nSamples
Definition: filter_bilateral_2ds.hpp:43
static T distanceSq(T *data0, T *data1, int n)
distanceSq
Definition: array.hpp:195
static float getK2(int kernelSize)
getK2
Definition: filter_bilateral_2ds.hpp:177
void update(float sigma_s, float sigma_r, int mult, SAMPLER_TYPE type)
update
Definition: filter_bilateral_2ds.hpp:232
int y0
Definition: bbox.hpp:32
bool Read(std::string name)
Read.
Definition: sampler_random_m.hpp:145
float sigma_s
Definition: filter_bilateral_2ds.hpp:39
RandomSampler< N > * getSampler(std::mt19937 *m)
getSampler gets a sampler at a given level
Definition: sampler_random_m.hpp:139
float sigma_r
Definition: filter_bilateral_2ds.hpp:39
PIC_INLINE ImageVec Double(Image *img1, Image *img2)
Double creates an std::vector which contains img1 and img2; this is for filters input.
Definition: image_vec.hpp:49
FilterBilateral2DS()
FilterBilateral2DS.
Definition: filter_bilateral_2ds.hpp:58
~FilterBilateral2DS()
Definition: filter_bilateral_2ds.hpp:65
std::string genBilString(std::string type, float sigma_s, float sigma_r)
genBilString
Definition: string.hpp:366
#define PIC_INLINE
Definition: base.hpp:33
SAMPLER_TYPE
Definition: point_samplers.hpp:51
std::vector< int > samplesR
Definition: sampler_random.hpp:53
static Image * execute(Image *imgIn, Image *imgEdge, float sigma_s, float sigma_r)
execute
Definition: filter_bilateral_2ds.hpp:144
#define MIN(a, b)
Definition: math.hpp:69
The Image class stores an image as buffer of float.
Definition: image.hpp:60
std::string signature()
signature
Definition: filter_bilateral_2ds.hpp:100
static void div(T *data, int size, T value)
div
Definition: array.hpp:353
The PrecomputedGaussian class.
Definition: precomputed_gaussian.hpp:30
int halfKernelSize
Definition: precomputed_gaussian.hpp:66
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
Definition: point_samplers.hpp:51
int kernelSize
Definition: precomputed_gaussian.hpp:66
PIC_INLINE ImageVec Single(Image *img)
Single creates an std::vector which contains img; this is for filters input.
Definition: image_vec.hpp:36
Definition: bilateral_separation.hpp:25
static T * assign(T *data, int size, T *ret)
assign
Definition: array.hpp:464
static Image * execute(Image *imgIn, float sigma_s, float sigma_r)
execute
Definition: filter_bilateral_2ds.hpp:126
int seed
Definition: filter_bilateral_2ds.hpp:42
static void precomputeKernels()
PrecomputedKernels.
Definition: filter_bilateral_2ds.hpp:187
The RandomSampler class.
Definition: sampler_random.hpp:43
bool Read(std::string filename)
Read.
Definition: filter_bilateral_2ds.hpp:350
float sigma_r_sq_2
Definition: filter_bilateral_2ds.hpp:39
MRSamplers< 2 > * ms
Definition: filter_bilateral_2ds.hpp:41
The Vec class.
Definition: vec.hpp:35
The FilterBilateral2DS class.
Definition: filter_bilateral_2ds.hpp:36