Skip to content

Commit

Permalink
remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
servantftechnicolor committed Jul 27, 2020
1 parent abecba3 commit ea6ba3f
Showing 1 changed file with 0 additions and 253 deletions.
253 changes: 0 additions & 253 deletions src/software/pipeline/main_panoramaWarping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,259 +38,6 @@ namespace po = boost::program_options;
namespace bpt = boost::property_tree;
namespace fs = boost::filesystem;


Eigen::VectorXf gaussian_kernel_vector(size_t kernel_length, float sigma) {

Eigen::VectorXd x;
x.setLinSpaced(kernel_length + 1, -sigma, +sigma);

Eigen::VectorXd cdf(kernel_length + 1);
for (int i = 0; i < kernel_length + 1; i++) {
cdf(i) = 0.5 * (1 + std::erf(x(i)/sqrt(2.0)));
}

Eigen::VectorXd k1d(kernel_length);
for (int i = 0; i < kernel_length; i++) {
k1d(i) = cdf(i + 1) - cdf(i);
}

double sum = k1d.sum();
k1d = k1d / sum;

return k1d.cast<float>();
}

Eigen::MatrixXf gaussian_kernel(size_t kernel_length, float sigma) {

Eigen::VectorXf k1d = gaussian_kernel_vector(kernel_length, sigma);
Eigen::MatrixXf K = k1d * k1d.transpose();


double sum = K.sum();
K = K / sum;

return K;
}



bool convolve(image::Image<float> & output, const image::Image<float> & input, const image::Image<unsigned char> & mask, const Eigen::MatrixXf & kernel) {

if (output.size() != input.size()) {
return false;
}

if (output.size() != mask.size()) {
return false;
}

if (kernel.size() % 2 == 0) {
return false;
}

if (kernel.rows() != kernel.cols()) {
return false;
}

int radius = kernel.rows() / 2;

Eigen::MatrixXf kernel_scaled = kernel;

for (int i = 0; i < output.Height(); i++) {
for (int j = 0; j < output.Width(); j++) {

float sum = 0.0f;
float sum_mask = 0.0f;

if (!mask(i, j)) {
output(i, j) = 0.0f;
continue;
}

for (int k = 0; k < kernel.rows(); k++) {
float ni = i + k - radius;
if (ni < 0 || ni >= output.Height()) {
continue;
}

for (int l = 0; l < kernel.cols(); l++) {
float nj = j + l - radius;
if (nj < 0 || nj >= output.Width()) {
continue;
}

if (!mask(ni, nj)) {
continue;
}

float val = kernel(k, l) * input(ni, nj);
sum += val;
sum_mask += kernel(k, l);
}
}

output(i, j) = sum / sum_mask;
}
}

return true;
}

bool convolve(image::Image<image::RGBfColor> & output, const image::Image<image::RGBfColor> & input, const image::Image<unsigned char> & mask, const Eigen::MatrixXf & kernel) {

if (output.size() != input.size()) {
return false;
}

if (output.size() != mask.size()) {
return false;
}

if (kernel.size() % 2 == 0) {
return false;
}

if (kernel.rows() != kernel.cols()) {
return false;
}

int radius = kernel.rows() / 2;

Eigen::MatrixXf kernel_scaled = kernel;

for (int i = 0; i < output.Height(); i++) {
for (int j = 0; j < output.Width(); j++) {

image::RGBfColor sum(0.0f);
float sum_mask = 0.0f;

if (!mask(i, j)) {
output(i, j) = sum;
continue;
}

for (int k = 0; k < kernel.rows(); k++) {
float ni = i + k - radius;
if (ni < 0 || ni >= output.Height()) {
continue;
}

for (int l = 0; l < kernel.cols(); l++) {
float nj = j + l - radius;
if (nj < 0 || nj >= output.Width()) {
continue;
}

if (!mask(ni, nj)) {
continue;
}

sum.r() += kernel(k, l) * input(ni, nj).r();
sum.g() += kernel(k, l) * input(ni, nj).g();
sum.b() += kernel(k, l) * input(ni, nj).b();
sum_mask += kernel(k, l);
}
}

output(i, j) = sum / sum_mask;
}
}

return true;
}

bool computeDistanceMap(image::Image<int> & distance, const image::Image<unsigned char> & mask) {

int m = mask.Height();
int n = mask.Width();

int maxval = m * n;

distance = image::Image<int> (n, m, false);
for(int x = 0; x < n; ++x) {

//A corner is when mask becomes 0
bool b = !mask(0, x);
if (b) {
distance(0, x) = 0;
}
else {
distance(0, x) = maxval * maxval;
}

for (int y = 1; y < m; y++) {
bool b = !mask(y, x);
if (b) {
distance(y, x) = 0;
}
else {
distance(y, x) = 1 + distance(y - 1, x);
}
}

for (int y = m - 2; y >= 0; y--) {
if (distance(y + 1, x) < distance(y, x)) {
distance(y, x) = 1 + distance(y + 1, x);
}
}
}

for (int y = 0; y < m; y++) {
int q;
std::map<int, int> s;
std::map<int, int> t;

q = 0;
s[0] = 0;
t[0] = 0;

std::function<int (int, int)> f = [distance, y](int x, int i) {
int gi = distance(y, i);
return (x - i)*(x - i) + gi * gi;
};

std::function<int (int, int)> sep = [distance, y](int i, int u) {
int gu = distance(y, u);
int gi = distance(y, i);

int nom = (u * u) - (i * i) + (gu * gu) - (gi * gi);
int denom = 2 * (u - i);

return nom / denom;
};

for (int u = 1; u < n; u++) {

while (q >= 0 && (f(t[q], s[q]) > f(t[q], u))) {
q = q - 1;
}

if (q < 0) {
q = 0;
s[0] = u;
}
else {
int w = 1 + sep(s[q], u);
if (w < n) {
q = q + 1;
s[q] = u;
t[q] = w;
}
}
}

for (int u = n - 1; u >= 0; u--) {
distance(y, u) = f(u, s[q]);
if (u == t[q]) {
q = q - 1;
}
}
}

return true;
}


namespace SphericalMapping
{
/**
Expand Down

0 comments on commit ea6ba3f

Please sign in to comment.