26#ifndef VIGRA_EXT_UTILS_H
27#define VIGRA_EXT_UTILS_H
30#include <vigra/rgbvalue.hxx>
31#include <vigra/transformimage.hxx>
32#include <vigra/codec.hxx>
37template <
class T1,
unsigned int R,
unsigned int G,
unsigned int B,
class T2>
49#define LUT_TRAITS(T1, Smin, Smax) \
63struct LUTTraits<vigra::RGBValue<T1> > \
93 }
else if (
v ==
"INT8") {
95 }
else if (
v ==
"UINT16") {
97 }
else if (
v ==
"INT16") {
99 }
else if (
v ==
"UINT32") {
101 }
else if (
v ==
"INT32") {
107template <
class VALUE>
136#define VT_TRAITS_VEC(T1) \
138struct ValueTypeTraits<vigra::RGBValue<T1, 0u, 1u, 2u> > \
140 typedef vigra::RGBValue<T1, 0u, 1u, 2u>::value_type value_type; \
143#define VT_TRAITS(T1) \
145struct ValueTypeTraits<T1> \
147 typedef T1 value_type; \
178using VIGRA_CSTD::pow;
179using VIGRA_CSTD::log;
181inline float pow(
float a,
double b)
183 return std::pow(a,(
float) b);
187template <
class T,
unsigned int R,
unsigned int G,
unsigned int B>
189vigra::RGBValue<T, R, G, B>
pow(vigra::RGBValue<T, R, G, B>
const &
v,
double e) {
190 return vigra::RGBValue<T, R, G, B>(
pow(
v.red(),e),
pow(
v.green(),e),
pow(
v.blue(),e));
194template <
class V1,
unsigned int R,
unsigned int G,
unsigned int B,
class V2>
196vigra::RGBValue<V1, R, G, B> &
206template <
class T,
unsigned int RIDX,
unsigned int GIDX,
unsigned int BIDX>
208vigra::RGBValue<T, RIDX, GIDX, BIDX>
209log(vigra::RGBValue<T, RIDX, GIDX, BIDX>
const &
v)
211 return vigra::RGBValue<T, RIDX, GIDX, BIDX>(std::log(
v.red()), std::log(
v.green()), std::log(
v.blue()));
215template <
class T,
unsigned int RIDX,
unsigned int GIDX,
unsigned int BIDX>
217vigra::RGBValue<T, RIDX, GIDX, BIDX>
218log10(vigra::RGBValue<T, RIDX, GIDX, BIDX>
const &
v)
220 return vigra::RGBValue<T, RIDX, GIDX, BIDX>(std::log10(
v.red()), std::log10(
v.green()), std::log10(
v.blue()));
224template <
class V1,
unsigned int R,
unsigned int G,
unsigned int B,
class V2>
228typename vigra::PromoteTraits<vigra::RGBValue<V1, R, G, B>,
V2 >::Promote
231 typename vigra::PromoteTraits<vigra::RGBValue<V1, R, G, B>,
V2 >::Promote res(r1);
240template <
class V,
int SIZE,
class D1,
class D2>
242vigra::TinyVector<V, SIZE>
243pow(vigra::TinyVector<V, SIZE>
const &
v,
double e)
245 vigra::TinyVector<V, SIZE> res;
246 for (
int i=0;
i<SIZE;
i++)
247 res[
i] = std::pow(
v[
i], e);
253template <
class V,
int SIZE,
class D1,
class D2>
255vigra::TinyVector<V, SIZE>
256log(vigra::TinyVector<V, SIZE>
const &
v,
double e)
258 vigra::TinyVector<V, SIZE> res;
259 for (
int i=0;
i<SIZE;
i++)
260 res[
i] = std::log(
v[
i], e);
270 return std::max(std::max(
v.red(),
v.green()),
v.blue());
288 return std::min(std::min(
v.red(),
v.green()),
v.blue());
300template <
class VALUETYPE>
369template<
class ImgIter,
class ImgAccessor,
class AlphaIter,
class AlphaAccessor>
373 vigra_precondition((image.second - image.first) == (mask.second - mask.first),
"applyExposureMask: image and mask have different sizes");
374 const vigra::Diff2D
imgSize = image.second - image.first;
406 template<
typename PIXEL>
409 if (img1 > 0 && img2 > 0) {
430template <
class F1,
class F2>
450 template <
class T1,
class T2>
457 template <
class T1,
class T2,
class T3>
472 template<
typename PIXEL>
494template <
class SrcImageIterator,
class SrcAccessor>
495void circularCrop(vigra::triple<SrcImageIterator, SrcImageIterator, SrcAccessor> img,
498 vigra::Diff2D
imgSize = img.second - img.first;
499 double r2 = radius*radius;
512 if (dx*dx+dy*dy > r2) {
536 template <
class T2,
class A>
550typename vigra::NumericTraits<T>::RealPromote
553 return vigra::NumericTraits<T>::toRealPromote(
v) / vigra::NumericTraits<T>::max();
557typename vigra::NumericTraits<T>::RealPromote
565template <
class DestValueType>
583 template <
class SrcValueType>
586 return vigra::NumericTraits<result_type>::fromRealPromote(
scale_ * (vigra::NumericTraits<SrcValueType>::toRealPromote(
s) +
offset_));
608 maxv = std::log10(max_);
615 typedef vigra::NumericTraits<vigra::UInt8>
DestTraits;
616 return DestTraits::fromRealPromote((std::log10(
float(
v))-
minv)/
scale);
619 template <
class T,
unsigned int R,
unsigned int G,
unsigned int B>
620 vigra::RGBValue<vigra::UInt8,0,1,2>
operator()(
const vigra::RGBValue<T,R,G,B> &
v)
const
622 typedef vigra::NumericTraits< vigra::RGBValue<vigra::UInt8,0,1,2> >
DestTraits;
623 typedef vigra::NumericTraits< vigra::RGBValue<T,R,G,B> >
SrcTraits;
624 return DestTraits::fromRealPromote((
log10(SrcTraits::toRealPromote(
v)) + (-
minv))/
scale);
629template <
class TIn,
class TOut=vigra::UInt8>
647 typedef vigra::NumericTraits<TOut>
DestTraits;
651 vigra::RGBValue<TOut>
operator()(
const vigra::RGBValue<TIn> &
v)
const
653 typedef vigra::NumericTraits< vigra::RGBValue<TOut> >
DestTraits;
654 typedef vigra::NumericTraits< vigra::RGBValue<TIn> >
SrcTraits;
663 vigra::UInt8 lut[65536];
668 for (
int i=0;
i<65536;
i++) {
678 vigra::RGBValue<vigra::UInt8>
operator()(
const vigra::RGBValue<vigra::UInt16> &
v)
const
680 return vigra::RGBValue<vigra::UInt8>(lut[
v[0]], lut[
v[1]], lut[
v[2]]);
684template <
class SrcIterator,
class SrcAccessor,
class DestIterator,
class DestAccessor,
class T>
685 void applyMapping(vigra::triple<SrcIterator, SrcIterator, SrcAccessor> img,
686 vigra::pair<DestIterator, DestAccessor>
dest, T min, T max,
int mapping )
694 float offset_ = -
float(min);
696 vigra::transformImage(img,
dest,
735 typename SrcImageIterator::row_iterator
s(
src_upperleft.rowIterator());
737 typename DestImageIterator::row_iterator
d(
dest_upperleft.rowIterator());
749 vigra::pair<DestImageIterator, DestAccessor>
dest,
756template <
class ImageType>
759 typedef vigra::NumericTraits<typename ImageType::PixelType>
DestTraits;
760 double maxVal = vigra::NumericTraits<typename DestTraits::ValueType>::max();
761 double minVal = vigra::NumericTraits<typename DestTraits::ValueType>::min();
762 const std::string
pixelType = vigra::TypeAsString<typename DestTraits::ValueType>::result();
766 vigra::FindMinMax<typename ImageType::PixelType>
minmax;
FindComponentsMinMax()
init min and max
void reset()
(re-)init functor (clear min, max)
void operator()(argument_type const &v)
update min and max
VALUETYPE argument_type
the functor's argument type
unsigned int count
the number of values processed so far
VALUETYPE max
the current max
VALUETYPE result_type
the functor's result type
void operator()(vigra::RGBValue< VALUETYPE > const &v)
update min and max with components of RGBValue<VALUETYPE>
VALUETYPE min
the current min
vigra::FRGBImage ImageType
misc math function & classes used by other parts of the program
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.
V getMaxComponent(vigra::RGBValue< V > const &v)
get the maximum component of a vector (also works for single pixel types...)
vigra::RGBValue< V1, R, G, B > & operator+=(vigra::RGBValue< V1, R, G, B > &l, V2 const &r)
add a scalar to all components
vigra::NumericTraits< T >::RealPromote normalizeValue(T v, vigra::VigraTrueType)
normalize a pixel to 0..1 Only has an effect on integer pixel types
PointPairT< float > PointPair
void ConvertTo8Bit(ImageType &image)
converts to given image to fit into 0..255
vigra::pair< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImage(ROIImage< Image, Alpha > &img)
void transformImageSpatial(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor sa, DestImageIterator dest_upperleft, DestAccessor da, Functor const &f, vigra::Diff2D ul)
V getMinComponent(vigra::RGBValue< V > const &v)
get the maximum component of a vector (also works for single pixel types...)
static const double A(-0.75)
float pow(float a, double b)
vigra::triple< typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::ImageConstAccessor > srcImageRange(const ROIImage< Image, Mask > &img)
helper function for ROIImages
vigra::RGBValue< T, RIDX, GIDX, BIDX > log(vigra::RGBValue< T, RIDX, GIDX, BIDX > const &v)
component-wise logarithm
double getMaxValForPixelType(const std::string &v)
void applyExposureClipMask(vigra::triple< ImgIter, ImgIter, ImgAccessor > image, vigra::triple< AlphaIter, AlphaIter, AlphaAccessor > mask, double lowerLimit, double upperLimit)
void applyMapping(vigra::triple< SrcIterator, SrcIterator, SrcAccessor > img, vigra::pair< DestIterator, DestAccessor > dest, T min, T max, int mapping)
PointPairT< vigra::RGBValue< float > > PointPairRGB
void circularCrop(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > img, hugin_utils::FDiff2D middle, double radius)
Apply a circular crop to img.
vigra::PromoteTraits< vigra::RGBValue< V1, R, G, B >, V2 >::Promote operator+(vigra::RGBValue< V1, R, G, B > const &r1, V2 const &r2)
add a scalar to all components
vigra::RGBValue< T, RIDX, GIDX, BIDX > log10(vigra::RGBValue< T, RIDX, GIDX, BIDX > const &v)
component-wise logarithm
Implementation of fast vector type with support of linear algebra operations Copyright (C) 2009 Lukáš...
vigra::RGBValue< vigra::UInt8 > operator()(const vigra::RGBValue< vigra::UInt16 > &v) const
ApplyGammaFunctor(vigra::UInt16 min, vigra::UInt16 max, float gamma)
vigra::UInt8 operator()(vigra::UInt16 v) const
ApplyGammaFunctor(TIn min_, TIn max_, float gamma_)
TOut operator()(TIn v) const
vigra::RGBValue< TOut > operator()(const vigra::RGBValue< TIn > &v) const
unsigned char operator()(T v) const
vigra::RGBValue< vigra::UInt8, 0, 1, 2 > operator()(const vigra::RGBValue< T, R, G, B > &v) const
ApplyLogFunctor(float min_, float max_)
count pixels that are > 0 in a single image
void operator()(PIXEL const &img1)
functor to combine two functors: result = f1( f2(v) )
result_type operator()(T1 const &v) const
result_type operator()(T1 const &v1, T2 const &v2, T3 const &v3) const
if F2 takes 3 arguments
F1::result_type result_type
the functor's second argument type
result_type operator()(T1 const &v1, T2 const &v2) const
if F2 takes 2 arguments
NestFunctor(const F1 &fu1, const F2 &fu2)
count pixels that are > 0 in both images
void operator()(PIXEL const &img1, PIXEL const &img2)
T2 operator()(const T2 &a, const hugin_utils::FDiff2D &p) const
A hdrWeight(T2 v, A a) const
T operator()(const T &a) const
PointPairT(short img1, VALUE val1, const hugin_utils::FDiff2D &p1, float r1, short img2, VALUE val2, const hugin_utils::FDiff2D &p2, float r2)
T1::value_type value_type
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.
#define VT_TRAITS_VEC(T1)
#define LUT_TRAITS(T1, Smin, Smax)
Traits to define the maximum value for all types.