27#include <foreign/levmar/levmar.h>
32#define DEBUG_LOG_VIG 1
50 const std::vector<vigra_ext::PointPairRGB> & data,
65 for (
unsigned i=0;
i < optvars.size();
i++)
67 const std::set<std::string> vars = optvars[
i];
69 for (std::set<std::string>::const_iterator
it = vars.begin();
70 it != vars.end(); ++
it)
80#define CheckLinked(name)\
81 if(img_i.name##isLinked())\
83 for(unsigned j=i+1;j<pano.getNrOfImages();j++)\
84 if(img_i.name##isLinkedWith(pano.getImage(j)))\
87 usedVars[j].insert(var.type);\
111 if(var.
type==
"Vx" || var.
type==
"Vy")
123 for (
size_t i=0;
i < m_vars.size();
i++)
125 assert(!m_vars[
i].imgs.empty());
127 unsigned j = *(m_vars[
i].imgs.begin());
129 x[
i] = m_imgs[
j].getVar(m_vars[
i].type);
137 for (
size_t i=0;
i < m_vars.size();
i++)
140 assert(!m_vars[
i].imgs.empty());
142 for (std::set<unsigned>::const_iterator
it = m_vars[
i].imgs.begin();
143 it != m_vars[
i].imgs.end(); ++
it)
145 m_imgs[*
it].setVar(m_vars[
i].type, x[
i]);
165 std::ostringstream
oss;
168 std::ofstream log(
oss.str().c_str());
169 log <<
"VIGparams = [";
170 for (
int i = 0;
i < m;
i++) {
173 log <<
" ]; " << std::endl;
175 std::ofstream
script(
"vig_test.pto");
178 dat->m_pano.printPanoramaScript(
script, optvars,
dat->m_pano.getOptions(), imgs,
false,
"");
181 size_t nImg =
dat->m_imgs.size();
184 for (
size_t i=0;
i <
nImg;
i++) {
202 resp[
i].enforceMonotonicity();
211 log <<
"VIGval = [ ";
214 for (std::vector<vigra_ext::PointPairRGB>::const_iterator
it =
dat->m_data.begin();
219 vigra::RGBValue<double> error =
it->i1 -
i2ini1;
229 for (
int i=0;
i < 3;
i++) {
236 if (
dat->huberSigma > 0) {
237 for (
int i=0;
i < 3;
i++) {
251 log <<
it->i1.green() <<
" "<<
l1.green() <<
" " <<
i1ini2.green() <<
" "
252 <<
it->i2.green() <<
" "<<
l2.green() <<
" " <<
i2ini1.green() <<
"; " << std::endl;
257 log << std::endl <<
"VIGerr = [";
258 for (
int i = 0;
i <
n;
i++) {
259 log << x[
i] << std::endl;
261 log <<
" ]; " << std::endl;
274 snprintf(tmp,199,
"Iteration: %d, error: %f",
iter, error);
275 return dat->m_progress->updateDisplay(std::string(tmp)) ? 1 : 0 ;
288 for (OptimizeVector::const_iterator
it=vars.begin();
it != vars.end(); ++
it)
290 std::set<std::string>
cvars;
291 for (std::set<std::string>::const_iterator
itv = (*it).begin();
292 itv != (*it).end(); ++
itv)
294 if ((*
itv)[0] ==
'E' || (*itv)[0] ==
'R' || (*itv)[0] ==
'V') {
314 vigra::ArrayVector<double> p(m, 0.0);
318 vigra::ArrayVector<double> x(
n, 0.0);
322 printf(
"Parameters before optimisation: ");
323 for(
int i=0;
i<m; ++
i)
339 dlevmar_dif(&
photometricError, &
photometricVis, &(p[0]), &(x[0]), m,
n,
nMaxIter,
optimOpts, info,
NULL,
NULL, &data);
342 data.
FromX(p.begin());
347 for (
int i=0;
i<
n;
i++) {
350 error =
sqrt(error/
n);
353 printf(
"Levenberg-Marquardt returned in %g iter, reason %g\nSolution: ", info[5], info[6]);
354 for(
int i=0;
i<m; ++
i)
356 printf(
"\n\nMinimization info:\n");
371 srcImage.setRadialVigCorrCoeff(
vigCorr);
372 srcImage.setSize(vigra::Size2D(500, 500));
374 for (
size_t x = 0; x < 250; x += 10)
389 if(pano.
getImage(
i).getWhiteBalanceBlue()>3)
393 if(pano.
getImage(
i).getWhiteBalanceRed()>3)
414 if (mode == OPT_PHOTOMETRIC_LDR || mode == OPT_PHOTOMETRIC_LDR_WB)
443 if (mode == OPT_PHOTOMETRIC_LDR_WB || mode == OPT_PHOTOMETRIC_HDR_WB)
declaration of functions to handle stacks and layers
#define CheckLinked(name)
@ RESPONSE_EMOR
empirical model of response
PanoramaData & o_panorama
virtual VariableMapVector getVariables() const =0
get variables of this panorama
virtual const PanoramaOptions & getOptions() const =0
returns the options for this panorama
virtual void setSrcImage(unsigned int nr, const SrcPanoImage &img)=0
set input image parameters TODO: Propagate changes to linked images.
virtual SrcPanoImage getSrcImage(unsigned imgNr) const =0
get a complete description of a source image
virtual const SrcPanoImage & getImage(std::size_t nr) const =0
get a panorama image, counting starts with 0
virtual void updateVariables(const VariableMapVector &vars)=0
Set the variables.
virtual std::size_t getNrOfImages() const =0
number of images.
unsigned int colorReferenceImage
virtual bool runAlgorithm()
implementation of the algorithm.
const PointPairs & o_correspondences
static void optimizePhotometric(PanoramaData &pano, const OptimizeVector &vars, const PointPairs &correspondences, const float imageStepSize, AppBase::ProgressDisplay *progress, double &error)
static void photometricError(double *p, double *x, int m, int n, void *data)
const float o_imageStepSize
static int photometricVis(double *p, double *x, int m, int n, int iter, double sqerror, void *data)
const OptimizeVector & o_vars
static void smartOptimizePhotometric(PanoramaData &pano, PhotometricOptimizeMode mode, const std::vector< vigra_ext::PointPairRGB > &correspondences, const float imageStepSize, AppBase::ProgressDisplay *progress, double &error)
use various heuristics to decide what to optimize.
PhotometricOptimizeMode
local optimize definition.
virtual bool runAlgorithm()
implementation of the algorithm.
All variables of a source image.
virtual void cancelAlgorithm()
Call this when the algorithm is cancelled.
virtual bool wasCancelled() const
virtual AppBase::ProgressDisplay * getProgressDisplay() const
std::vector< float > EMoRParams
hugin_utils::FDiff2D RadialVigCorrCenterShift
std::vector< double > RadialVigCorrCoeff
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
std::vector< VariableMap > VariableMapVector
double weightHuber(double x, double sigma)
expects the abs(error) values
std::vector< std::set< std::string > > OptimizeVector
bool IsHighVignetting(std::vector< double > vigCorr)
std::set< unsigned int > UIntSet
std::vector< UIntSet > getHDRStacks(const PanoramaData &pano, UIntSet allImgs, PanoramaOptions opts)
returns vector of set of output stacks
bool CheckStrangeWB(PanoramaData &pano)
bool set_contains(const _Container &c, const typename _Container::key_type &key)
void fill_set(_Container &c, typename _Container::key_type begin, typename _Container::key_type end)
std::vector< SrcPanoImage > m_imgs
std::vector< VarMapping > m_vars
OptimData(const PanoramaData &pano, const OptimizeVector &optvars, const std::vector< vigra_ext::PointPairRGB > &data, double mEstimatorSigma, bool symmetric, int maxIter, AppBase::ProgressDisplay *progress)
void ToX(double *x)
copy optimisation variables into x
void FromX(double *x)
copy new values from x to into this->m_imgs
std::set< unsigned > imgs
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.