-
Notifications
You must be signed in to change notification settings - Fork 31
/
ARAPSmoothTerm.cc
109 lines (105 loc) · 4.12 KB
/
ARAPSmoothTerm.cc
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
#include <ARAPSmoothTerm.h>
#include <vw/Image/Filter.h>
#include <vw/Image/ImageView.h>
#include <vw/Image/ImageViewRef.h>
#include <Eigen/Sparse>
void vw::stereo::generate_weight1(ImageView<float> const& a,
double gamma,
ImageView<float> & weight) {
ImageView<float> kernel(3,1);
kernel(0,0)=1; kernel(1,0)=-2; kernel(2,0)=1;
weight =
exp(-abs(convolution_filter(a, kernel, 1, 0, ConstantEdgeExtension()))/gamma);
}
void vw::stereo::generate_weight2(ImageView<float> const& a,
double gamma,
ImageView<float> & weight) {
ImageView<float> kernel(1,3);
kernel(0,0)=1; kernel(0,1)=-2; kernel(0,2)=1;
weight =
exp(-abs(convolution_filter(a, kernel, 0, 1, ConstantEdgeExtension()))/gamma);
}
void vw::stereo::generate_weight3(ImageView<float> const& a,
double gamma,
ImageView<float> & weight) {
ImageView<float> kernel(3,3);
kernel(0,0)=1; kernel(1,0)=0 ; kernel(2,0)=0;
kernel(0,1)=0; kernel(1,1)=-2; kernel(2,1)=0;
kernel(0,2)=0; kernel(1,2)=0 ; kernel(2,2)=1;
weight =
exp(-abs(convolution_filter(a, kernel, 1, 1, ConstantEdgeExtension()))/gamma);
}
void vw::stereo::generate_weight4(ImageView<float> const& a,
double gamma,
ImageView<float> & weight) {
ImageView<float> kernel(3,3);
kernel(0,0)=0; kernel(1,0)=0 ; kernel(2,0)=1;
kernel(0,1)=0; kernel(1,1)=-2; kernel(2,1)=0;
kernel(0,2)=1; kernel(1,2)=0 ; kernel(2,2)=0;
weight =
exp(-abs(convolution_filter(a, kernel, 1, 1, ConstantEdgeExtension()))/gamma);
}
void vw::stereo::generate_laplacian1(ImageView<float> const& weight,
Eigen::SparseMatrix<float> & sparse) {
// These matrices are column major
sparse.reserve(Eigen::VectorXf::Constant(weight.cols() * weight.rows(), 3));
int k = 0;
for (int j = 0; j < weight.rows(); j++ ) {
for (int i = 0; i < weight.cols(); i++) {
if (i > 0 && i < weight.cols()-1) {
sparse.insert(k, k) = 2 * weight(i,j);
sparse.insert(k, k - 1) = -weight(i,j);
sparse.insert(k, k + 1) = -weight(i,j);
}
k++;
}
}
}
void vw::stereo::generate_laplacian2(ImageView<float> const& weight,
Eigen::SparseMatrix<float> & sparse) {
// These matrices are column major
sparse.reserve(Eigen::VectorXf::Constant(weight.cols() * weight.rows(), 3));
int k = 0;
for (int j = 0; j < weight.rows(); j++ ) {
for (int i = 0; i < weight.cols(); i++) {
if (j > 0 && j < weight.rows()-1) {
sparse.insert(k,k) = 2 * weight(i,j);
sparse.insert(k, k-weight.cols()) = -weight(i,j);
sparse.insert(k, k+weight.cols()) = -weight(i,j);
}
k++;
}
}
}
void vw::stereo::generate_laplacian3(ImageView<float> const& weight,
Eigen::SparseMatrix<float> & sparse) {
// These matrices are column major
sparse.reserve(Eigen::VectorXf::Constant(weight.cols() * weight.rows(), 3));
int k = 0;
for (int j = 0; j < weight.rows(); j++ ) {
for (int i = 0; i < weight.cols(); i++) {
if (j > 0 && i > 0 && j < weight.rows()-1 && i < weight.cols() - 1) {
sparse.insert(k,k) = 2 * weight(i,j);
sparse.insert(k, k - weight.cols() - 1) = -weight(i,j);
sparse.insert(k, k + weight.cols() + 1) = -weight(i,j);
}
k++;
}
}
}
void vw::stereo::generate_laplacian4(ImageView<float> const& weight,
Eigen::SparseMatrix<float> & sparse) {
// These matrices are column major
sparse.reserve(Eigen::VectorXf::Constant(weight.cols() * weight.rows(), 3));
int k = 0;
for (int j = 0; j < weight.rows(); j++ ) {
for (int i = 0; i < weight.cols(); i++) {
if (j > 0 && i < weight.cols() - 1 && j < weight.rows()-1 && i > 0) {
sparse.insert(k,k) = 2 * weight(i,j);
sparse.insert(k - weight.cols() + 1, k) = -weight(i,j);
sparse.insert(k + weight.cols() - 1, k) = -weight(i,j);
}
k++;
}
}
}