Blender V4.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"
26
27namespace libmv {
28
29// TODO(keir): Find a better place for these functions. gaussian.h in numeric?
30
31// Zero mean Gaussian.
32inline 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
37inline 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}
41inline 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.
45inline double GaussianInversePositive(double y, double sigma) {
46 return sqrt(-2 * sigma * sigma * log(y * sigma * sqrt(2 * M_PI)));
47}
48
49void ComputeGaussianKernel(double sigma, Vec* kernel, Vec* derivative);
50void ConvolveHorizontal(const FloatImage& in,
51 const Vec& kernel,
52 FloatImage* out_pointer,
53 int plane = -1);
54void ConvolveVertical(const FloatImage& in,
55 const Vec& kernel,
56 FloatImage* out_pointer,
57 int plane = -1);
58void ConvolveGaussian(const FloatImage& in,
59 double sigma,
60 FloatImage* out_pointer);
61
62void 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
79void BoxFilterHorizontal(const FloatImage& in,
80 int window_size,
81 FloatImage* out_pointer);
82
83void BoxFilterVertical(const FloatImage& in,
84 int window_size,
85 FloatImage* out_pointer);
86
87void BoxFilter(const FloatImage& in, int box_width, FloatImage* out);
88
99void 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
ccl_device_inline float3 exp(float3 v)
ccl_device_inline float3 log(float3 v)
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