27#include <foreign/levmar/levmar.h>
33#define DEBUG_LOG_VIG 1
51 const std::vector<vigra_ext::PointPairRGB> & data,
66 for (
unsigned i=0;
i < optvars.size();
i++)
68 const std::set<std::string> vars = optvars[
i];
70 for (std::set<std::string>::const_iterator
it = vars.begin();
71 it != vars.end(); ++
it)
81#define CheckLinked(name)\
82 if(img_i.name##isLinked())\
84 for(unsigned j=i+1;j<pano.getNrOfImages();j++)\
85 if(img_i.name##isLinkedWith(pano.getImage(j)))\
88 usedVars[j].insert(var.type);\
112 if(var.
type==
"Vx" || var.
type==
"Vy")
124 for (
size_t i=0;
i < m_vars.size();
i++)
126 assert(!m_vars[
i].imgs.empty());
128 unsigned j = *(m_vars[
i].imgs.begin());
130 x[
i] = m_imgs[
j].getVar(m_vars[
i].type);
138 for (
size_t i=0;
i < m_vars.size();
i++)
141 assert(!m_vars[
i].imgs.empty());
143 for (std::set<unsigned>::const_iterator
it = m_vars[
i].imgs.begin();
144 it != m_vars[
i].imgs.end(); ++
it)
146 m_imgs[*
it].setVar(m_vars[
i].type, x[
i]);
166 std::ostringstream
oss;
169 std::ofstream log(
oss.str().c_str());
170 log <<
"VIGparams = [";
171 for (
int i = 0;
i < m;
i++) {
174 log <<
" ]; " << std::endl;
176 std::ofstream
script(
"vig_test.pto");
179 dat->m_pano.printPanoramaScript(
script, optvars,
dat->m_pano.getOptions(), imgs,
false,
"");
182 size_t nImg =
dat->m_imgs.size();
185 for (
size_t i=0;
i <
nImg;
i++) {
203 resp[
i].enforceMonotonicity();
212 log <<
"VIGval = [ ";
215 for (std::vector<vigra_ext::PointPairRGB>::const_iterator
it =
dat->m_data.begin();
220 vigra::RGBValue<double> error =
it->i1 -
i2ini1;
230 for (
int i=0;
i < 3;
i++) {
237 if (
dat->huberSigma > 0) {
238 for (
int i=0;
i < 3;
i++) {
252 log <<
it->i1.green() <<
" "<<
l1.green() <<
" " <<
i1ini2.green() <<
" "
253 <<
it->i2.green() <<
" "<<
l2.green() <<
" " <<
i2ini1.green() <<
"; " << std::endl;
258 log << std::endl <<
"VIGerr = [";
259 for (
int i = 0;
i <
n;
i++) {
260 log << x[
i] << std::endl;
262 log <<
" ]; " << std::endl;
275 snprintf(tmp,199,
"Iteration: %d, error: %f",
iter, error);
276 return dat->m_progress->updateDisplay(std::string(tmp)) ? 1 : 0 ;
289 for (OptimizeVector::const_iterator
it=vars.begin();
it != vars.end(); ++
it)
291 std::set<std::string>
cvars;
292 for (std::set<std::string>::const_iterator
itv = (*it).begin();
293 itv != (*it).end(); ++
itv)
295 if ((*
itv)[0] ==
'E' || (*itv)[0] ==
'R' || (*itv)[0] ==
'V') {
315 vigra::ArrayVector<double> p(m, 0.0);
319 vigra::ArrayVector<double> x(
n, 0.0);
323 printf(
"Parameters before optimisation: ");
324 for(
int i=0;
i<m; ++
i)
340 dlevmar_dif(&
photometricError, &
photometricVis, &(p[0]), &(x[0]), m,
n,
nMaxIter,
optimOpts, info,
NULL,
NULL, &data);
343 data.
FromX(p.begin());
348 for (
int i=0;
i<
n;
i++) {
351 error =
sqrt(error/
n);
354 printf(
"Levenberg-Marquardt returned in %g iter, reason %g\nSolution: ", info[5], info[6]);
355 for(
int i=0;
i<m; ++
i)
357 printf(
"\n\nMinimization info:\n");
372 srcImage.setRadialVigCorrCoeff(
vigCorr);
373 srcImage.setSize(vigra::Size2D(500, 500));
375 for (
size_t x = 0; x < 250; x += 10)
390 if(pano.
getImage(
i).getWhiteBalanceBlue()>3)
394 if(pano.
getImage(
i).getWhiteBalanceRed()>3)
419 for (
auto img = ++stacks[0].begin(); img != stacks[0].end(); ++img)
431 if (mode == OPT_PHOTOMETRIC_LDR || mode == OPT_PHOTOMETRIC_LDR_WB)
460 if (mode == OPT_PHOTOMETRIC_LDR_WB || mode == OPT_PHOTOMETRIC_HDR_WB)
definitions of classes to calculate overlap between different images
declaration of functions to handle stacks and layers
#define CheckLinked(name)
@ RESPONSE_EMOR
empirical model of response
class for calculating overlap of images
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.