37 #ifndef VIGRA_RESIZEIMAGE_HXX 38 #define VIGRA_RESIZEIMAGE_HXX 41 #include "utilities.hxx" 42 #include "numerictraits.hxx" 43 #include "stdimage.hxx" 44 #include "recursiveconvolution.hxx" 45 #include "separableconvolution.hxx" 46 #include "resampling_convolution.hxx" 47 #include "splines.hxx" 48 #include "multi_shape.hxx" 134 return prefilterCoefficients_;
165 template <
class SrcIterator,
class SrcAccessor,
166 class DestIterator,
class DestAccessor>
168 resizeLineNoInterpolation(SrcIterator i1, SrcIterator iend, SrcAccessor as,
169 DestIterator
id, DestIterator idend, DestAccessor ad)
171 int wold = iend - i1;
172 int wnew = idend - id;
180 double dx = (double)(wold - 1) / (wnew - 1);
182 for(;
id != idend; ++id, x += dx)
185 ad.set(as(i1, ix),
id);
281 template <
class SrcIterator,
class SrcAccessor,
282 class DestIterator,
class DestAccessor>
284 resizeImageNoInterpolation(SrcIterator is, SrcIterator iend, SrcAccessor sa,
285 DestIterator
id, DestIterator idend, DestAccessor da)
287 int w = iend.x - is.x;
288 int h = iend.y - is.y;
290 int wnew = idend.x -
id.x;
291 int hnew = idend.y -
id.y;
293 vigra_precondition((w > 1) && (h > 1),
294 "resizeImageNoInterpolation(): " 295 "Source image too small.\n");
296 vigra_precondition((wnew > 1) && (hnew > 1),
297 "resizeImageNoInterpolation(): " 298 "Destination image too small.\n");
301 typedef typename TmpImage::traverser TmpImageIterator;
303 TmpImage tmp(w, hnew);
305 TmpImageIterator yt = tmp.upperLeft();
307 for(
int x=0; x<w; ++x, ++is.x, ++yt.x)
309 typename SrcIterator::column_iterator c1 = is.columnIterator();
310 typename TmpImageIterator::column_iterator ct = yt.columnIterator();
312 resizeLineNoInterpolation(c1, c1 + h, sa, ct, ct + hnew, tmp.accessor());
315 yt = tmp.upperLeft();
317 for(
int y=0; y < hnew; ++y, ++yt.y, ++
id.y)
319 typename DestIterator::row_iterator rd =
id.rowIterator();
320 typename TmpImageIterator::row_iterator rt = yt.rowIterator();
322 resizeLineNoInterpolation(rt, rt + w, tmp.accessor(), rd, rd + wnew, da);
326 template <
class SrcIterator,
class SrcAccessor,
327 class DestIterator,
class DestAccessor>
329 resizeImageNoInterpolation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
330 triple<DestIterator, DestIterator, DestAccessor> dest)
332 resizeImageNoInterpolation(src.first, src.second, src.third,
333 dest.first, dest.second, dest.third);
336 template <
class T1,
class S1,
342 resizeImageNoInterpolation(srcImageRange(src),
343 destImageRange(dest));
352 template <
class SrcIterator,
class SrcAccessor,
353 class DestIterator,
class DestAccessor>
355 resizeLineLinearInterpolation(SrcIterator i1, SrcIterator iend, SrcAccessor as,
356 DestIterator
id, DestIterator idend, DestAccessor ad)
358 int wold = iend - i1;
359 int wnew = idend - id;
361 if((wold <= 1) || (wnew <= 1))
return;
364 NumericTraits<typename DestAccessor::value_type> DestTraits;
365 typedef typename DestTraits::RealPromote RealPromote;
367 ad.set(DestTraits::fromRealPromote(as(i1)),
id);
371 ad.set(DestTraits::fromRealPromote(as(iend)), idend);
373 double dx = (double)(wold - 1) / (wnew - 1);
376 for(;
id != idend; ++id, x += dx)
386 ad.set(DestTraits::fromRealPromote(RealPromote(x1 * as(i1) + x * as(i1, 1))),
id);
496 template <
class SrcIterator,
class SrcAccessor,
497 class DestIterator,
class DestAccessor>
499 resizeImageLinearInterpolation(SrcIterator is, SrcIterator iend, SrcAccessor sa,
500 DestIterator
id, DestIterator idend, DestAccessor da)
502 int w = iend.x - is.x;
503 int h = iend.y - is.y;
505 int wnew = idend.x -
id.x;
506 int hnew = idend.y -
id.y;
508 vigra_precondition((w > 1) && (h > 1),
509 "resizeImageLinearInterpolation(): " 510 "Source image too small.\n");
511 vigra_precondition((wnew > 1) && (hnew > 1),
512 "resizeImageLinearInterpolation(): " 513 "Destination image too small.\n");
515 double const scale = 2.0;
517 typedef typename SrcAccessor::value_type SRCVT;
518 typedef typename NumericTraits<SRCVT>::RealPromote TMPTYPE;
520 typedef typename TmpImage::traverser TmpImageIterator;
528 typename TmpImageIterator::row_iterator lt = line.
upperLeft().rowIterator();
530 for(x=0; x<w; ++x, ++is.x, ++yt.x)
532 typename SrcIterator::column_iterator c1 = is.columnIterator();
533 typename TmpImageIterator::column_iterator ct = yt.columnIterator();
538 lt, line.
accessor(), (double)h/hnew/scale);
540 resizeLineLinearInterpolation(lt, lt + h, line.
accessor(),
545 resizeLineLinearInterpolation(c1, c1 + h, sa,
552 for(y=0; y < hnew; ++y, ++yt.y, ++
id.y)
554 typename DestIterator::row_iterator rd =
id.rowIterator();
555 typename TmpImageIterator::row_iterator rt = yt.rowIterator();
560 lt, line.
accessor(), (double)w/wnew/scale);
562 resizeLineLinearInterpolation(lt, lt + w, line.
accessor(),
567 resizeLineLinearInterpolation(rt, rt + w, tmp.
accessor(),
573 template <
class SrcIterator,
class SrcAccessor,
574 class DestIterator,
class DestAccessor>
576 resizeImageLinearInterpolation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
577 triple<DestIterator, DestIterator, DestAccessor> dest)
579 resizeImageLinearInterpolation(src.first, src.second, src.third,
580 dest.first, dest.second, dest.third);
583 template <
class T1,
class S1,
589 resizeImageLinearInterpolation(srcImageRange(src),
590 destImageRange(dest));
727 template <
class SrcIterator,
class SrcAccessor,
728 class DestIterator,
class DestAccessor,
731 resizeImageSplineInterpolation(
732 SrcIterator src_iter, SrcIterator src_iter_end, SrcAccessor src_acc,
733 DestIterator dest_iter, DestIterator dest_iter_end, DestAccessor dest_acc,
734 SPLINE
const & spline)
737 int width_old = src_iter_end.x - src_iter.x;
738 int height_old = src_iter_end.y - src_iter.y;
740 int width_new = dest_iter_end.x - dest_iter.x;
741 int height_new = dest_iter_end.y - dest_iter.y;
743 vigra_precondition((width_old > 1) && (height_old > 1),
744 "resizeImageSplineInterpolation(): " 745 "Source image too small.\n");
747 vigra_precondition((width_new > 1) && (height_new > 1),
748 "resizeImageSplineInterpolation(): " 749 "Destination image too small.\n");
754 resampling_detail::MapTargetToSourceCoordinate xmapCoordinate(xratio, offset);
755 resampling_detail::MapTargetToSourceCoordinate ymapCoordinate(yratio, offset);
759 double const scale = 2.0;
761 typedef typename SrcAccessor::value_type SRCVT;
762 typedef typename NumericTraits<SRCVT>::RealPromote TMPTYPE;
764 typedef typename TmpImage::traverser TmpImageIterator;
775 createResamplingKernels(spline, ymapCoordinate, kernels);
778 typename TmpImageIterator::row_iterator line_tmp = line.
upperLeft().rowIterator();
780 for(x=0; x<width_old; ++x, ++src_iter.x, ++y_tmp.x)
783 typename SrcIterator::column_iterator c_src = src_iter.columnIterator();
784 typename TmpImageIterator::column_iterator c_tmp = y_tmp.columnIterator();
786 if(prefilterCoeffs.
size() == 0)
788 if(height_new >= height_old)
791 c_tmp, c_tmp + height_new, tmp_acc,
792 kernels, ymapCoordinate);
797 line_tmp, line.
accessor(), (double)height_old/height_new/scale);
799 c_tmp, c_tmp + height_new, tmp_acc,
800 kernels, ymapCoordinate);
807 prefilterCoeffs[0], BORDER_TREATMENT_REFLECT);
808 for(
unsigned int b = 1; b < prefilterCoeffs.
size(); ++b)
812 prefilterCoeffs[b], BORDER_TREATMENT_REFLECT);
814 if(height_new < height_old)
817 line_tmp, line.
accessor(), (double)height_old/height_new/scale);
820 c_tmp, c_tmp + height_new, tmp_acc,
821 kernels, ymapCoordinate);
827 kernels.resize(xperiod);
828 createResamplingKernels(spline, xmapCoordinate, kernels);
830 for(y=0; y < height_new; ++y, ++y_tmp.y, ++dest_iter.y)
832 typename DestIterator::row_iterator r_dest = dest_iter.rowIterator();
833 typename TmpImageIterator::row_iterator r_tmp = y_tmp.rowIterator();
835 if(prefilterCoeffs.
size() == 0)
837 if(width_new >= width_old)
840 r_dest, r_dest + width_new, dest_acc,
841 kernels, xmapCoordinate);
846 line_tmp, line.
accessor(), (double)width_old/width_new/scale);
848 r_dest, r_dest + width_new, dest_acc,
849 kernels, xmapCoordinate);
856 prefilterCoeffs[0], BORDER_TREATMENT_REFLECT);
857 for(
unsigned int b = 1; b < prefilterCoeffs.
size(); ++b)
861 prefilterCoeffs[b], BORDER_TREATMENT_REFLECT);
863 if(width_new < width_old)
866 line_tmp, line.
accessor(), (double)width_old/width_new/scale);
869 r_dest, r_dest + width_new, dest_acc,
870 kernels, xmapCoordinate);
875 template <
class SrcIterator,
class SrcAccessor,
876 class DestIterator,
class DestAccessor>
878 resizeImageSplineInterpolation(SrcIterator is, SrcIterator iend, SrcAccessor sa,
879 DestIterator
id, DestIterator idend, DestAccessor da)
884 template <
class SrcIterator,
class SrcAccessor,
885 class DestIterator,
class DestAccessor,
888 resizeImageSplineInterpolation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
889 triple<DestIterator, DestIterator, DestAccessor> dest,
890 SPLINE
const & spline)
892 resizeImageSplineInterpolation(src.first, src.second, src.third,
893 dest.first, dest.second, dest.third, spline);
896 template <
class SrcIterator,
class SrcAccessor,
897 class DestIterator,
class DestAccessor>
899 resizeImageSplineInterpolation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
900 triple<DestIterator, DestIterator, DestAccessor> dest)
902 resizeImageSplineInterpolation(src.first, src.second, src.third,
903 dest.first, dest.second, dest.third);
906 template <
class T1,
class S1,
912 SPLINE
const & spline)
914 resizeImageSplineInterpolation(srcImageRange(src),
915 destImageRange(dest), spline);
918 template <
class T1,
class S1,
924 resizeImageSplineInterpolation(srcImageRange(src),
925 destImageRange(dest));
989 template <
class SrcIterator,
class SrcAccessor,
990 class DestIterator,
class DestAccessor>
992 resizeImageCatmullRomInterpolation(SrcIterator src_iter, SrcIterator src_iter_end, SrcAccessor src_acc,
993 DestIterator dest_iter, DestIterator dest_iter_end, DestAccessor dest_acc)
995 resizeImageSplineInterpolation(src_iter, src_iter_end, src_acc, dest_iter, dest_iter_end, dest_acc,
999 template <
class SrcIterator,
class SrcAccessor,
1000 class DestIterator,
class DestAccessor>
1002 resizeImageCatmullRomInterpolation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
1003 triple<DestIterator, DestIterator, DestAccessor> dest)
1005 resizeImageCatmullRomInterpolation(src.first, src.second, src.third,
1006 dest.first, dest.second, dest.third);
1009 template <
class T1,
class S1,
1015 resizeImageCatmullRomInterpolation(srcImageRange(src),
1016 destImageRange(dest));
1081 template <
class SrcIterator,
class SrcAccessor,
1082 class DestIterator,
class DestAccessor>
1084 resizeImageCoscotInterpolation(SrcIterator src_iter, SrcIterator src_iter_end, SrcAccessor src_acc,
1085 DestIterator dest_iter, DestIterator dest_iter_end, DestAccessor dest_acc)
1087 resizeImageSplineInterpolation(src_iter, src_iter_end, src_acc, dest_iter, dest_iter_end, dest_acc,
1091 template <
class SrcIterator,
class SrcAccessor,
1092 class DestIterator,
class DestAccessor>
1094 resizeImageCoscotInterpolation(triple<SrcIterator, SrcIterator, SrcAccessor> src,
1095 triple<DestIterator, DestIterator, DestAccessor> dest)
1097 resizeImageCoscotInterpolation(src.first, src.second, src.third,
1098 dest.first, dest.second, dest.third);
1101 template <
class T1,
class S1,
1107 resizeImageCoscotInterpolation(srcImageRange(src),
1108 destImageRange(dest));
1115 #endif // VIGRA_RESIZEIMAGE_HXX Definition: resizeimage.hxx:82
result_type operator()(argument_type x) const
Definition: resizeimage.hxx:103
Accessor accessor()
Definition: basicimage.hxx:1064
param_type denominator() const
Definition: rational.hxx:273
linalg::TemporaryMatrix< T > sin(MultiArrayView< 2, T, C > const &v)
void recursiveSmoothLine(...)
Convolves the image with a 1-dimensional exponential filter.
double radius() const
Definition: resizeimage.hxx:121
unsigned int derivativeOrder() const
Definition: resizeimage.hxx:126
Definition: accessor.hxx:43
T argument_type
Definition: resizeimage.hxx:91
Definition: splines.hxx:268
value_type operator[](value_type x) const
Definition: resizeimage.hxx:115
Definition: basicimage.hxx:262
void recursiveFilterLine(...)
Performs a 1-dimensional recursive convolution of the source signal.
IntType lcm(IntType n, IntType m)
Definition: rational.hxx:122
T result_type
Definition: resizeimage.hxx:94
Fundamental class template for images.
Definition: basicimage.hxx:473
param_type numerator() const
Definition: rational.hxx:269
T value_type
Definition: resizeimage.hxx:88
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:655
ArrayVector< double > const & prefilterCoefficients() const
Definition: resizeimage.hxx:132
linalg::TemporaryMatrix< T > tan(MultiArrayView< 2, T, C > const &v)
size_type size() const
Definition: array_vector.hxx:330
Encapsulate access to the values an iterator points to.
Definition: accessor.hxx:133
linalg::TemporaryMatrix< T > cos(MultiArrayView< 2, T, C > const &v)
void resamplingConvolveLine(...)
Performs a 1-dimensional resampling convolution of the source signal using the given set of kernels...
Definition: rational.hxx:147
Definition: splines.hxx:1309
traverser upperLeft()
Definition: basicimage.hxx:923