27#ifndef VIGRA_EXT_INTERPOLATORS_H
28#define VIGRA_EXT_INTERPOLATORS_H
37#include <vigra/accessor.hxx>
38#include <vigra/diff2d.hxx>
46static double sinc (
double x );
47static double cubic01 (
double x );
48static double cubic12 (
double x );
50static double sinc(
double x )
62static const double A(-0.75);
67 return ((
A + 2.0 )*x - (
A + 3.0 ))*x*x +1.0;
73 return ((
A * x - 5.0 *
A ) * x + 8.0 *
A ) * x - 4.0 *
A;
108 w[1] = (x >= 0.5) ? 1 : 0;
109 w[0] = (x < 0.5) ? 1 : 0;
113 oss <<
" return (i == 0.0) ? float(f < 0.5) : float(f >= 0.5);" << endl;
131 oss <<
" return abs(i + f - 1.0);" << endl;
151 oss <<
" float A = " <<
A <<
";" << endl
152 <<
" float c = abs(i - 1.0);" << endl
153 <<
" float m = (i > 1.0) ? -1.0 : 1.0;" << endl
154 <<
" float p = c + m * f;" << endl
155 <<
" if (i == 1.0 || i == 2.0) {" << endl
156 <<
" return (( A + 2.0 )*p - ( A + 3.0 ))*p*p + 1.0;" << endl
157 <<
" } else {" << endl
158 <<
" return (( A * p - 5.0 * A ) * p + 8.0 * A ) * p - 4.0 * A;" << endl
172 w[3] = ( ( 1.0/3.0 * x - 1.0/5.0 ) * x - 2.0/15.0 ) * x;
173 w[2] = ( ( 6.0/5.0 - x ) * x + 4.0/5.0 ) * x;
174 w[1] = ( ( x - 9.0/5.0 ) * x - 1.0/5.0 ) * x + 1.0;
175 w[0] = ( ( -1.0/3.0 * x + 4.0/5.0 ) * x - 7.0/15.0 ) * x;
179 oss <<
" return (i > 1.0) ? (i == 3.0) ? (( ( 1.0/3.0 * f - 1.0/5.0 ) * f - 2.0/15.0 ) * f)" << endl
180 <<
" : (( ( 6.0/5.0 - f ) * f + 4.0/5.0 ) * f)" << endl
181 <<
" : (i == 1.0) ? (( ( f - 9.0/5.0 ) * f - 1.0/5.0 ) * f + 1.0)" << endl
182 <<
" : (( ( -1.0/3.0 * f + 4.0/5.0 ) * f - 7.0/15.0 ) * f);" << endl;
200 w[5] = ( ( - 1.0/11.0 * x + 12.0/ 209.0 ) * x + 7.0/ 209.0 ) * x;
201 w[4] = ( ( 6.0/11.0 * x - 72.0/ 209.0 ) * x - 42.0/ 209.0 ) * x;
202 w[3] = ( ( - 13.0/11.0 * x + 288.0/ 209.0 ) * x + 168.0/ 209.0 ) * x;
203 w[2] = ( ( 13.0/11.0 * x - 453.0/ 209.0 ) * x - 3.0/ 209.0 ) * x + 1.0;
204 w[1] = ( ( - 6.0/11.0 * x + 270.0/ 209.0 ) * x - 156.0/ 209.0 ) * x;
205 w[0] = ( ( 1.0/11.0 * x - 45.0/ 209.0 ) * x + 26.0/ 209.0 ) * x;
209 oss <<
" return (i > 3.0) ? (i == 5.0) ? (( ( - 1.0/11.0 * f + 12.0/ 209.0 ) * f + 7.0/ 209.0 ) * f)" << endl
210 <<
" : (( ( 6.0/11.0 * f - 72.0/ 209.0 ) * f - 42.0/ 209.0 ) * f)" << endl
211 <<
" : (i > 1.0) ? (i == 3.0) ? (( ( - 13.0/11.0 * f + 288.0/ 209.0 ) * f + 168.0/ 209.0 ) * f)" << endl
212 <<
" : (( ( 13.0/11.0 * f - 453.0/ 209.0 ) * f - 3.0/ 209.0 ) * f + 1.0)" << endl
213 <<
" : (i == 1.0) ? (( ( - 6.0/11.0 * f + 270.0/ 209.0 ) * f - 156.0/ 209.0 ) * f)" << endl
214 <<
" : (( ( 1.0/11.0 * f - 45.0/ 209.0 ) * f + 26.0/ 209.0 ) * f);" << endl;
228 w[7] = (( 1.0/41.0 * x - 45.0/2911.0) * x - 26.0/2911.0) * x;
229 w[6] = ((- 6.0/41.0 * x + 270.0/2911.0) * x + 156.0/2911.0) * x;
230 w[5] = (( 24.0/41.0 * x - 1080.0/2911.0) * x - 624.0/2911.0) * x;
231 w[4] = ((-49.0/41.0 * x + 4050.0/2911.0) * x + 2340.0/2911.0) * x;
232 w[3] = (( 49.0/41.0 * x - 6387.0/2911.0) * x - 3.0/2911.0) * x + 1.0;
233 w[2] = ((-24.0/41.0 * x + 4032.0/2911.0) * x - 2328.0/2911.0) * x;
234 w[1] = (( 6.0/41.0 * x - 1008.0/2911.0) * x + 582.0/2911.0) * x;
235 w[0] = ((- 1.0/41.0 * x + 168.0/2911.0) * x - 97.0/2911.0) * x;
239 oss <<
" return (i > 3.0) ? (i > 5.0) ? (i == 7.0) ? ((( 1.0/41.0 * f - 45.0/2911.0) * f - 26.0/2911.0) * f)" << endl
240 <<
" : (((- 6.0/41.0 * f + 270.0/2911.0) * f + 156.0/2911.0) * f)" << endl
241 <<
" : (i == 5.0) ? ((( 24.0/41.0 * f - 1080.0/2911.0) * f - 624.0/2911.0) * f)" << endl
242 <<
" : (((-49.0/41.0 * f + 4050.0/2911.0) * f + 2340.0/2911.0) * f)" << endl
243 <<
" : (i > 1.0) ? (i == 3.0) ? ((( 49.0/41.0 * f - 6387.0/2911.0) * f - 3.0/2911.0) * f + 1.0)" << endl
244 <<
" : (((-24.0/41.0 * f + 4032.0/2911.0) * f - 2328.0/2911.0) * f)" << endl
245 <<
" : (i == 1.0) ? ((( 6.0/41.0 * f - 1008.0/2911.0) * f + 582.0/2911.0) * f)" << endl
246 <<
" : (((- 1.0/41.0 * f + 168.0/2911.0) * f - 97.0/2911.0) * f);" << endl;
277 oss <<
" float c = (i < " << (
size/2.0) <<
") ? 1.0 : -1.0;" << endl
278 <<
" float x = c * (" << (
size/2 - 1.0) <<
" - i + f);" << endl
279 <<
" vec2 xpi = vec2(x, x / " << (
size/2.0) <<
") * " <<
M_PI <<
";" << endl
280 <<
" vec2 xsin = sin(xpi);" << endl
281 <<
" vec2 result = vec2(1.0, 1.0);" << endl
282 <<
" if (xpi.x != 0.0) result.x = xsin.x / xpi.x;" << endl
283 <<
" if (xpi.y != 0.0) result.y = xsin.y / xpi.y;" << endl
284 <<
" return result.x * result.y;" << endl;
302 typedef typename vigra::NumericTraits<PixelType>::RealPromote
RealPixelType;
367 if (
srcx > INTERPOLATOR::size/2 &&
srcx <
m_w -INTERPOLATOR::size/2 &&
368 srcy > INTERPOLATOR::size/2 &&
srcy <
m_h - INTERPOLATOR::size/2)
373 double wx[INTERPOLATOR::size];
374 double wy[INTERPOLATOR::size];
380 RealPixelType p(vigra::NumericTraits<RealPixelType>::zero());
382 for (
int ky = 0;
ky < INTERPOLATOR::size;
ky++) {
390 for (
int kx = 0;
kx < INTERPOLATOR::size;
kx++) {
422 result = vigra::detail::RequiresExplicitCast<PixelType>::cast(p);
431 double w[INTERPOLATOR::size];
440 vigra::Diff2D offset(
srcx - INTERPOLATOR::size/2 + 1,
441 srcy - INTERPOLATOR::size/2 + 1);
443 for (
int ky = 0;
ky < INTERPOLATOR::size;
ky++, ++(
ys.y)) {
444 p = vigra::NumericTraits<RealPixelType>::zero();
445 typename SrcImageIterator::row_iterator
xs(
ys.rowIterator());
447 for (
int kx = 0;
kx < INTERPOLATOR::size;
kx++, ++
xs) {
455 p = vigra::NumericTraits<RealPixelType>::zero();
456 for (
int ky = 0;
ky < INTERPOLATOR::size;
ky++) {
460 result = vigra::detail::RequiresExplicitCast<PixelType>::cast(p);
483 typedef typename MaskAccessor::value_type
MaskType;
485 typedef typename vigra::NumericTraits<PixelType>::RealPromote
RealPixelType;
501 std::pair<MaskIterator, MaskAccessor> mask,
573 double w[INTERPOLATOR::size];
575 double weightsX[INTERPOLATOR::size];
583 for (
int ky = 0;
ky < INTERPOLATOR::size;
ky++) {
597 RealPixelType p(vigra::NumericTraits<RealPixelType>::zero());
600 for (
int kx = 0;
kx < INTERPOLATOR::size;
kx++) {
631 RealPixelType p(vigra::NumericTraits<RealPixelType>::zero());
633 for (
int ky = 0;
ky < INTERPOLATOR::size;
ky++) {
642 result = vigra::detail::RequiresExplicitCast<PixelType>::cast(p);
681 if (
srcx > INTERPOLATOR::size/2 &&
srcx <
m_w -INTERPOLATOR::size/2 &&
682 srcy > INTERPOLATOR::size/2 &&
srcy <
m_h - INTERPOLATOR::size/2)
687 double wx[INTERPOLATOR::size];
688 double wy[INTERPOLATOR::size];
696 RealPixelType p(vigra::NumericTraits<RealPixelType>::zero());
699 for (
int ky = 0;
ky < INTERPOLATOR::size;
ky++) {
707 for (
int kx = 0;
kx < INTERPOLATOR::size;
kx++) {
747 mask = vigra::detail::RequiresExplicitCast<MaskType>::cast(m);
748 result = vigra::detail::RequiresExplicitCast<PixelType>::cast(p);
758 double wx[INTERPOLATOR::size];
759 double wy[INTERPOLATOR::size];
765 RealPixelType p(vigra::NumericTraits<RealPixelType>::zero());
768 vigra::Diff2D offset(
srcx - INTERPOLATOR::size/2 + 1,
769 srcy - INTERPOLATOR::size/2 + 1);
772 for (
int ky = 0;
ky < INTERPOLATOR::size;
ky++, ++(
ys.y), ++(
yms.y)) {
774 typename SrcImageIterator::row_iterator
xs(
ys.rowIterator());
775 typename MaskIterator::row_iterator
xms(
yms.rowIterator());
776 for (
int kx = 0;
kx < INTERPOLATOR::size;
kx++, ++
xs, ++
xms) {
799 result = vigra::detail::RequiresExplicitCast<PixelType>::cast(p);
800 mask = vigra::detail::RequiresExplicitCast<MaskType>::cast(m);
861template <
class ACCESSOR,
class VALUETYPE,
class INTERPOLATOR>
891 template <
class ITERATOR>
898 double wx[INTERPOLATOR::size];
899 double wy[INTERPOLATOR::size];
902 typename vigra::NumericTraits<value_type>::RealPromote
903 ret (vigra::NumericTraits<value_type>::zero());
911 for(
int y = 0; y <
inter_y.size; ++y, ++
ys.y) {
913 for(
int x = 0; x <
inter_x.size; x++, ++
xs.x) {
917 return vigra::detail::RequiresExplicitCast<value_type>::cast(
ret);
941 template <
class ITERATOR,
class ALPHAITERATOR,
class ALPHAACCESSOR>
949 double wx[INTERPOLATOR::size];
950 double wy[INTERPOLATOR::size];
953 typename vigra::NumericTraits<value_type>::RealPromote
954 ret (vigra::NumericTraits<value_type>::zero());
964 for(
int y = 0; y <
inter_y.size; ++y, ++
ys.y, ++
ays.y) {
967 for(
int x = 0; x <
inter_x.size; x++, ++
xs.x, ++
axs.x) {
968 if (alpha.second(
axs) <= 0 ) {
974 result = vigra::detail::RequiresExplicitCast<value_type>::cast(
ret);
"wrapper" for efficient interpolation access to an image
bool operator()(double x, double y, PixelType &result, MaskType &mask) const
Interpolate without mask, but return dummy alpha value nevertheless.
ImageInterpolator(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor sa, INTERPOLATOR &inter, bool warparound)
Construct interpolator for specific image.
bool operator()(double x, double y, PixelType &result) const
Interpolate without mask.
ImageInterpolator(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > const &src, INTERPOLATOR &inter, bool warparound)
Construct interpolator for an given image.
vigra::NumericTraits< PixelType >::RealPromote RealPixelType
SrcAccessor::value_type PixelType
bool interpolateNoMaskInside(int srcx, int srcy, double dx, double dy, PixelType &result) const
Interpolate without boundary check and mask.
void emitGLSL(std::ostringstream &oss) const
"wrapper" for efficient interpolation access to an image
bool operator()(double x, double y, PixelType &result, MaskType &mask) const
Interpolate the data item at a non-integer position x, y.
MaskAccessor::value_type MaskType
bool interpolateInside(int srcx, int srcy, double dx, double dy, PixelType &result, MaskType &mask) const
Interpolate without boundary check.
ImageMaskInterpolator(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor sa, MaskIterator mask_upperleft, MaskAccessor ma, INTERPOLATOR &inter, bool warparound)
Construct interpolator for specific image.
ImageMaskInterpolator(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > const &src, std::pair< MaskIterator, MaskAccessor > mask, INTERPOLATOR &inter, bool warparound)
Construct interpolator for an given image.
vigra::NumericTraits< PixelType >::RealPromote RealPixelType
SrcAccessor::value_type PixelType
interpolation at non-integer positions.
VALUETYPE value_type
the iterators' pixel type
InterpolatingAccessor(ACCESSOR a, INTERPOLATOR inter)
init from given accessor
value_type operator()(ITERATOR const &i, float x, float y) const
Interpolate the data item at a non-integer position x, y.
bool operator()(ITERATOR const &i, std::pair< ALPHAITERATOR, ALPHAACCESSOR > const &alpha, float x, float y, value_type &result) const
Interpolate the data item at a non-integer position x, y.
misc math function & classes used by other parts of the program
static double sinc(double x)
static const double A(-0.75)
static double cubic01(double x)
Interpolator
enum with all interpolation methods
@ INTERP_NEAREST_NEIGHBOUR
static double cubic12(double x)
simple bilinear interpolation
void calc_coeff(double x, double *w) const
void emitGLSL(std::ostringstream &oss) const
void emitGLSL(std::ostringstream &oss) const
void calc_coeff(double x, double *w) const
initialize weights for given x
several classes to calculate interpolator weights,
void emitGLSL(std::ostringstream &oss) const
void calc_coeff(double x, double *w) const
sinc interpolation, with variable width
void calc_coeff(double x, double *w) const
initialize weights for given offset x
void emitGLSL(std::ostringstream &oss) const
void emitGLSL(std::ostringstream &oss) const
void calc_coeff(double x, double *w) const
initialize weights for given x
void emitGLSL(std::ostringstream &oss) const
void calc_coeff(double x, double *w) const
calculate weights for given offset x.
void emitGLSL(std::ostringstream &oss) const
void calc_coeff(double x, double *w) const
initialize weights for given offset x
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.