Can ceres-solver get exact solution of linear equations with LU decomposition method?

58 views
Skip to first unread message

Moses

unread,
Jul 8, 2018, 7:14:35 AM7/8/18
to Ceres Solver
I am using opencv to do Exposure Compensate with GainCompensator method.  
https://github.com/opencv/opencv/blob/master/modules/stitching/src/exposure_compensate.cpp (line 127~141)
OpenCV use solve(A, b, gains_); with CV_EXPORTS_W bool solve(InputArray src1, InputArray src2, OutputArray dst, int flags = DECOMP_LU);。
error equation:


above equation's derivative:

Set to 0:


I replace OpenCV code (line 127~141) with ceres-solver, like below:
---------------
struct F {
F(int Nij, double Iij, double Iji, double alpha, double beta) :Nij_(Nij), Iij_(Iij), Iji_(Iji), alpha_(alpha), beta_(beta) {}
template <typename T> bool operator()(const T* const gi, const T* const gj, T* residual) const {
residual[0] = T(Nij_) * ( alpha_ * alpha_ *  (gi[0] * Iij_ - gj[0] * Iji_) * (gi[0] * Iij_ - gj[0] * Iji_) + beta_ * beta_ * (T(1) - gi[0]) * (T(1) - gi[0]) );
return true;
}
private:
const int Nij_;
const double Iij_, Iji_, alpha_, beta_;
};

struct E {
E(int Nij, double beta) :Nij_(Nij), beta_(beta) {}
template <typename T> bool operator()(const T* const gi, T* residual) const {
residual[0] = T(Nij_) * (beta_ * beta_ * (T(1) - gi[0]) * (T(1) - gi[0]));
return true;
}
private:
const int Nij_;
const double beta_;
};
---------------
//google::InitGoogleLogging("");
gains_ = Mat_<double>::zeros(num_images, 1);
for (int i = 0; i < num_images; ++i) {
gains_(i, 0) = 0; // if I set to all 1, then it will output all 1.
}
ceres::Problem problem;
for (int i = 0; i < num_images; ++i)
{
for (int j = 0; j < num_images; ++j)
{
if (i != j)
problem.AddResidualBlock(new AutoDiffCostFunction<F, 1, 1, 1>(new F(N(i, j), I(i, j), I(j, i), alpha, beta)), NULL, &gains_(i, 0), &gains_(j, 0));
else
problem.AddResidualBlock(new AutoDiffCostFunction<E, 1, 1>(new E(N(i, j), beta)), NULL, &gains_(i, 0));
}
}
ceres::Solver::Options options;
//options.max_num_iterations = 25;
options.linear_solver_type = ceres::DENSE_QR;
options.num_linear_solver_threads = 4;
options.function_tolerance = 0.1;
options.minimizer_progress_to_stdout = true;
ceres::Solver::Summary summary;
ceres::Solve(options, &problem, &summary);
//std::cout << summary.BriefReport() << "\n";
----------------

I use seven images to test exposure compensate, ceres-solver quick a little, but the answer is not what I want.


I think this is because ceres-solver is getting a local solution, how can I get the same answer the same with Opencv, because ceres-solver is very easy to use.
Does anyone know more about math with this problem, thank you very much!

Moses

unread,
Jul 8, 2018, 7:18:09 AM7/8/18
to Ceres Solver
Update missing images 

在 2018年7月8日星期日 UTC+8下午7:14:35,Moses写道:
I am using opencv to do Exposure Compensate with GainCompensator method.  
https://github.com/opencv/opencv/blob/master/modules/stitching/src/exposure_compensate.cpp (line 127~141)
OpenCV use solve(A, b, gains_); with CV_EXPORTS_W bool solve(InputArray src1, InputArray src2, OutputArray dst, int flags = DECOMP_LU);。
 
error equation:
above equation's derivative:

Sameer Agarwal

unread,
Jul 8, 2018, 11:04:32 PM7/8/18
to ceres-...@googlegroups.com
Moses,
I am confused.
Are you asking if Ceres can do LU factorization? The answer is no.
Are you asking if ceres can get the same solution as an LU factorization? for a linear problem yes.
But looks like your problem is non-linear. In which case all you can get is a local minimum.
Sameer


--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/f0a07df7-5ff3-432b-bffb-9fbdee4cfe0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages