24 #ifndef _VIGRA_EXT_LUT_H
25 #define _VIGRA_EXT_LUT_H
32 #include <vigra/stdimage.hxx>
33 #include <vigra/numerictraits.hxx>
37 #include <vigra/array_vector.hxx>
49 template <
class VECTOR>
52 typedef typename VECTOR::value_type VT;
56 for (
size_t i=0; i<lut.size(); ++i) {
57 double x = i*1.0/(lut.size() -1);
58 lut[i] = vigra::NumericTraits<VT>::fromRealPromote(
pow(x, gamma)*s);
63 template <
class VEC,
class VEC2>
69 for(
size_t oIdx = 0; oIdx < oLUT.size(); oIdx++) {
70 double ix = oIdx/(oLUT.size()-1.0) * (iLUT.size()-1);
71 unsigned iIdx = unsigned(ix);
72 double deltaix = ix-iIdx;
75 oLUT[oIdx] = iLUT[iIdx];
76 }
else if (iIdx+1 <= iLUT.size()){
78 oLUT[oIdx] = (1-deltaix) * iLUT[iIdx] + deltaix * iLUT[iIdx+1];
80 oLUT[oIdx] = iLUT.back();
89 typedef typename LUT::value_type lut_type;
90 int lutsize = lut.size();
93 lut_type
max = lut.back();
94 for (
int j=0; j < lutsize-1; j++)
98 }
else if (lut[j+1] < lut[j]) {
117 template <
class VTIn,
class LUT>
152 assert(!
m_lut.empty());
158 double x=v/m*(
m_lut.size()-1);
159 unsigned i = unsigned(x);
161 if ( x != 0 && i+1 <
m_lut.size()) {
172 assert(!
m_lut.empty());
173 if (v > 1)
return m_lut.back();
175 double x=v*(
m_lut.size()-1);
176 unsigned i = unsigned(x);
179 if ( i+1 <
m_lut.size()) {
181 return vigra::NumericTraits<lut_type>::fromRealPromote((1-x)*
m_lut[i]+x*
m_lut[i+1]);
188 vigra::RGBValue<lut_type>
applyVector( vigra::RGBValue<VT1> v, vigra::VigraFalseType)
const
190 vigra::RGBValue<VT1> ret;
191 for (
size_t i=0; i < v.size(); i++) {
198 vigra::RGBValue<lut_type>
applyVector(vigra::RGBValue<VT1> v, vigra::VigraTrueType)
const
200 assert(!
m_lut.empty());
201 vigra::RGBValue<lut_type> ret;
202 for (
size_t i=0; i < v.size(); i++) {
222 typedef typename vigra::NumericTraits<VT1>::isIntegral isIntegral;
226 vigra::RGBValue<lut_type>
apply(vigra::RGBValue<VT1> v, vigra::VigraFalseType)
const
228 typedef typename vigra::NumericTraits<VT1>::isIntegral isIntegral;
233 typename vigra::NumericTraits<T>::RealPromote
operator()(T v)
const
235 typedef typename vigra::NumericTraits<T>::isScalar is_scalar;
236 return apply(v, is_scalar());
251 template <
class VT1,
class LUT>
277 assert(!
m_lut.empty());
279 if (v <
m_lut[0])
return 0;
282 typename LUT::const_iterator p = lower_bound(
m_lut.begin(),
m_lut.end(), v);
285 int x = p-
m_lut.begin();
294 }
else if (v == *p) {
295 return x/(
m_lut.size()-1.0);
299 double lower = *(p-1);
301 lut_type delta = (v - lower) / (upper - lower);
302 return (x-1 + delta) / (
m_lut.size()-1.0);
316 vigra::RGBValue<lut_type>
applyVector( vigra::RGBValue<T> v, vigra::VigraFalseType)
const
318 vigra::RGBValue<VT1> ret;
319 for (
size_t i=0; i < v.size(); i++) {
326 vigra::RGBValue<lut_type>
applyVector(vigra::RGBValue<T> v, vigra::VigraTrueType)
const
328 vigra::RGBValue<lut_type> ret;
329 for (
size_t i=0; i < v.size(); i++) {
352 typedef typename vigra::NumericTraits<T>::isIntegral isIntegral;
357 vigra::RGBValue<lut_type>
apply(vigra::RGBValue<T> v, vigra::VigraFalseType)
const
359 typedef typename vigra::NumericTraits<T>::isIntegral isIntegral;
364 typename vigra::NumericTraits<T>::RealPromote
operator()(T v)
const
366 typedef typename vigra::NumericTraits<T>::isScalar is_scalar;
367 return apply(v, is_scalar());
379 :
op(operation),
e(exposure)
388 typename vigra::NumericTraits<VT>::RealPromote
LUT::value_type lut_type
the functor's first argument type
vigra::RGBValue< lut_type > applyVector(vigra::RGBValue< VT1 > v, vigra::VigraTrueType) const
lut_type applyScalar(T v, vigra::VigraFalseType) const
lut_type apply(VT1 v, vigra::VigraTrueType) const
lut_type applyScalar(VT1 v, vigra::VigraTrueType) const
void resizeLUT(const VEC &iLUT, VEC2 &oLUT)
misc math function & classes used by other parts of the program
vigra::RGBValue< lut_type > applyVector(vigra::RGBValue< VT1 > v, vigra::VigraFalseType) const
ExposureResponseFunctor(double exposure, OP &operation)
lut_type applyScalar(VT1 v, vigra::VigraFalseType) const
void enforceMonotonicity(LUT &lut)
enforce monotonicity of an array (mostly used for lookup tables)
LUTFunctor()
the functor's result type
functor to apply a LUT to gray and color images.
functions to manage ROI's
functor to apply a LUT to gray and color images.
vigra::RGBValue< lut_type > applyVector(vigra::RGBValue< T > v, vigra::VigraTrueType) const
lut_type applyScalar(T v, vigra::VigraTrueType) const
LUT::value_type lut_type
the functor's first argument type
just apply exposure and response to linear data
float pow(float a, double b)
vigra_ext::ValueTypeTraits< VTIn >::value_type VT1
vigra::NumericTraits< VT >::RealPromote operator()(VT v)
vigra::NumericTraits< T >::RealPromote operator()(T v) const
vigra::NumericTraits< T >::RealPromote operator()(T v) const
LUTFunctor(LUT &lut)
create a LUT functor.
lut_type applyLutFloat(lut_type v) const
lut_type applyLutFloat(double v) const
vigra::RGBValue< lut_type > apply(vigra::RGBValue< T > v, vigra::VigraFalseType) const
void createGammaLUT(double gamma, VECTOR &lut)
InvLUTFunctor()
the functor's result type
InvLUTFunctor(LUT &lut)
create a LUT functor.
T1::value_type value_type
lut_type applyLutInteger(VT1 v) const
lut_type apply(T v, vigra::VigraTrueType) const
vigra::RGBValue< lut_type > applyVector(vigra::RGBValue< T > v, vigra::VigraFalseType) const
lut_type applyLutInteger(T i) const
vigra::RGBValue< lut_type > apply(vigra::RGBValue< VT1 > v, vigra::VigraFalseType) const