Blender  V3.3
convolve.h
Go to the documentation of this file.
1 // Copyright (c) 2007, 2008, 2011 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
21 #ifndef LIBMV_IMAGE_CONVOLVE_H_
22 #define LIBMV_IMAGE_CONVOLVE_H_
23 
24 #include "libmv/image/image.h"
25 #include "libmv/numeric/numeric.h"
26 
27 namespace libmv {
28 
29 // TODO(keir): Find a better place for these functions. gaussian.h in numeric?
30 
31 // Zero mean Gaussian.
32 inline double Gaussian(double x, double sigma) {
33  return 1 / sqrt(2 * M_PI * sigma * sigma) * exp(-(x * x / 2 / sigma / sigma));
34 }
35 // 2D gaussian (zero mean)
36 // (9) in http://mathworld.wolfram.com/GaussianFunction.html
37 inline double Gaussian2D(double x, double y, double sigma) {
38  return 1.0 / (2.0 * M_PI * sigma * sigma) *
39  exp(-(x * x + y * y) / (2.0 * sigma * sigma));
40 }
41 inline double GaussianDerivative(double x, double sigma) {
42  return -x / sigma / sigma * Gaussian(x, sigma);
43 }
44 // Solve the inverse of the Gaussian for positive x.
45 inline double GaussianInversePositive(double y, double sigma) {
46  return sqrt(-2 * sigma * sigma * log(y * sigma * sqrt(2 * M_PI)));
47 }
48 
49 void ComputeGaussianKernel(double sigma, Vec* kernel, Vec* derivative);
50 void ConvolveHorizontal(const FloatImage& in,
51  const Vec& kernel,
52  FloatImage* out_pointer,
53  int plane = -1);
54 void ConvolveVertical(const FloatImage& in,
55  const Vec& kernel,
56  FloatImage* out_pointer,
57  int plane = -1);
58 void ConvolveGaussian(const FloatImage& in,
59  double sigma,
60  FloatImage* out_pointer);
61 
62 void ImageDerivatives(const FloatImage& in,
63  double sigma,
64  FloatImage* gradient_x,
65  FloatImage* gradient_y);
66 
68  double sigma,
69  FloatImage* blurred_image,
70  FloatImage* gradient_x,
71  FloatImage* gradient_y);
72 
73 // Blur and take the gradients of an image, storing the results inside the
74 // three channels of blurred_and_gradxy.
76  double sigma,
77  FloatImage* blurred_and_gradxy);
78 
79 void BoxFilterHorizontal(const FloatImage& in,
80  int window_size,
81  FloatImage* out_pointer);
82 
83 void BoxFilterVertical(const FloatImage& in,
84  int window_size,
85  FloatImage* out_pointer);
86 
87 void BoxFilter(const FloatImage& in, int box_width, FloatImage* out);
88 
99 void LaplaceFilter(unsigned char* src,
100  unsigned char* dst,
101  int width,
102  int height,
103  int strength);
104 
105 } // namespace libmv
106 
107 #endif // LIBMV_IMAGE_CONVOLVE_H_
sqrt(x)+1/max(0
#define M_PI
Definition: BLI_math_base.h:20
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
SyclQueue void void size_t num_bytes SyclQueue void const char void *memory_device_pointer KernelContext int kernel
SyclQueue void void * src
ccl_device_inline float3 exp(float3 v)
Definition: math_float3.h:392
ccl_device_inline float3 log(float3 v)
Definition: math_float3.h:397
void BoxFilterVertical(const Array3Df &in, int window_size, Array3Df *out_pointer)
Definition: convolve.cc:289
Eigen::VectorXd Vec
Definition: numeric.h:61
void ImageDerivatives(const Array3Df &in, double sigma, Array3Df *gradient_x, Array3Df *gradient_y)
Definition: convolve.cc:191
void ConvolveHorizontal(const Array3Df &in, const Vec &kernel, Array3Df *out_pointer, int plane)
Definition: convolve.cc:168
void ConvolveVertical(const Array3Df &in, const Vec &kernel, Array3Df *out_pointer, int plane)
Definition: convolve.cc:175
void LaplaceFilter(unsigned char *src, unsigned char *dst, int width, int height, int strength)
Definition: convolve.cc:329
double GaussianDerivative(double x, double sigma)
Definition: convolve.h:41
Array3Df FloatImage
void BoxFilterHorizontal(const Array3Df &in, int window_size, Array3Df *out_pointer)
Definition: convolve.cc:255
void BlurredImageAndDerivativesChannels(const Array3Df &in, double sigma, Array3Df *blurred_and_gradxy)
Definition: convolve.cc:233
double Gaussian(double x, double sigma)
Definition: convolve.h:32
double GaussianInversePositive(double y, double sigma)
Definition: convolve.h:45
void ConvolveGaussian(const Array3Df &in, double sigma, Array3Df *out_pointer)
Definition: convolve.cc:182
void ComputeGaussianKernel(double sigma, Vec *kernel, Vec *derivative)
Definition: convolve.cc:32
void BoxFilter(const Array3Df &in, int box_width, Array3Df *out)
Definition: convolve.cc:323
double Gaussian2D(double x, double y, double sigma)
Definition: convolve.h:37
void BlurredImageAndDerivatives(const Array3Df &in, double sigma, Array3Df *blurred_image, Array3Df *gradient_x, Array3Df *gradient_y)
Definition: convolve.cc:208
static const pxr::TfToken out("out", pxr::TfToken::Immortal)