24 #ifndef VIGRA_EXT_VIGNETTING_CORRECTION_H
25 #define VIGRA_EXT_VIGNETTING_CORRECTION_H
29 #include "hugin_config.h"
31 #include <vigra/stdimage.hxx>
32 #include <vigra/transformimage.hxx>
33 #include <vigra/inspectimage.hxx>
34 #include <vigra/combineimages.hxx>
35 #include <vigra/functorexpression.hxx>
45 template <
class VT1,
class VT2,
class InvResp,
class Adjust>
59 typedef typename vigra::NumericTraits<VT1>::RealPromote
result_type;
62 typedef typename vigra::NumericTraits<VT2>::RealPromote
RVT2;
85 template <
class VT1,
class InvResp,
class VigFunc,
class Adjust>
95 typedef typename vigra::NumericTraits<VT1>::RealPromote
result_type;
118 template <
class VT1,
class VT2,
class InvResp,
class Adjust>
132 typedef typename vigra::NumericTraits<VT1>::RealPromote
result_type;
135 typedef typename vigra::NumericTraits<VT2>::RealPromote
RVT2;
154 template <
class VT1,
class InvResp,
class VigFunc,
class Adjust>
164 typedef typename vigra::NumericTraits<VT1>::RealPromote
result_type;
187 template <
int NTERMS=4>
194 for (
unsigned int i=0; i<NTERMS; i++)
m_coeff[i] = coeff[i];
200 double r2 = x*x + y*y;
202 for (
unsigned int i = 1; i < NTERMS; i++) {
221 typedef typename vigra::NumericTraits<T>::isIntegral is_integral;
245 std::mt19937 &mt =
const_cast<std::mt19937 &
>(
Twister);
246 double vFraction = v - floor(v);
248 if (vFraction > 0.25 && vFraction <= 0.75) {
250 double random = 0.5 * (double)mt() / UINT_MAX;
251 if ((vFraction - 0.25) >= random) {
262 T
dither(
const T &v, vigra::VigraFalseType)
const
265 for (
size_t i=0; i < v.size(); i++) {
272 T
dither(
const T & v, vigra::VigraTrueType)
const
279 typedef typename vigra::NumericTraits<T>::isScalar is_scalar;
281 return dither(v, is_scalar());
296 typename vigra::NumericTraits<T>::RealPromote
operator()(T p)
const
298 typedef typename vigra::NumericTraits<T>::RealPromote RT;
327 template <
class SrcImageIterator,
class SrcAccessor,
328 class DestImageIterator,
class DestAccessor,
class Functor>
331 vigra::pair<DestImageIterator, DestAccessor> dest,
332 double cx,
double cy,
339 template <
class SrcImageIterator,
class SrcAccessor,
340 class DestImageIterator,
class DestAccessor,
class Functor>
343 SrcImageIterator src_lowerright, SrcAccessor sa,
344 DestImageIterator dest_upperleft, DestAccessor da,
345 double cx,
double cy,
348 vigra::Diff2D destSize = src_lowerright - src_upperleft;
350 double sf = 1.0/sqrt(destSize.x/2.0*destSize.x/2.0 + destSize.y/2.0*destSize.y/2.0);
351 double ynorm = -cy * sf;
353 for(; src_upperleft.y < src_lowerright.y; ++src_upperleft.y, ++dest_upperleft.y)
355 typename SrcImageIterator::row_iterator s(src_upperleft.rowIterator());
356 typename SrcImageIterator::row_iterator send(s+ destSize.x);
357 typename DestImageIterator::row_iterator d(dest_upperleft.rowIterator());
358 double xnorm = -cx*sf;
359 for(; s != send; ++s, ++d) {
360 da.set(f(sa(s), xnorm, ynorm), d);
371 template <
class SrcImageIterator,
class SrcAccessor,
372 class DestImageIterator,
class DestAccessor,
class Functor>
375 vigra::pair<DestImageIterator, DestAccessor> dest,
376 double cx,
double cy,
377 Functor
const & f,
bool dither)
394 template <
class ImgIter,
class ImgAccessor,
395 class FFIter,
class FFAccessor,
396 class DestIter,
class DestAccessor,
400 vigra::pair<FFIter, FFAccessor> ffImg,
401 vigra::pair<DestIter, DestAccessor> destImg,
402 Functor
const & f,
bool dither)
415 template <
class ImgIter,
class ImgAccessor,
class FFIter,
class FFAccessor,
class DestIter,
class DestAccessor>
417 vigra::pair<FFIter, FFAccessor> ffImg,
418 vigra::pair<DestIter, DestAccessor> destImg,
419 double gamma,
double gammaMaxVal,
bool division,
420 typename vigra::NumericTraits<typename ImgAccessor::value_type>::RealPromote a,
421 typename vigra::NumericTraits<typename ImgAccessor::value_type>::RealPromote b,
424 typedef typename ImgAccessor::value_type PT;
425 typedef typename vigra::NumericTraits<PT>::RealPromote RPT;
426 typedef typename FFAccessor::value_type FFT;
427 typedef typename vigra::NumericTraits<FFT>::RealPromote RFFT;
436 vigra::FindAverage<FFT> average;
437 vigra::inspectImage(ffImg.first, ffImg.first + (srcImg.second - srcImg.first), ffImg.second, average);
467 template <
class ImgIter,
class ImgAccessor,
class DestIter,
class DestAccessor>
469 vigra::pair<DestIter, DestAccessor> destImg,
double gamma,
double gammaMaxVal,
471 typename vigra::NumericTraits<typename ImgAccessor::value_type>::RealPromote a,
472 typename vigra::NumericTraits<typename ImgAccessor::value_type>::RealPromote b,
475 typedef typename ImgAccessor::value_type PT;
476 typedef typename vigra::NumericTraits<PT>::RealPromote RPT;
482 PolyF poly(radCoeff);
512 template <
class ImgIter,
class ImgAccessor,
class DestIter,
class DestAccessor>
514 vigra::pair<DestIter, DestAccessor> destImg,
515 typename vigra::NumericTraits<typename ImgAccessor::value_type>::RealPromote a,
516 typename vigra::NumericTraits<typename ImgAccessor::value_type>::RealPromote b)
518 typedef typename ImgAccessor::value_type PT;
519 typedef typename vigra::NumericTraits<PT>::RealPromote RPT;
525 template <
class ImgIter,
class ImgAccessor,
class DestIter,
class DestAccessor>
527 vigra::pair<DestIter, DestAccessor> destImg,
528 double gamma,
double maxGVal,
529 typename vigra::NumericTraits<typename ImgAccessor::value_type>::RealPromote a,
530 typename vigra::NumericTraits<typename ImgAccessor::value_type>::RealPromote b)
532 typedef typename ImgAccessor::value_type PT;
533 typedef typename vigra::NumericTraits<PT>::RealPromote RPT;
541 template <
class ImgIter,
class ImgAccessor,
class DestIter,
class DestAccessor>
543 vigra::pair<DestIter, DestAccessor> destImg,
544 double gamma,
double maxGVal)
611 #endif // VIGRA_EXT_VIGNETTING_CORRECTION_H
double operator()(double x, double y) const
VigCorrFlatDivFunctor(RVT2 mean, const InvResp &fr, const Adjust &adj)
void transformImage(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, vigra::triple< DestImageIterator, DestImageIterator, DestAccessor > dest, std::pair< AlphaImageIterator, AlphaAccessor > alpha, vigra::Diff2D destUL, TRANSFORM &transform, PixelTransform &pixelTransform, bool warparound, Interpolator interpol, AppBase::ProgressDisplay *progress, bool singleThreaded=false)
Transform an image into the panorama.
vigra::NumericTraits< T >::RealPromote operator()(T p) const
VigCorrDivFunctor(const InvResp &fr, const VigFunc &vf, const Adjust &adj)
vigra::NumericTraits< VT1 >::RealPromote result_type
the functor's result type
VT2 second_argument_type
the functor's second argument type
PolySqDistFunctor(const std::vector< double > &coeff)
void flatfieldVigCorrection(vigra::triple< ImgIter, ImgIter, ImgAccessor > srcImg, vigra::pair< FFIter, FFAccessor > ffImg, vigra::pair< DestIter, DestAccessor > destImg, double gamma, double gammaMaxVal, bool division, typename vigra::NumericTraits< typename ImgAccessor::value_type >::RealPromote a, typename vigra::NumericTraits< typename ImgAccessor::value_type >::RealPromote b, bool dither)
void radialVigCorrection(vigra::triple< ImgIter, ImgIter, ImgAccessor > srcImg, vigra::pair< DestIter, DestAccessor > destImg, double gamma, double gammaMaxVal, const std::vector< double > &radCoeff, hugin_utils::FDiff2D center, bool division, typename vigra::NumericTraits< typename ImgAccessor::value_type >::RealPromote a, typename vigra::NumericTraits< typename ImgAccessor::value_type >::RealPromote b, bool dither)
result_type operator()(first_argument_type const &v1, float x, float y) const
calculate transform.
vigra::NumericTraits< VT2 >::RealPromote RVT2
VT1 first_argument_type
the functor's first argument type
T dither(const T &v, vigra::VigraTrueType) const
functions to manage ROI's
result_type operator()(first_argument_type const &v1, float x, float y) const
calculate transform.
void combineTwoImages(SrcImageIterator1 src1_upperleft, SrcImageIterator1 src1_lowerright, SrcAccessor1 src1_acc, SrcImageIterator2 src2_upperleft, SrcAccessor2 src2_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc, const Functor &func)
VT1 first_argument_type
the functor's first argument type
float pow(float a, double b)
double dither(const double &v) const
VT1 first_argument_type
the functor's first argument type
VT2 second_argument_type
the functor's second argument type
T dither(const T &v, vigra::VigraFalseType) const
functor to combine two functors: result = f1( f2(v) )
void applyGammaCorrection(vigra::triple< ImgIter, ImgIter, ImgAccessor > srcImg, vigra::pair< DestIter, DestAccessor > destImg, double gamma, double maxGVal)
void applyBrightnessCorrection(vigra::triple< ImgIter, ImgIter, ImgAccessor > srcImg, vigra::pair< DestIter, DestAccessor > destImg, typename vigra::NumericTraits< typename ImgAccessor::value_type >::RealPromote a, typename vigra::NumericTraits< typename ImgAccessor::value_type >::RealPromote b)
result_type operator()(first_argument_type const &v1, second_argument_type const &v2) const
calculate transform.
VigCorrFlatAddFunctor(const InvResp &fr, const Adjust &adj)
void combineTwoImagesDither(vigra::triple< ImgIter, ImgIter, ImgAccessor > srcImg, vigra::pair< FFIter, FFAccessor > ffImg, vigra::pair< DestIter, DestAccessor > destImg, Functor const &f, bool dither)
Apply combine two images.
VT1 first_argument_type
the functor's first argument type
vigra::NumericTraits< VT1 >::RealPromote result_type
the functor's result type
GammaFunctor(double g, double m)
result_type operator()(first_argument_type const &v1, second_argument_type const &v2) const
calculate transform.
bool isTrueType(vigra::VigraFalseType)
VigCorrAddFunctor(const InvResp &fr, const VigFunc &vf, const Adjust &adj)
T operator()(const T &v) const
Dither code taken from enblend and adapted to a standalone functor.
vigra::NumericTraits< VT1 >::RealPromote result_type
the functor's result type
vigra::NumericTraits< VT2 >::RealPromote RVT2
bool ditheringNeeded(T const &)
void applyGammaAndBrightCorrection(vigra::triple< ImgIter, ImgIter, ImgAccessor > srcImg, vigra::pair< DestIter, DestAccessor > destImg, double gamma, double maxGVal, typename vigra::NumericTraits< typename ImgAccessor::value_type >::RealPromote a, typename vigra::NumericTraits< typename ImgAccessor::value_type >::RealPromote b)
void applyRadialVigCorrectionDither(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, vigra::pair< DestImageIterator, DestAccessor > dest, double cx, double cy, Functor const &f, bool dither)
Apply flatfield correction with dithering.
void applyRadialVigCorrection(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, vigra::pair< DestImageIterator, DestAccessor > dest, double cx, double cy, Functor const &f)
vigra::NumericTraits< VT1 >::RealPromote result_type
the functor's result type