18 #ifndef PIC_FILTERING_FILTER_ANISOTROPIC_DIFFUSION_HPP 19 #define PIC_FILTERING_FILTER_ANISOTROPIC_DIFFUSION_HPP 21 #include "../base.hpp" 22 #include "../filtering/filter.hpp" 23 #include "../filtering/filter_iterative.hpp" 63 float k,
unsigned int mode,
unsigned int iterations)
67 imgOut = iter_flt.
Process(imgIn, imgOut);
81 float sigma_s,
float sigma_r,
int maxIterations = -1)
93 if(maxIterations > 0) {
94 iterations = maxIterations;
96 iterations = int(ceilf(5.0
f * sigma_s));
101 imgOut = iter_flt.
Process(imgIn, imgOut);
132 float *gN =
new float [channels];
133 float *gS =
new float [channels];
134 float *gW =
new float [channels];
135 float *gE =
new float [channels];
137 for(
int j = box->
y0; j < box->y1; j++) {
138 for(
int i = box->
x0; i < box->x1; i++) {
140 float *dst_data = (*dst)(i, j);
141 float *img_data = (*img)(i, j);
143 float *img_dataN = (*img)(i + 1, j );
144 float *img_dataS = (*img)(i - 1, j );
145 float *img_dataW = (*img)(i , j - 1);
146 float *img_dataE = (*img)(i , j + 1);
153 for(
int p = 0; p < channels; p++) {
154 gN[p] = img_dataN[p] - img_data[p];
155 gS[p] = img_dataS[p] - img_data[p];
156 gW[p] = img_dataW[p] - img_data[p];
157 gE[p] = img_dataE[p] - img_data[p];
168 cN = 1.0f / (1.0f + cN /
k_sq);
169 cS = 1.0f / (1.0f + cS /
k_sq);
170 cW = 1.0f / (1.0f + cW /
k_sq);
171 cE = 1.0f / (1.0f + cE /
k_sq);
177 t = 1.0f - expf(-3.315
f / powf(cN /
k_sq, 8.0
f));
178 cN = cN > 0.0f ? t : 1.0f;
180 t = 1.0f - expf(-3.315
f / powf(cS /
k_sq, 8.0
f));
181 cS = cS > 0.0f ? t : 1.0f;
183 t = 1.0f - expf(-3.315
f / powf(cW /
k_sq, 8.0
f));
184 cW = cW > 0.0f ? t : 1.0f;
186 t = 1.0f - expf(-3.315
f / powf(cE /
k_sq, 8.0
f));
187 cE = cE > 0.0f ? t : 1.0f;
192 cN = expf(-cN /
k_sq);
193 cS = expf(-cS /
k_sq);
194 cW = expf(-cW /
k_sq);
195 cE = expf(-cE /
k_sq);
199 for(
int p = 0; p < channels; p++) {
200 dst_data[p] = img_data[p] +
delta_t *
201 (cN * gN[p] + cS * gS[p] + cW * gW[p] + cE * gE[p]);
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
float delta_t
Definition: filter_anisotropic_diffusion.hpp:41
float k_sq
Definition: filter_anisotropic_diffusion.hpp:41
int channels
Definition: image.hpp:80
std::vector< Image * > ImageVec
ImageVec an std::vector of pic::Image.
Definition: image_vec.hpp:29
int x0
Definition: bbox.hpp:32
The Filter class.
Definition: filter.hpp:50
unsigned int mode
Definition: filter_anisotropic_diffusion.hpp:42
static Image * execute(ImageVec imgIn, Image *imgOut, float k, unsigned int mode, unsigned int iterations)
execute
Definition: filter_anisotropic_diffusion.hpp:62
int y0
Definition: bbox.hpp:32
FilterAnsiotropicDiffusion(float k, unsigned int mode)
FilterAnsiotropicDiffusion.
Definition: filter_anisotropic_diffusion.hpp:107
Image * Process(ImageVec imgIn, Image *imgOut)
Process.
Definition: filter_npasses.hpp:310
static Image * execute(ImageVec imgIn, Image *imgOut, float sigma_s, float sigma_r, int maxIterations=-1)
execute
Definition: filter_anisotropic_diffusion.hpp:80
#define PIC_INLINE
Definition: base.hpp:33
The Image class stores an image as buffer of float.
Definition: image.hpp:60
void ProcessBBox(Image *dst, ImageVec src, BBox *box)
ProcessBBox.
Definition: filter_anisotropic_diffusion.hpp:126
virtual void f(FilterFData *data)
f
Definition: filter_radial_basis_function.hpp:69
The FilterIterative class.
Definition: filter_iterative.hpp:28
Definition: bilateral_separation.hpp:25
The FilterAnsiotropicDiffusion class.
Definition: filter_anisotropic_diffusion.hpp:30
float k
Definition: filter_anisotropic_diffusion.hpp:41