36 #ifndef VIGRA_SPLINEIMAGEVIEW_HXX 37 #define VIGRA_SPLINEIMAGEVIEW_HXX 39 #include "mathutil.hxx" 40 #include "recursiveconvolution.hxx" 41 #include "splines.hxx" 42 #include "array_vector.hxx" 43 #include "basicimage.hxx" 44 #include "copyimage.hxx" 45 #include "tinyvector.hxx" 46 #include "fixedpoint.hxx" 47 #include "multi_array.hxx" 98 template <
int ORDER,
class VALUETYPE>
101 typedef typename NumericTraits<VALUETYPE>::RealPromote InternalValue;
131 typedef typename InternalTraverser::row_iterator InternalRowIterator;
135 enum { ksize_ = ORDER + 1, kcenter_ = ORDER / 2 };
146 template <
class U,
class S>
148 : w_(s.
shape(0)), h_(s.
shape(1)), w1_(w_-1), h1_(h_-1),
149 x0_(kcenter_), x1_(w_ - kcenter_ - 2), y0_(kcenter_), y1_(h_ - kcenter_ - 2),
154 copyImage(srcImageRange(s), destImage(image_));
155 if(!skipPrefiltering)
166 template <
class SrcIterator,
class SrcAccessor>
167 SplineImageView(SrcIterator is, SrcIterator iend, SrcAccessor sa,
bool skipPrefiltering =
false)
168 : w_(iend.x - is.x), h_(iend.y - is.y), w1_(w_-1), h1_(h_-1),
169 x0_(kcenter_), x1_(w_ - kcenter_ - 2), y0_(kcenter_), y1_(h_ - kcenter_ - 2),
174 copyImage(srcIterRange(is, iend, sa), destImage(image_));
175 if(!skipPrefiltering)
186 template <
class SrcIterator,
class SrcAccessor>
187 SplineImageView(triple<SrcIterator, SrcIterator, SrcAccessor> s,
bool skipPrefiltering =
false)
188 : w_(s.second.x - s.first.x), h_(s.second.y - s.first.y), w1_(w_-1), h1_(h_-1),
189 x0_(kcenter_), x1_(w_ - kcenter_ - 2), y0_(kcenter_), y1_(h_ - kcenter_ - 2),
194 copyImage(srcIterRange(s.first, s.second, s.third), destImage(image_));
195 if(!skipPrefiltering)
204 value_type
operator()(
double x,
double y)
const;
211 value_type
operator()(
double x,
double y,
unsigned int dx,
unsigned int dy)
const;
216 value_type
dx(
double x,
double y)
const 222 value_type
dy(
double x,
double y)
const 228 value_type
dxx(
double x,
double y)
const 234 value_type
dxy(
double x,
double y)
const 240 value_type
dyy(
double x,
double y)
const 246 value_type
dx3(
double x,
double y)
const 252 value_type
dy3(
double x,
double y)
const 258 value_type
dxxy(
double x,
double y)
const 264 value_type
dxyy(
double x,
double y)
const 276 value_type
operator()(difference_type
const & d,
unsigned int dx,
unsigned int dy)
const 282 value_type
dx(difference_type
const & d)
const 283 {
return dx(d[0], d[1]); }
288 value_type
dy(difference_type
const & d)
const 289 {
return dy(d[0], d[1]); }
294 value_type
dxx(difference_type
const & d)
const 295 {
return dxx(d[0], d[1]); }
300 value_type
dxy(difference_type
const & d)
const 301 {
return dxy(d[0], d[1]); }
306 value_type
dyy(difference_type
const & d)
const 307 {
return dyy(d[0], d[1]); }
312 value_type
dx3(difference_type
const & d)
const 313 {
return dx3(d[0], d[1]); }
318 value_type
dy3(difference_type
const & d)
const 319 {
return dy3(d[0], d[1]); }
324 value_type
dxxy(difference_type
const & d)
const 325 {
return dxxy(d[0], d[1]); }
330 value_type
dxyy(difference_type
const & d)
const 331 {
return dxyy(d[0], d[1]); }
335 SquaredNormType
g2(
double x,
double y)
const;
340 SquaredNormType
g2x(
double x,
double y)
const;
345 SquaredNormType
g2y(
double x,
double y)
const;
350 SquaredNormType
g2xx(
double x,
double y)
const;
355 SquaredNormType
g2xy(
double x,
double y)
const;
360 SquaredNormType
g2yy(
double x,
double y)
const;
364 SquaredNormType
g2(difference_type
const & d)
const 365 {
return g2(d[0], d[1]); }
370 SquaredNormType
g2x(difference_type
const & d)
const 371 {
return g2x(d[0], d[1]); }
376 SquaredNormType
g2y(difference_type
const & d)
const 377 {
return g2y(d[0], d[1]); }
382 SquaredNormType
g2xx(difference_type
const & d)
const 383 {
return g2xx(d[0], d[1]); }
388 SquaredNormType
g2xy(difference_type
const & d)
const 389 {
return g2xy(d[0], d[1]); }
394 SquaredNormType
g2yy(difference_type
const & d)
const 395 {
return g2yy(d[0], d[1]); }
465 template <
class Array>
473 return x >= 0.0 && x <=
width()-1.0;
481 return y >= 0.0 && y <=
height()-1.0;
499 return x < w1_ + x1_ && x > -x1_ && y < h1_ + y1_ && y > -y1_;
509 bool sameFacet(
double x0,
double y0,
double x1,
double y1)
const 515 return x0 == x1 && y0 == y1;
521 void calculateIndices(
double x,
double y)
const;
522 void coefficients(
double t,
double *
const & c)
const;
523 void derivCoefficients(
double t,
unsigned int d,
double *
const & c)
const;
524 value_type convolve()
const;
528 double x0_, x1_, y0_, y1_;
529 InternalImage image_;
531 mutable double x_, y_, u_, v_, kx_[ksize_], ky_[ksize_];
532 mutable int ix_[ksize_], iy_[ksize_];
535 template <
int ORDER,
class VALUETYPE>
540 for(
unsigned int i=0; i<b.
size(); ++i)
542 recursiveFilterX(srcImageRange(image_), destImage(image_), b[i], BORDER_TREATMENT_REFLECT);
543 recursiveFilterY(srcImageRange(image_), destImage(image_), b[i], BORDER_TREATMENT_REFLECT);
551 struct SplineImageViewUnrollLoop1
553 template <
class Array>
554 static void exec(
int c0, Array c)
556 SplineImageViewUnrollLoop1<i-1>::exec(c0, c);
562 struct SplineImageViewUnrollLoop1<0>
564 template <
class Array>
565 static void exec(
int c0, Array c)
571 template <
int i,
class ValueType>
572 struct SplineImageViewUnrollLoop2
574 template <
class Array1,
class RowIterator,
class Array2>
578 return ValueType(k[i] * r[x[i]]) + SplineImageViewUnrollLoop2<i-1, ValueType>::exec(k, r, x);
582 template <
class ValueType>
583 struct SplineImageViewUnrollLoop2<0, ValueType>
585 template <
class Array1,
class RowIterator,
class Array2>
589 return ValueType(k[0] * r[x[0]]);
595 template <
int ORDER,
class VALUETYPE>
599 if(x == x_ && y == y_)
602 if(x > x0_ && x < x1_ && y > y0_ && y < y1_)
604 detail::SplineImageViewUnrollLoop1<ORDER>::exec(
605 (ORDER % 2) ?
int(x - kcenter_) :
int(x + 0.5 - kcenter_), ix_);
606 detail::SplineImageViewUnrollLoop1<ORDER>::exec(
607 (ORDER % 2) ?
int(y - kcenter_) :
int(y + 0.5 - kcenter_), iy_);
609 u_ = x - ix_[kcenter_];
610 v_ = y - iy_[kcenter_];
614 vigra_precondition(
isValid(x,y),
615 "SplineImageView::calculateIndices(): coordinates out of range.");
617 int xCenter = (ORDER % 2) ?
620 int yCenter = (ORDER % 2) ?
626 for(
int i = 0; i < ksize_; ++i)
627 ix_[i] = w1_ -
vigra::abs(w1_ - xCenter - (i - kcenter_));
631 for(
int i = 0; i < ksize_; ++i)
632 ix_[i] =
vigra::abs(xCenter - (kcenter_ - i));
636 for(
int i = 0; i < ksize_; ++i)
637 iy_[i] = h1_ -
vigra::abs(h1_ - yCenter - (i - kcenter_));
641 for(
int i = 0; i < ksize_; ++i)
642 iy_[i] =
vigra::abs(yCenter - (kcenter_ - i));
651 template <
int ORDER,
class VALUETYPE>
655 for(
int i = 0; i<ksize_; ++i)
659 template <
int ORDER,
class VALUETYPE>
661 unsigned int d,
double *
const & c)
const 664 for(
int i = 0; i<ksize_; ++i)
668 template <
int ORDER,
class VALUETYPE>
671 typedef typename NumericTraits<VALUETYPE>::RealPromote RealPromote;
674 ky_[0]*detail::SplineImageViewUnrollLoop2<ORDER, RealPromote>::exec(kx_, image_.rowBegin(iy_[0]), ix_));
676 for(
int j=1; j<ksize_; ++j)
679 ky_[j]*detail::SplineImageViewUnrollLoop2<ORDER, RealPromote>::exec(kx_, image_.rowBegin(iy_[j]), ix_));
681 return detail::RequiresExplicitCast<VALUETYPE>::cast(sum);
684 template <
int ORDER,
class VALUETYPE>
685 template <
class Array>
689 typedef typename Array::value_type ResType;
691 ResType tmp[ksize_][ksize_];
693 calculateIndices(x, y);
694 for(
int j=0; j<ksize_; ++j)
696 for(
int i=0; i<ksize_; ++i)
698 tmp[i][j] = ResType();
699 for(
int k=0; k<ksize_; ++k)
701 tmp[i][j] += weights[i][k]*image_(ix_[k], iy_[j]);
705 for(
int j=0; j<ksize_; ++j)
707 for(
int i=0; i<ksize_; ++i)
709 res(i,j) = ResType();
710 for(
int k=0; k<ksize_; ++k)
712 res(i,j) += weights[j][k]*tmp[i][k];
718 template <
int ORDER,
class VALUETYPE>
721 calculateIndices(x, y);
722 coefficients(u_, kx_);
723 coefficients(v_, ky_);
727 template <
int ORDER,
class VALUETYPE>
729 unsigned int dx,
unsigned int dy)
const 731 calculateIndices(x, y);
732 derivCoefficients(u_, dx, kx_);
733 derivCoefficients(v_, dy, ky_);
737 template <
int ORDER,
class VALUETYPE>
744 template <
int ORDER,
class VALUETYPE>
751 template <
int ORDER,
class VALUETYPE>
758 template <
int ORDER,
class VALUETYPE>
766 template <
int ORDER,
class VALUETYPE>
774 template <
int ORDER,
class VALUETYPE>
787 template <
class VALUETYPE,
class INTERNAL_INDEXER>
788 class SplineImageView0Base
790 typedef typename INTERNAL_INDEXER::value_type InternalValue;
793 typedef typename NormTraits<VALUETYPE>::SquaredNormType
SquaredNormType;
800 SplineImageView0Base(
unsigned int w,
unsigned int h)
804 SplineImageView0Base(
int w,
int h, INTERNAL_INDEXER i)
805 : w_(w), h_(h), internalIndexer_(i)
808 template <
unsigned IntBits1,
unsigned FractionalBits1,
809 unsigned IntBits2,
unsigned FractionalBits2>
816 template <
unsigned IntBits1,
unsigned FractionalBits1,
817 unsigned IntBits2,
unsigned FractionalBits2>
820 unsigned int dx,
unsigned int dy)
const 822 if((dx != 0) || (dy != 0))
823 return NumericTraits<VALUETYPE>::zero();
824 return unchecked(x, y);
827 value_type unchecked(
double x,
double y)
const 829 return internalIndexer_((
int)(x + 0.5), (
int)(y + 0.5));
832 value_type unchecked(
double x,
double y,
unsigned int dx,
unsigned int dy)
const 834 if((dx != 0) || (dy != 0))
835 return NumericTraits<VALUETYPE>::zero();
836 return unchecked(x, y);
839 value_type
operator()(
double x,
double y)
const 844 ix = (int)(-x + 0.5);
845 vigra_precondition(ix <= (
int)w_ - 1,
846 "SplineImageView::operator(): coordinates out of range.");
854 vigra_precondition(ix >= 0,
855 "SplineImageView::operator(): coordinates out of range.");
860 iy = (int)(-y + 0.5);
861 vigra_precondition(iy <= (
int)h_ - 1,
862 "SplineImageView::operator(): coordinates out of range.");
870 vigra_precondition(iy >= 0,
871 "SplineImageView::operator(): coordinates out of range.");
874 return internalIndexer_(ix, iy);
877 value_type
operator()(
double x,
double y,
unsigned int dx,
unsigned int dy)
const 879 if((dx != 0) || (dy != 0))
880 return NumericTraits<VALUETYPE>::zero();
884 value_type
dx(
double x,
double y)
const 885 {
return NumericTraits<VALUETYPE>::zero(); }
887 value_type
dy(
double x,
double y)
const 888 {
return NumericTraits<VALUETYPE>::zero(); }
890 value_type
dxx(
double x,
double y)
const 891 {
return NumericTraits<VALUETYPE>::zero(); }
893 value_type
dxy(
double x,
double y)
const 894 {
return NumericTraits<VALUETYPE>::zero(); }
896 value_type
dyy(
double x,
double y)
const 897 {
return NumericTraits<VALUETYPE>::zero(); }
899 value_type
dx3(
double x,
double y)
const 900 {
return NumericTraits<VALUETYPE>::zero(); }
902 value_type
dy3(
double x,
double y)
const 903 {
return NumericTraits<VALUETYPE>::zero(); }
905 value_type
dxxy(
double x,
double y)
const 906 {
return NumericTraits<VALUETYPE>::zero(); }
908 value_type
dxyy(
double x,
double y)
const 909 {
return NumericTraits<VALUETYPE>::zero(); }
911 value_type
operator()(difference_type
const & d)
const 914 value_type
operator()(difference_type
const & d,
unsigned int dx,
unsigned int dy)
const 917 value_type
dx(difference_type
const & d)
const 918 {
return NumericTraits<VALUETYPE>::zero(); }
920 value_type
dy(difference_type
const & d)
const 921 {
return NumericTraits<VALUETYPE>::zero(); }
923 value_type
dxx(difference_type
const & d)
const 924 {
return NumericTraits<VALUETYPE>::zero(); }
926 value_type
dxy(difference_type
const & d)
const 927 {
return NumericTraits<VALUETYPE>::zero(); }
929 value_type
dyy(difference_type
const & d)
const 930 {
return NumericTraits<VALUETYPE>::zero(); }
932 value_type
dx3(difference_type
const & d)
const 933 {
return NumericTraits<VALUETYPE>::zero(); }
935 value_type
dy3(difference_type
const & d)
const 936 {
return NumericTraits<VALUETYPE>::zero(); }
938 value_type
dxxy(difference_type
const & d)
const 939 {
return NumericTraits<VALUETYPE>::zero(); }
941 value_type
dxyy(difference_type
const & d)
const 942 {
return NumericTraits<VALUETYPE>::zero(); }
944 SquaredNormType
g2(
double x,
double y)
const 945 {
return NumericTraits<SquaredNormType>::zero(); }
947 SquaredNormType
g2x(
double x,
double y)
const 948 {
return NumericTraits<SquaredNormType>::zero(); }
950 SquaredNormType
g2y(
double x,
double y)
const 951 {
return NumericTraits<SquaredNormType>::zero(); }
953 SquaredNormType
g2xx(
double x,
double y)
const 954 {
return NumericTraits<SquaredNormType>::zero(); }
956 SquaredNormType
g2xy(
double x,
double y)
const 957 {
return NumericTraits<SquaredNormType>::zero(); }
959 SquaredNormType
g2yy(
double x,
double y)
const 960 {
return NumericTraits<SquaredNormType>::zero(); }
962 SquaredNormType
g2(difference_type
const & d)
const 963 {
return NumericTraits<SquaredNormType>::zero(); }
965 SquaredNormType
g2x(difference_type
const & d)
const 966 {
return NumericTraits<SquaredNormType>::zero(); }
968 SquaredNormType
g2y(difference_type
const & d)
const 969 {
return NumericTraits<SquaredNormType>::zero(); }
971 SquaredNormType
g2xx(difference_type
const & d)
const 972 {
return NumericTraits<SquaredNormType>::zero(); }
974 SquaredNormType
g2xy(difference_type
const & d)
const 975 {
return NumericTraits<SquaredNormType>::zero(); }
977 SquaredNormType
g2yy(difference_type
const & d)
const 978 {
return NumericTraits<SquaredNormType>::zero(); }
980 unsigned int width()
const 983 unsigned int height()
const 986 size_type
size()
const 992 template <
class Array>
1000 return x >= 0.0 && x <=
width() - 1.0;
1005 return y >= 0.0 && y <=
height() - 1.0;
1008 bool isInside(
double x,
double y)
const 1013 bool isValid(
double x,
double y)
const 1015 return x < 2.0*w_-2.0 && x > 1.0-w_ && y < 2.0*h_-2.0 && y > 1.0-h_;
1018 bool sameFacet(
double x0,
double y0,
double x1,
double y1)
const 1024 return x0 == x1 && y0 == y1;
1028 unsigned int w_, h_;
1029 INTERNAL_INDEXER internalIndexer_;
1041 template <class VALUETYPE, class INTERNAL_TRAVERSER = typename BasicImage<VALUETYPE>::const_traverser>
1043 :
public SplineImageView0Base<VALUETYPE, INTERNAL_TRAVERSER>
1045 typedef SplineImageView0Base<VALUETYPE, INTERNAL_TRAVERSER> Base;
1047 typedef typename Base::value_type
value_type;
1051 enum StaticOrder { order = Base::order };
1065 SplineImageView0(InternalTraverser is, InternalTraverser iend, InternalAccessor sa)
1066 : Base(iend.x - is.x, iend.y - is.y, is)
1069 SplineImageView0(triple<InternalTraverser, InternalTraverser, InternalAccessor> s)
1070 : Base(s.second.x - s.first.x, s.second.y - s.first.y, s.first)
1073 SplineImageView0(InternalConstTraverser is, InternalConstTraverser iend, InternalConstAccessor sa)
1074 : Base(iend.x - is.x, iend.y - is.y, is)
1077 SplineImageView0(triple<InternalConstTraverser, InternalConstTraverser, InternalConstAccessor> s)
1078 : Base(s.second.x - s.first.x, s.second.y - s.first.y, s.first)
1081 template<
class T,
class SU>
1086 for(
unsigned int y=0; y<this->
height(); ++y)
1087 for(
unsigned int x=0; x<this->
width(); ++x)
1088 image_(x,y) = detail::RequiresExplicitCast<VALUETYPE>::cast(i(x,y));
1089 this->internalIndexer_ = image_.upperLeft();
1092 template <
class SrcIterator,
class SrcAccessor>
1094 : Base(iend.x - is.x, iend.y - is.y),
1097 copyImage(srcIterRange(is, iend, sa), destImage(image_));
1098 this->internalIndexer_ = image_.upperLeft();
1101 template <
class SrcIterator,
class SrcAccessor>
1103 : Base(s.second.x - s.first.x, s.second.y - s.first.y),
1104 image_(s.second - s.first)
1107 this->internalIndexer_ = image_.upperLeft();
1110 InternalImage
const &
image()
const 1114 InternalImage image_;
1117 template <
class VALUETYPE,
class Str
idedOrUnstr
ided>
1118 class SplineImageView0<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> >
1119 :
public SplineImageView0Base<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> >
1121 typedef SplineImageView0Base<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> > Base;
1123 typedef typename Base::value_type
value_type;
1127 enum StaticOrder { order = Base::order };
1139 : Base(i.shape(0), i.shape(1), i)
1142 template<
class T,
class SU>
1147 for(
unsigned int y=0; y<this->
height(); ++y)
1148 for(
unsigned int x=0; x<this->
width(); ++x)
1149 image_(x,y) = detail::RequiresExplicitCast<VALUETYPE>::cast(i(x,y));
1150 this->internalIndexer_ = InternalIndexer(
typename InternalIndexer::difference_type(this->
width(), this->
height()),
1154 template <
class SrcIterator,
class SrcAccessor>
1156 : Base(iend.x - is.x, iend.y - is.y),
1159 copyImage(srcIterRange(is, iend, sa), destImage(image_));
1160 this->internalIndexer_ = InternalIndexer(
typename InternalIndexer::difference_type(this->
width(), this->
height()),
1164 template <
class SrcIterator,
class SrcAccessor>
1165 SplineImageView0(triple<SrcIterator, SrcIterator, SrcAccessor> s)
1166 : Base(s.second.x - s.first.x, s.second.y - s.first.y),
1167 image_(s.second - s.first)
1170 this->internalIndexer_ = InternalIndexer(
typename InternalIndexer::difference_type(this->
width(), this->
height()),
1174 InternalImage
const &
image()
const 1178 InternalImage image_;
1181 template <
class VALUETYPE>
1187 typedef typename Base::value_type
value_type;
1191 enum StaticOrder { order = Base::order };
1195 typedef typename Base::InternalTraverser InternalTraverser;
1197 typedef typename Base::InternalConstTraverser InternalConstTraverser;
1205 SplineImageView(InternalTraverser is, InternalTraverser iend, InternalAccessor sa,
bool =
false)
1206 : Base(is, iend, sa)
1209 SplineImageView(triple<InternalTraverser, InternalTraverser, InternalAccessor> s,
bool =
false)
1213 SplineImageView(InternalConstTraverser is, InternalConstTraverser iend, InternalConstAccessor sa,
bool =
false)
1214 : Base(is, iend, sa)
1217 SplineImageView(triple<InternalConstTraverser, InternalConstTraverser, InternalConstAccessor> s,
bool =
false)
1221 template <
class SrcIterator,
class SrcAccessor>
1222 SplineImageView(SrcIterator is, SrcIterator iend, SrcAccessor sa,
bool =
false)
1223 : Base(is, iend, sa)
1225 copyImage(srcIterRange(is, iend, sa), destImage(this->image_));
1228 template <
class SrcIterator,
class SrcAccessor>
1229 SplineImageView(triple<SrcIterator, SrcIterator, SrcAccessor> s,
bool =
false)
1241 template <
class VALUETYPE,
class INTERNAL_INDEXER>
1242 class SplineImageView1Base
1244 typedef typename INTERNAL_INDEXER::value_type InternalValue;
1248 typedef typename NormTraits<VALUETYPE>::SquaredNormType
SquaredNormType;
1250 enum StaticOrder { order = 1 };
1254 SplineImageView1Base(
unsigned int w,
unsigned int h)
1258 SplineImageView1Base(
int w,
int h, INTERNAL_INDEXER i)
1259 : w_(w), h_(h), internalIndexer_(i)
1262 template <
unsigned IntBits1,
unsigned FractionalBits1,
1263 unsigned IntBits2,
unsigned FractionalBits2>
1270 if(ix == (
int)w_ - 1)
1279 if(iy == (
int)h_ - 1)
1286 dty*(dtx*fixedPoint(internalIndexer_(ix,iy)) +
1287 tx*fixedPoint(internalIndexer_(ix+1,iy))) +
1288 ty *(dtx*fixedPoint(internalIndexer_(ix,iy+1)) +
1289 tx*fixedPoint(internalIndexer_(ix+1,iy+1))));
1292 template <
unsigned IntBits1,
unsigned FractionalBits1,
1293 unsigned IntBits2,
unsigned FractionalBits2>
1296 unsigned int dx,
unsigned int dy)
const 1301 if(ix == (
int)w_ - 1)
1310 if(iy == (
int)h_ - 1)
1323 dty*(dtx*fixedPoint(internalIndexer_(ix,iy)) +
1324 tx*fixedPoint(internalIndexer_(ix+1,iy))) +
1325 ty *(dtx*fixedPoint(internalIndexer_(ix,iy+1)) +
1326 tx*fixedPoint(internalIndexer_(ix+1,iy+1))));
1329 (dtx*fixedPoint(internalIndexer_(ix,iy+1)) + tx*fixedPoint(internalIndexer_(ix+1,iy+1))) -
1330 (dtx*fixedPoint(internalIndexer_(ix,iy)) + tx*fixedPoint(internalIndexer_(ix+1,iy))));
1332 return NumericTraits<VALUETYPE>::zero();
1339 dty*(fixedPoint(internalIndexer_(ix+1,iy)) - fixedPoint(internalIndexer_(ix,iy))) +
1340 ty *(fixedPoint(internalIndexer_(ix+1,iy+1)) - fixedPoint(internalIndexer_(ix,iy+1))));
1342 return detail::RequiresExplicitCast<value_type>::cast(
1343 (internalIndexer_(ix+1,iy+1) - internalIndexer_(ix,iy+1)) -
1344 (internalIndexer_(ix+1,iy) - internalIndexer_(ix,iy)));
1346 return NumericTraits<VALUETYPE>::zero();
1349 return NumericTraits<VALUETYPE>::zero();
1353 value_type unchecked(
double x,
double y)
const 1356 if(ix == (
int)w_ - 1)
1360 if(iy == (
int)h_ - 1)
1363 return NumericTraits<value_type>::fromRealPromote(
1364 (1.0-ty)*((1.0-tx)*internalIndexer_(ix,iy) + tx*internalIndexer_(ix+1,iy)) +
1365 ty *((1.0-tx)*internalIndexer_(ix,iy+1) + tx*internalIndexer_(ix+1,iy+1)));
1368 value_type unchecked(
double x,
double y,
unsigned int dx,
unsigned int dy)
const 1371 if(ix == (
int)w_ - 1)
1375 if(iy == (
int)h_ - 1)
1384 return detail::RequiresExplicitCast<value_type>::cast(
1385 (1.0-ty)*((1.0-tx)*internalIndexer_(ix,iy) + tx*internalIndexer_(ix+1,iy)) +
1386 ty *((1.0-tx)*internalIndexer_(ix,iy+1) + tx*internalIndexer_(ix+1,iy+1)));
1388 return detail::RequiresExplicitCast<value_type>::cast(
1389 ((1.0-tx)*internalIndexer_(ix,iy+1) + tx*internalIndexer_(ix+1,iy+1)) -
1390 ((1.0-tx)*internalIndexer_(ix,iy) + tx*internalIndexer_(ix+1,iy)));
1392 return NumericTraits<VALUETYPE>::zero();
1398 return detail::RequiresExplicitCast<value_type>::cast(
1399 (1.0-ty)*(internalIndexer_(ix+1,iy) - internalIndexer_(ix,iy)) +
1400 ty *(internalIndexer_(ix+1,iy+1) - internalIndexer_(ix,iy+1)));
1402 return detail::RequiresExplicitCast<value_type>::cast(
1403 (internalIndexer_(ix+1,iy+1) - internalIndexer_(ix,iy+1)) -
1404 (internalIndexer_(ix+1,iy) - internalIndexer_(ix,iy)));
1406 return NumericTraits<VALUETYPE>::zero();
1409 return NumericTraits<VALUETYPE>::zero();
1413 value_type
operator()(
double x,
double y)
const 1418 value_type
operator()(
double x,
double y,
unsigned int dx,
unsigned int dy)
const 1420 value_type
mul = NumericTraits<value_type>::one();
1424 vigra_precondition(x <= w_ - 1.0,
1425 "SplineImageView::operator(): coordinates out of range.");
1429 else if(x > w_ - 1.0)
1432 vigra_precondition(x >= 0.0,
1433 "SplineImageView::operator(): coordinates out of range.");
1440 vigra_precondition(y <= h_ - 1.0,
1441 "SplineImageView::operator(): coordinates out of range.");
1445 else if(y > h_ - 1.0)
1448 vigra_precondition(y >= 0.0,
1449 "SplineImageView::operator(): coordinates out of range.");
1453 return mul*unchecked(x, y, dx, dy);
1456 value_type
dx(
double x,
double y)
const 1459 value_type
dy(
double x,
double y)
const 1462 value_type
dxx(
double x,
double y)
const 1463 {
return NumericTraits<VALUETYPE>::zero(); }
1465 value_type
dxy(
double x,
double y)
const 1468 value_type
dyy(
double x,
double y)
const 1469 {
return NumericTraits<VALUETYPE>::zero(); }
1471 value_type
dx3(
double x,
double y)
const 1472 {
return NumericTraits<VALUETYPE>::zero(); }
1474 value_type
dy3(
double x,
double y)
const 1475 {
return NumericTraits<VALUETYPE>::zero(); }
1477 value_type
dxxy(
double x,
double y)
const 1478 {
return NumericTraits<VALUETYPE>::zero(); }
1480 value_type
dxyy(
double x,
double y)
const 1481 {
return NumericTraits<VALUETYPE>::zero(); }
1483 value_type
operator()(difference_type
const & d)
const 1486 value_type
operator()(difference_type
const & d,
unsigned int dx,
unsigned int dy)
const 1489 value_type
dx(difference_type
const & d)
const 1492 value_type
dy(difference_type
const & d)
const 1495 value_type
dxx(difference_type
const & d)
const 1496 {
return NumericTraits<VALUETYPE>::zero(); }
1498 value_type
dxy(difference_type
const & d)
const 1501 value_type
dyy(difference_type
const & d)
const 1502 {
return NumericTraits<VALUETYPE>::zero(); }
1504 value_type
dx3(difference_type
const & d)
const 1505 {
return NumericTraits<VALUETYPE>::zero(); }
1507 value_type
dy3(difference_type
const & d)
const 1508 {
return NumericTraits<VALUETYPE>::zero(); }
1510 value_type
dxxy(difference_type
const & d)
const 1511 {
return NumericTraits<VALUETYPE>::zero(); }
1513 value_type
dxyy(difference_type
const & d)
const 1514 {
return NumericTraits<VALUETYPE>::zero(); }
1516 SquaredNormType
g2(
double x,
double y)
const 1519 SquaredNormType
g2x(
double x,
double y)
const 1520 {
return NumericTraits<SquaredNormType>::zero(); }
1522 SquaredNormType
g2y(
double x,
double y)
const 1523 {
return NumericTraits<SquaredNormType>::zero(); }
1525 SquaredNormType
g2xx(
double x,
double y)
const 1526 {
return NumericTraits<SquaredNormType>::zero(); }
1528 SquaredNormType
g2xy(
double x,
double y)
const 1529 {
return NumericTraits<SquaredNormType>::zero(); }
1531 SquaredNormType
g2yy(
double x,
double y)
const 1532 {
return NumericTraits<SquaredNormType>::zero(); }
1534 SquaredNormType
g2(difference_type
const & d)
const 1535 {
return g2(d[0], d[1]); }
1537 SquaredNormType
g2x(difference_type
const & d)
const 1538 {
return NumericTraits<SquaredNormType>::zero(); }
1540 SquaredNormType
g2y(difference_type
const & d)
const 1541 {
return NumericTraits<SquaredNormType>::zero(); }
1543 SquaredNormType
g2xx(difference_type
const & d)
const 1544 {
return NumericTraits<SquaredNormType>::zero(); }
1546 SquaredNormType
g2xy(difference_type
const & d)
const 1547 {
return NumericTraits<SquaredNormType>::zero(); }
1549 SquaredNormType
g2yy(difference_type
const & d)
const 1550 {
return NumericTraits<SquaredNormType>::zero(); }
1552 unsigned int width()
const 1555 unsigned int height()
const 1558 size_type
size()
const 1564 template <
class Array>
1567 void calculateIndices(
double x,
double y,
int & ix,
int & iy,
int & ix1,
int & iy1)
const;
1571 return x >= 0.0 && x <=
width() - 1.0;
1576 return y >= 0.0 && y <=
height() - 1.0;
1579 bool isInside(
double x,
double y)
const 1584 bool isValid(
double x,
double y)
const 1586 return x < 2.0*w_-2.0 && x > 1.0-w_ && y < 2.0*h_-2.0 && y > 1.0-h_;
1589 bool sameFacet(
double x0,
double y0,
double x1,
double y1)
const 1595 return x0 == x1 && y0 == y1;
1599 unsigned int w_, h_;
1600 INTERNAL_INDEXER internalIndexer_;
1603 template <
class VALUETYPE,
class INTERNAL_INDEXER>
1604 template <
class Array>
1605 void SplineImageView1Base<VALUETYPE, INTERNAL_INDEXER>::coefficientArray(
double x,
double y, Array & res)
const 1607 int ix, iy, ix1, iy1;
1608 calculateIndices(x, y, ix, iy, ix1, iy1);
1609 res(0,0) = internalIndexer_(ix,iy);
1610 res(1,0) = internalIndexer_(ix1,iy) - internalIndexer_(ix,iy);
1611 res(0,1) = internalIndexer_(ix,iy1) - internalIndexer_(ix,iy);
1612 res(1,1) = internalIndexer_(ix,iy) - internalIndexer_(ix1,iy) -
1613 internalIndexer_(ix,iy1) + internalIndexer_(ix1,iy1);
1616 template <
class VALUETYPE,
class INTERNAL_INDEXER>
1617 void SplineImageView1Base<VALUETYPE, INTERNAL_INDEXER>::calculateIndices(
double x,
double y,
int & ix,
int & iy,
int & ix1,
int & iy1)
const 1622 vigra_precondition(x <= w_ - 1.0,
1623 "SplineImageView::calculateIndices(): coordinates out of range.");
1627 else if(x >= w_ - 1.0)
1630 vigra_precondition(x > 0.0,
1631 "SplineImageView::calculateIndices(): coordinates out of range.");
1643 vigra_precondition(y <= h_ - 1.0,
1644 "SplineImageView::calculateIndices(): coordinates out of range.");
1648 else if(y >= h_ - 1.0)
1651 vigra_precondition(y > 0.0,
1652 "SplineImageView::calculateIndices(): coordinates out of range.");
1678 template <class VALUETYPE, class INTERNAL_TRAVERSER = typename BasicImage<VALUETYPE>::const_traverser>
1680 :
public SplineImageView1Base<VALUETYPE, INTERNAL_TRAVERSER>
1682 typedef SplineImageView1Base<VALUETYPE, INTERNAL_TRAVERSER> Base;
1684 typedef typename Base::value_type
value_type;
1688 enum StaticOrder { order = Base::order };
1702 SplineImageView1(InternalTraverser is, InternalTraverser iend, InternalAccessor sa)
1703 : Base(iend.x - is.x, iend.y - is.y, is)
1706 SplineImageView1(triple<InternalTraverser, InternalTraverser, InternalAccessor> s)
1707 : Base(s.second.x - s.first.x, s.second.y - s.first.y, s.first)
1710 SplineImageView1(InternalConstTraverser is, InternalConstTraverser iend, InternalConstAccessor sa)
1711 : Base(iend.x - is.x, iend.y - is.y, is)
1714 SplineImageView1(triple<InternalConstTraverser, InternalConstTraverser, InternalConstAccessor> s)
1715 : Base(s.second.x - s.first.x, s.second.y - s.first.y, s.first)
1718 template<
class T,
class SU>
1723 for(
unsigned int y=0; y<this->
height(); ++y)
1724 for(
unsigned int x=0; x<this->
width(); ++x)
1725 image_(x,y) = detail::RequiresExplicitCast<VALUETYPE>::cast(i(x,y));
1726 this->internalIndexer_ = image_.upperLeft();
1729 template <
class SrcIterator,
class SrcAccessor>
1731 : Base(iend.x - is.x, iend.y - is.y),
1734 copyImage(srcIterRange(is, iend, sa), destImage(image_));
1735 this->internalIndexer_ = image_.upperLeft();
1738 template <
class SrcIterator,
class SrcAccessor>
1740 : Base(s.second.x - s.first.x, s.second.y - s.first.y),
1741 image_(s.second - s.first)
1744 this->internalIndexer_ = image_.upperLeft();
1747 InternalImage
const &
image()
const 1751 InternalImage image_;
1754 template <
class VALUETYPE,
class Str
idedOrUnstr
ided>
1755 class SplineImageView1<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> >
1756 :
public SplineImageView1Base<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> >
1758 typedef SplineImageView1Base<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> > Base;
1760 typedef typename Base::value_type
value_type;
1764 enum StaticOrder { order = Base::order };
1776 : Base(i.shape(0), i.shape(1), i)
1779 template<
class T,
class SU>
1784 copyImage(srcImageRange(i), destImage(image_));
1788 this->internalIndexer_ = InternalIndexer(
typename InternalIndexer::difference_type(this->
width(), this->
height()),
1792 template <
class SrcIterator,
class SrcAccessor>
1794 : Base(iend.x - is.x, iend.y - is.y),
1797 copyImage(srcIterRange(is, iend, sa), destImage(image_));
1798 this->internalIndexer_ = InternalIndexer(
typename InternalIndexer::difference_type(this->
width(), this->
height()),
1802 template <
class SrcIterator,
class SrcAccessor>
1803 SplineImageView1(triple<SrcIterator, SrcIterator, SrcAccessor> s)
1804 : Base(s.second.x - s.first.x, s.second.y - s.first.y),
1805 image_(s.second - s.first)
1808 this->internalIndexer_ = InternalIndexer(
typename InternalIndexer::difference_type(this->
width(), this->
height()),
1812 InternalImage
const &
image()
const 1816 InternalImage image_;
1819 template <
class VALUETYPE>
1825 typedef typename Base::value_type
value_type;
1829 enum StaticOrder { order = Base::order };
1833 typedef typename Base::InternalTraverser InternalTraverser;
1835 typedef typename Base::InternalConstTraverser InternalConstTraverser;
1843 SplineImageView(InternalTraverser is, InternalTraverser iend, InternalAccessor sa,
bool =
false)
1844 : Base(is, iend, sa)
1847 SplineImageView(triple<InternalTraverser, InternalTraverser, InternalAccessor> s,
bool =
false)
1851 SplineImageView(InternalConstTraverser is, InternalConstTraverser iend, InternalConstAccessor sa,
bool =
false)
1852 : Base(is, iend, sa)
1855 SplineImageView(triple<InternalConstTraverser, InternalConstTraverser, InternalConstAccessor> s,
bool =
false)
1859 template <
class SrcIterator,
class SrcAccessor>
1860 SplineImageView(SrcIterator is, SrcIterator iend, SrcAccessor sa,
bool =
false)
1861 : Base(is, iend, sa)
1863 copyImage(srcIterRange(is, iend, sa), destImage(this->image_));
1866 template <
class SrcIterator,
class SrcAccessor>
1867 SplineImageView(triple<SrcIterator, SrcIterator, SrcAccessor> s,
bool =
false)
1873 template<
class T,
class SU>
SquaredNormType g2(difference_type const &d) const
Definition: splineimageview.hxx:364
SquaredNormType g2(double x, double y) const
Definition: splineimageview.hxx:739
bool isInside(double x, double y) const
Definition: splineimageview.hxx:487
VALUETYPE value_type
Definition: splineimageview.hxx:107
bool isInsideY(double y) const
Definition: splineimageview.hxx:479
PromoteTraits< V1, V2 >::Promote dot(RGBValue< V1, RIDX1, GIDX1, BIDX1 > const &r1, RGBValue< V2, RIDX2, GIDX2, BIDX2 > const &r2)
dot product
Definition: rgbvalue.hxx:906
Export associated information for each image iterator.
Definition: iteratortraits.hxx:109
unsigned int width() const
Definition: splineimageview.hxx:400
value_type operator()(difference_type const &d) const
Definition: splineimageview.hxx:270
SquaredNormType g2y(double x, double y) const
Definition: splineimageview.hxx:753
void recursiveFilterY(...)
Performs 1 dimensional recursive filtering (1st and 2nd order) in y direction.
SquaredNormType g2x(difference_type const &d) const
Definition: splineimageview.hxx:370
const difference_type & shape() const
Definition: multi_array.hxx:1596
void coefficientArray(double x, double y, Array &res) const
Definition: splineimageview.hxx:687
ArrayVector< double > const & prefilterCoefficients() const
Definition: splines.hxx:164
SplineImageView(MultiArrayView< 2, U, S > const &s, bool skipPrefiltering=false)
Definition: splineimageview.hxx:147
value_type dyy(difference_type const &d) const
Definition: splineimageview.hxx:306
value_type dxx(difference_type const &d) const
Definition: splineimageview.hxx:294
FFTWComplex< R >::SquaredNormType squaredNorm(const FFTWComplex< R > &a)
squared norm (= squared magnitude)
Definition: fftw3.hxx:1044
SquaredNormType g2y(difference_type const &d) const
Definition: splineimageview.hxx:376
int round(FixedPoint< IntBits, FracBits > v)
rounding to the nearest integer.
Definition: fixedpoint.hxx:683
TARGET fixed_point_cast(FixedPoint< IntBits, FracBits > v)
Definition: fixedpoint.hxx:486
value_type dyy(double x, double y) const
Definition: splineimageview.hxx:240
value_type dxy(difference_type const &d) const
Definition: splineimageview.hxx:300
SquaredNormType g2x(double x, double y) const
Definition: splineimageview.hxx:746
Iterator adapter to linearly access row.
Definition: imageiteratoradapter.hxx:281
SquaredNormType g2xy(difference_type const &d) const
Definition: splineimageview.hxx:388
StaticOrder
Definition: splineimageview.hxx:123
value_type operator()(double x, double y) const
Definition: splineimageview.hxx:719
Definition: accessor.hxx:43
static WeightMatrix const & weights()
Definition: splines.hxx:176
SquaredNormType g2xx(double x, double y) const
Definition: splineimageview.hxx:760
value_type dy3(difference_type const &d) const
Definition: splineimageview.hxx:318
bool isValid(double x, double y) const
Definition: splineimageview.hxx:497
FixedPoint< 0, FracBits > dual_frac(FixedPoint< IntBits, FracBits > v)
dual fractional part: 1 - frac(v).
Definition: fixedpoint.hxx:658
value_type dx(difference_type const &d) const
Definition: splineimageview.hxx:282
Two dimensional size object.
Definition: diff2d.hxx:482
FixedPoint< 0, FracBits > frac(FixedPoint< IntBits, FracBits > v)
fractional part.
Definition: fixedpoint.hxx:650
SquaredNormType g2yy(double x, double y) const
Definition: splineimageview.hxx:768
SquaredNormType g2xx(difference_type const &d) const
Definition: splineimageview.hxx:382
value_type dxxy(double x, double y) const
Definition: splineimageview.hxx:258
Definition: basicimage.hxx:262
value_type dxx(double x, double y) const
Definition: splineimageview.hxx:228
InternalImage const & image() const
Definition: splineimageview.hxx:424
void mul(FixedPoint< IntBits1, FracBits1 > l, FixedPoint< IntBits2, FracBits2 > r, FixedPoint< IntBits3, FracBits3 > &result)
multiplication with enforced result type.
Definition: fixedpoint.hxx:605
value_type operator()(difference_type const &d, unsigned int dx, unsigned int dy) const
Definition: splineimageview.hxx:276
void recursiveFilterX(...)
Performs 1 dimensional recursive filtering (1st and 2nd order) in x direction.
NumericTraits< V >::Promote sum(TinyVectorBase< V, SIZE, D1, D2 > const &l)
sum of the vector's elements
Definition: tinyvector.hxx:2073
NormTraits< VALUETYPE >::SquaredNormType SquaredNormType
Definition: splineimageview.hxx:111
TinyVector< double, 2 > difference_type
Definition: splineimageview.hxx:119
Create an image view for bi-linear interpolation.
Definition: splineimageview.hxx:1679
size_type size() const
Definition: splineimageview.hxx:413
TinyVector< unsigned int, 2 > shape() const
Definition: splineimageview.hxx:419
void copyImage(...)
Copy source image into destination image.
value_type dxxy(difference_type const &d) const
Definition: splineimageview.hxx:324
value_type dx3(double x, double y) const
Definition: splineimageview.hxx:246
value_type dx(double x, double y) const
Definition: splineimageview.hxx:216
value_type dy3(double x, double y) const
Definition: splineimageview.hxx:252
value_type dx3(difference_type const &d) const
Definition: splineimageview.hxx:312
value_type dxyy(difference_type const &d) const
Definition: splineimageview.hxx:330
Size2D size_type
Definition: splineimageview.hxx:115
SquaredNormType g2yy(difference_type const &d) const
Definition: splineimageview.hxx:394
SplineImageView(triple< SrcIterator, SrcIterator, SrcAccessor > s, bool skipPrefiltering=false)
Definition: splineimageview.hxx:187
bool sameFacet(double x0, double y0, double x1, double y1) const
Definition: splineimageview.hxx:509
FFTWComplex< R >::NormType abs(const FFTWComplex< R > &a)
absolute value (= magnitude)
Definition: fftw3.hxx:1002
Base class for, and view to, vigra::MultiArray.
Definition: multi_array.hxx:652
value_type dy(difference_type const &d) const
Definition: splineimageview.hxx:288
value_type dxyy(double x, double y) const
Definition: splineimageview.hxx:264
value_type dy(double x, double y) const
Definition: splineimageview.hxx:222
size_type size() const
Definition: array_vector.hxx:358
BasicImage< InternalValue > InternalImage
Definition: splineimageview.hxx:127
SquaredNormType g2xy(double x, double y) const
Definition: splineimageview.hxx:776
int ceil(FixedPoint< IntBits, FracBits > v)
rounding up.
Definition: fixedpoint.hxx:675
Encapsulate access to the values an iterator points to.
Definition: accessor.hxx:133
Quickly create 1-dimensional iterator adapters.
Definition: iteratoradapter.hxx:147
Create a continuous view onto a discrete image using splines.
Definition: splineimageview.hxx:99
Definition: fixedpoint.hxx:47
int floor(FixedPoint< IntBits, FracBits > v)
rounding down.
Definition: fixedpoint.hxx:667
Create an image view for nearest-neighbor interpolation.
Definition: splineimageview.hxx:1042
value_type dxy(double x, double y) const
Definition: splineimageview.hxx:234
unsigned int height() const
Definition: splineimageview.hxx:406
bool isInsideX(double x) const
Definition: splineimageview.hxx:471
SplineImageView(SrcIterator is, SrcIterator iend, SrcAccessor sa, bool skipPrefiltering=false)
Definition: splineimageview.hxx:167