-
Notifications
You must be signed in to change notification settings - Fork 12
/
algorithms.hpp
136 lines (121 loc) · 5.91 KB
/
algorithms.hpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef ALGORITHMS_HPP
#define ALGORITHMS_HPP
#include <vigra/multi_array.hxx>
#include <vigra/matrix.hxx>
#include "point.hpp"
#include "types.hpp"
namespace sift {
namespace alg {
/**
* Convolves a given image with gaussian with a given sigma
* @param input the input image which will be convolved
* @param sigma the standard deviation for the gaussian
* @return blured image
*/
const vigra::MultiArray<2, f32_t> convolveWithGauss(const vigra::MultiArray<2, f32_t>&,
f32_t);
/**
* Resamples an image by 0.5
* @param img the input image
* @return the output image
*/
const vigra::MultiArray<2, f32_t> reduceToNextLevel(const vigra::MultiArray<2, f32_t>&,
f32_t);
/**
* Resamples an image by 2
* @param in the input image
* @return the output image
*/
const vigra::MultiArray<2, f32_t> increaseToNextLevel(const vigra::MultiArray<2, f32_t>&,
f32_t);
/**
* Calculates the Difference of Gaussian, which is the differnce between 2
* images which were convolved with gaussian under usage of a constant K
* @param lower the image which lies lower in an octave
* @param higher the image which lies higher in an octave
* @return the difference of gaussian image, which contains our interest points
*/
const vigra::MultiArray<2, f32_t> dog(const vigra::MultiArray<2, f32_t>&,
const vigra::MultiArray<2, f32_t>&);
/**
* Calculates the first order derivative of the image, at the coordinates
* @param img the image of which the first derivative is taken.
* @param p the point at which the derivative is taken
* @return the derivative as a vector (dx, dy, ds)
*/
const vigra::Matrix<f32_t> foDerivative(const std::array<vigra::MultiArray<2, f32_t>, 3>&, const Point<u16_t, u16_t>&);
/**
* Calculates the second order derivative of the image, at the coordinates
* @param img the image of which the second derivative is taken.
* @param p the point at which the derivative is taken
* @return the derivative as a matrix
* (dxx, dxy, dxs)
* (dyx, dyy, dys)
* (dsx, dsy, dss)
*/
const vigra::Matrix<f32_t> soDerivative(const std::array<vigra::MultiArray<2, f32_t>, 3>&, const Point<u16_t, u16_t>&);
/**
* Calculates the gradient magnitude of the given image at the given position
* @param img the given img
* @param p the current point
* @return the gradient magnitude value
*/
f32_t gradientMagnitude(const vigra::MultiArray<2, f32_t>&, const Point<u16_t, u16_t>&);
/**
* Calculates the gradient orientation of the given image at the given position
* @param img the given img
* @param p the current point
* @return the gradient orientation value
*/
f32_t gradientOrientation(const vigra::MultiArray<2, f32_t>&, const Point<u16_t, u16_t>&);
/**
* Creates an orientation Histogram of a given img and his corresponding orientations and
* magnitudes. Places values in bins of size 10. So the resulting histogram has 36 elements.
* @param orientations The img of which the histogram is taken from. Needs to be computed by gradient
* orientations before
* @param magnitudes The img of which the bins of the histogram will be weighted. Need to be
* precomputed by gradient magnitude
* @param img the given img
* @return histogram with 36 bins which are weighted by magnitudes and gaussian
*/
const std::array<f32_t, 36> orientationHistogram36(const vigra::MultiArray<2, f32_t>&,
const vigra::MultiArray<2, f32_t>& , const vigra::MultiArray<2, f32_t>&);
/**
* Creates an orientation Histogram of a given img and his corresponding orientations and
* magnitudes. Places values in bins of size 45. So the resulting histogram has 8 elements.
* @param orientations The img of which the histogram is taken from. Needs to be computed by gradient
* orientations before
* @param magnitudes The img of which the bins of the histogram will be weighted. Need to be
* precomputed by gradient magnitude
* @param img the given img
* @return histogram with 8 bins which are weighted by magnitudes and gaussian
*/
const std::vector<f32_t> orientationHistogram8(const vigra::MultiArray<2, f32_t>&,
const vigra::MultiArray<2, f32_t>&, const vigra::MultiArray<2, f32_t>&);
/**
* Calculates the vertex of a parabola, by taking a max value and its 2 neigbours
* @param ln the left neighbor of the peak
* @param peak the peak value
* @param rn the right neighbor of the peak
* @return the vertex value
*/
f32_t vertexParabola(const Point<u16_t, f32_t>&, const Point<u16_t, f32_t>&,
const Point<u16_t, f32_t>&);
/**
* Rotates a given shape by a given degree clockwise
* @param center the center point of the shape
* @param angle by which angle the shape should be rotated
* @param width the width of the shape
* @param height the height of the shape
* @return array with 2 elements. First element represents upper left corner of the shape and
* bottom right is represented by the second argument
*/
std::array<Point<f32_t, f32_t>, 4> rotateShape(const Point<u16_t, u16_t>&, f32_t, const u16_t, const u16_t);
/**
* Normalizes a vector
* @param vec the vector to be normalized
*/
void normalizeVector(std::vector<f32_t>&);
}
}
#endif //ALGORITHMS_HPP