/usr/include/vigra/resampling_convolution.hxx is in libvigraimpex-dev 1.7.1+dfsg1-2ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 | /************************************************************************/
/* */
/* Copyright 1998-2004 by Ullrich Koethe */
/* */
/* This file is part of the VIGRA computer vision library. */
/* The VIGRA Website is */
/* http://hci.iwr.uni-heidelberg.de/vigra/ */
/* Please direct questions, bug reports, and contributions to */
/* ullrich.koethe@iwr.uni-heidelberg.de or */
/* vigra@informatik.uni-hamburg.de */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
#ifndef VIGRA_RESAMPLING_CONVOLUTION_HXX
#define VIGRA_RESAMPLING_CONVOLUTION_HXX
#include <cmath>
#include "stdimage.hxx"
#include "array_vector.hxx"
#include "rational.hxx"
#include "functortraits.hxx"
#include "functorexpression.hxx"
#include "transformimage.hxx"
#include "imagecontainer.hxx"
namespace vigra {
namespace resampling_detail
{
struct MapTargetToSourceCoordinate
{
MapTargetToSourceCoordinate(Rational<int> const & samplingRatio,
Rational<int> const & offset)
: a(samplingRatio.denominator()*offset.denominator()),
b(samplingRatio.numerator()*offset.numerator()),
c(samplingRatio.numerator()*offset.denominator())
{}
// the following functions are more efficient realizations of:
// rational_cast<T>(i / samplingRatio + offset);
// we need efficiency because this may be called in the inner loop
int operator()(int i) const
{
return (i * a + b) / c;
}
double toDouble(int i) const
{
return double(i * a + b) / c;
}
Rational<int> toRational(int i) const
{
return Rational<int>(i * a + b, c);
}
bool isExpand2() const
{
return a == 1 && b == 0 && c == 2;
}
bool isReduce2() const
{
return a == 2 && b == 0 && c == 1;
}
int a, b, c;
};
} // namespace resampling_detail
template <>
class FunctorTraits<resampling_detail::MapTargetToSourceCoordinate>
: public FunctorTraitsBase<resampling_detail::MapTargetToSourceCoordinate>
{
public:
typedef VigraTrueType isUnaryFunctor;
};
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class KernelArray>
void
resamplingExpandLine2(SrcIter s, SrcIter send, SrcAcc src,
DestIter d, DestIter dend, DestAcc dest,
KernelArray const & kernels)
{
typedef typename KernelArray::value_type Kernel;
typedef typename KernelArray::const_reference KernelRef;
typedef typename Kernel::const_iterator KernelIter;
typedef typename
PromoteTraits<typename SrcAcc::value_type, typename Kernel::value_type>::Promote
TmpType;
int wo = send - s;
int wn = dend - d;
int wo2 = 2*wo - 2;
int ileft = std::max(kernels[0].right(), kernels[1].right());
int iright = wo + std::min(kernels[0].left(), kernels[1].left()) - 1;
for(int i = 0; i < wn; ++i, ++d)
{
int is = i / 2;
KernelRef kernel = kernels[i & 1];
KernelIter k = kernel.center() + kernel.right();
TmpType sum = NumericTraits<TmpType>::zero();
if(is < ileft)
{
for(int m=is-kernel.right(); m <= is-kernel.left(); ++m, --k)
{
int mm = (m < 0)
? -m
: m;
sum += *k * src(s, mm);
}
}
else if(is > iright)
{
for(int m=is-kernel.right(); m <= is-kernel.left(); ++m, --k)
{
int mm = (m >= wo)
? wo2 - m
: m;
sum += *k * src(s, mm);
}
}
else
{
SrcIter ss = s + is - kernel.right();
for(int m = 0; m < kernel.size(); ++m, --k, ++ss)
{
sum += *k * src(ss);
}
}
dest.set(sum, d);
}
}
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class KernelArray>
void
resamplingReduceLine2(SrcIter s, SrcIter send, SrcAcc src,
DestIter d, DestIter dend, DestAcc dest,
KernelArray const & kernels)
{
typedef typename KernelArray::value_type Kernel;
typedef typename KernelArray::const_reference KernelRef;
typedef typename Kernel::const_iterator KernelIter;
KernelRef kernel = kernels[0];
KernelIter kbegin = kernel.center() + kernel.right();
typedef typename
PromoteTraits<typename SrcAcc::value_type, typename Kernel::value_type>::Promote
TmpType;
int wo = send - s;
int wn = dend - d;
int wo2 = 2*wo - 2;
int ileft = kernel.right();
int iright = wo + kernel.left() - 1;
for(int i = 0; i < wn; ++i, ++d)
{
int is = 2 * i;
KernelIter k = kbegin;
TmpType sum = NumericTraits<TmpType>::zero();
if(is < ileft)
{
for(int m=is-kernel.right(); m <= is-kernel.left(); ++m, --k)
{
int mm = (m < 0)
? -m
: m;
sum += *k * src(s, mm);
}
}
else if(is > iright)
{
for(int m=is-kernel.right(); m <= is-kernel.left(); ++m, --k)
{
int mm = (m >= wo)
? wo2 - m
: m;
sum += *k * src(s, mm);
}
}
else
{
SrcIter ss = s + is - kernel.right();
for(int m = 0; m < kernel.size(); ++m, --k, ++ss)
{
sum += *k * src(ss);
}
}
dest.set(sum, d);
}
}
/** \addtogroup ResamplingConvolutionFilters Resampling Convolution Filters
These functions implement the convolution operation when the source and target images
have different sizes. This is realized by accessing a continous kernel at the
appropriate non-integer positions. The technique is, for example, described in
D. Schumacher: <i>General Filtered Image Rescaling</i>, in: Graphics Gems III,
Academic Press, 1992.
*/
//@{
/********************************************************/
/* */
/* resamplingConvolveLine */
/* */
/********************************************************/
/** \brief Performs a 1-dimensional resampling convolution of the source signal using the given
set of kernels.
This function is mainly used internally: It is called for each dimension of a
higher dimensional array in order to perform a separable resize operation.
<b> Declaration:</b>
<b>\#include</b> \<<a href="resampling__convolution_8hxx-source.html">vigra/resampling_convolution.hxx</a>\>
\code
namespace vigra {
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class KernelArray,
class Functor>
void
resamplingConvolveLine(SrcIter s, SrcIter send, SrcAcc src,
DestIter d, DestIter dend, DestAcc dest,
KernelArray const & kernels,
Functor mapTargetToSourceCoordinate)
}
\endcode
*/
doxygen_overloaded_function(template <...> void resamplingConvolveLine)
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class KernelArray,
class Functor>
void
resamplingConvolveLine(SrcIter s, SrcIter send, SrcAcc src,
DestIter d, DestIter dend, DestAcc dest,
KernelArray const & kernels,
Functor mapTargetToSourceCoordinate)
{
if(mapTargetToSourceCoordinate.isExpand2())
{
resamplingExpandLine2(s, send, src, d, dend, dest, kernels);
return;
}
if(mapTargetToSourceCoordinate.isReduce2())
{
resamplingReduceLine2(s, send, src, d, dend, dest, kernels);
return;
}
typedef typename
NumericTraits<typename SrcAcc::value_type>::RealPromote
TmpType;
typedef typename KernelArray::value_type Kernel;
typedef typename Kernel::const_iterator KernelIter;
int wo = send - s;
int wn = dend - d;
int wo2 = 2*wo - 2;
int i;
typename KernelArray::const_iterator kernel = kernels.begin();
for(i=0; i<wn; ++i, ++d, ++kernel)
{
// use the kernels periodically
if(kernel == kernels.end())
kernel = kernels.begin();
// calculate current target point into source location
int is = mapTargetToSourceCoordinate(i);
TmpType sum = NumericTraits<TmpType>::zero();
int lbound = is - kernel->right(),
hbound = is - kernel->left();
KernelIter k = kernel->center() + kernel->right();
if(lbound < 0 || hbound >= wo)
{
vigra_precondition(-lbound < wo && wo2 - hbound >= 0,
"resamplingConvolveLine(): kernel or offset larger than image.");
for(int m=lbound; m <= hbound; ++m, --k)
{
int mm = (m < 0) ?
-m :
(m >= wo) ?
wo2 - m :
m;
sum = TmpType(sum + *k * src(s, mm));
}
}
else
{
SrcIter ss = s + lbound;
SrcIter ssend = s + hbound;
for(; ss <= ssend; ++ss, --k)
{
sum = TmpType(sum + *k * src(ss));
}
}
dest.set(sum, d);
}
}
template <class Kernel, class MapCoordinate, class KernelArray>
void
createResamplingKernels(Kernel const & kernel,
MapCoordinate const & mapCoordinate, KernelArray & kernels)
{
for(unsigned int idest = 0; idest < kernels.size(); ++idest)
{
int isrc = mapCoordinate(idest);
double idsrc = mapCoordinate.toDouble(idest);
double offset = idsrc - isrc;
double radius = kernel.radius();
int left = int(ceil(-radius - offset));
int right = int(floor(radius - offset));
kernels[idest].initExplicitly(left, right);
double x = left + offset;
for(int i = left; i <= right; ++i, ++x)
kernels[idest][i] = kernel(x);
kernels[idest].normalize(1.0, kernel.derivativeOrder(), offset);
}
}
/** \brief Apply a resampling filter in the x-direction.
This function implements a convolution operation in x-direction
(i.e. applies a 1D filter to every row) where the width of the source
and destination images differ. This is typically used to avoid aliasing if
the image is scaled down, or to interpolate smoothly if the image is scaled up.
The target coordinates are transformed into source coordinates by
\code
xsource = (xtarget - offset) / samplingRatio
\endcode
The <tt>samplingRatio</tt> and <tt>offset</tt> must be given as \ref vigra::Rational
in order to avoid rounding errors in this transformation. It is required that for all
pixels of the target image, <tt>xsource</tt> remains within the range of the source
image (i.e. <tt>0 <= xsource <= sourceWidth-1</tt>. Since <tt>xsource</tt> is
in general not an integer, the <tt>kernel</tt> must be a functor that can be accessed at
arbitrary (<tt>double</tt>) coordinates. It must also provide a member function <tt>radius()</tt>
which specifies the support (non-zero interval) of the kernel. VIGRA already
provides a number of suitable functors, e.g. \ref vigra::Gaussian, \ref vigra::BSpline
\ref vigra::CatmullRomSpline, and \ref vigra::CoscotFunction. The function
\ref resizeImageSplineInterpolation() is implemented by means resamplingConvolveX() and
resamplingConvolveY().
<b> Declarations:</b>
pass arguments explicitly:
\code
namespace vigra {
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class Kernel>
void
resamplingConvolveX(SrcIter sul, SrcIter slr, SrcAcc src,
DestIter dul, DestIter dlr, DestAcc dest,
Kernel const & kernel,
Rational<int> const & samplingRatio, Rational<int> const & offset);
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories :
\code
namespace vigra {
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class Kernel>
void
resamplingConvolveX(triple<SrcIter, SrcIter, SrcAcc> src,
triple<DestIter, DestIter, DestAcc> dest,
Kernel const & kernel,
Rational<int> const & samplingRatio, Rational<int> const & offset);
}
\endcode
<b> Usage:</b>
<b>\#include</b> \<<a href="resampling__convolution_8hxx-source.html">vigra/resampling_convolution.hxx</a>\>
\code
Rational<int> ratio(2), offset(0);
FImage src(w,h),
dest(rational_cast<int>(ratio*w), h);
float sigma = 2.0;
Gaussian<float> smooth(sigma);
...
// simpultaneously enlarge and smooth source image
resamplingConvolveX(srcImageRange(src), destImageRange(dest),
smooth, ratio, offset);
\endcode
<b> Required Interface:</b>
\code
Kernel kernel;
int kernelRadius = kernel.radius();
double x = ...; // must be <= radius()
double value = kernel(x);
\endcode
*/
doxygen_overloaded_function(template <...> void resamplingConvolveX)
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class Kernel>
void
resamplingConvolveX(SrcIter sul, SrcIter slr, SrcAcc src,
DestIter dul, DestIter dlr, DestAcc dest,
Kernel const & kernel,
Rational<int> const & samplingRatio, Rational<int> const & offset)
{
int wold = slr.x - sul.x;
int wnew = dlr.x - dul.x;
vigra_precondition(!samplingRatio.is_inf() && samplingRatio > 0,
"resamplingConvolveX(): sampling ratio must be > 0 and < infinity");
vigra_precondition(!offset.is_inf(),
"resamplingConvolveX(): offset must be < infinity");
int period = lcm(samplingRatio.numerator(), samplingRatio.denominator());
resampling_detail::MapTargetToSourceCoordinate mapCoordinate(samplingRatio, offset);
ArrayVector<Kernel1D<double> > kernels(period);
createResamplingKernels(kernel, mapCoordinate, kernels);
for(; sul.y < slr.y; ++sul.y, ++dul.y)
{
typename SrcIter::row_iterator sr = sul.rowIterator();
typename DestIter::row_iterator dr = dul.rowIterator();
resamplingConvolveLine(sr, sr+wold, src, dr, dr+wnew, dest,
kernels, mapCoordinate);
}
}
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class Kernel>
inline void
resamplingConvolveX(triple<SrcIter, SrcIter, SrcAcc> src,
triple<DestIter, DestIter, DestAcc> dest,
Kernel const & kernel,
Rational<int> const & samplingRatio, Rational<int> const & offset)
{
resamplingConvolveX(src.first, src.second, src.third,
dest.first, dest.second, dest.third,
kernel, samplingRatio, offset);
}
/********************************************************/
/* */
/* resamplingConvolveY */
/* */
/********************************************************/
/** \brief Apply a resampling filter in the y-direction.
This function implements a convolution operation in y-direction
(i.e. applies a 1D filter to every column) where the height of the source
and destination images differ. This is typically used to avoid aliasing if
the image is scaled down, or to interpolate smoothly if the image is scaled up.
The target coordinates are transformed into source coordinates by
\code
ysource = (ytarget - offset) / samplingRatio
\endcode
The <tt>samplingRatio</tt> and <tt>offset</tt> must be given as \ref vigra::Rational
in order to avoid rounding errors in this transformation. It is required that for all
pixels of the target image, <tt>ysource</tt> remains within the range of the source
image (i.e. <tt>0 <= ysource <= sourceHeight-1</tt>. Since <tt>ysource</tt> is
in general not an integer, the <tt>kernel</tt> must be a functor that can be accessed at
arbitrary (<tt>double</tt>) coordinates. It must also provide a member function <tt>radius()</tt>
which specifies the support (non-zero interval) of the kernel. VIGRA already
provides a number of suitable functors, e.g. \ref vigra::Gaussian, \ref vigra::BSpline
\ref vigra::CatmullRomSpline, and \ref vigra::CoscotFunction. The function
\ref resizeImageSplineInterpolation() is implemented by means resamplingConvolveX() and
resamplingConvolveY().
<b> Declarations:</b>
pass arguments explicitly:
\code
namespace vigra {
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class Kernel>
void
resamplingConvolveY(SrcIter sul, SrcIter slr, SrcAcc src,
DestIter dul, DestIter dlr, DestAcc dest,
Kernel const & kernel,
Rational<int> const & samplingRatio, Rational<int> const & offset);
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories :
\code
namespace vigra {
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class Kernel>
void
resamplingConvolveY(triple<SrcIter, SrcIter, SrcAcc> src,
triple<DestIter, DestIter, DestAcc> dest,
Kernel const & kernel,
Rational<int> const & samplingRatio, Rational<int> const & offset);
}
\endcode
<b> Usage:</b>
<b>\#include</b> \<<a href="resampling__convolution_8hxx-source.html">vigra/resampling_convolution.hxx</a>\>
\code
Rational<int> ratio(2), offset(0);
FImage src(w,h),
dest(w, rational_cast<int>(ratio*h));
float sigma = 2.0;
Gaussian<float> smooth(sigma);
...
// simpultaneously enlarge and smooth source image
resamplingConvolveY(srcImageRange(src), destImageRange(dest),
smooth, ratio, offset);
\endcode
<b> Required Interface:</b>
\code
Kernel kernel;
int kernelRadius = kernel.radius();
double y = ...; // must be <= radius()
double value = kernel(y);
\endcode
*/
doxygen_overloaded_function(template <...> void resamplingConvolveY)
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class Kernel>
void
resamplingConvolveY(SrcIter sul, SrcIter slr, SrcAcc src,
DestIter dul, DestIter dlr, DestAcc dest,
Kernel const & kernel,
Rational<int> const & samplingRatio, Rational<int> const & offset)
{
int hold = slr.y - sul.y;
int hnew = dlr.y - dul.y;
vigra_precondition(!samplingRatio.is_inf() && samplingRatio > 0,
"resamplingConvolveY(): sampling ratio must be > 0 and < infinity");
vigra_precondition(!offset.is_inf(),
"resamplingConvolveY(): offset must be < infinity");
int period = lcm(samplingRatio.numerator(), samplingRatio.denominator());
resampling_detail::MapTargetToSourceCoordinate mapCoordinate(samplingRatio, offset);
ArrayVector<Kernel1D<double> > kernels(period);
createResamplingKernels(kernel, mapCoordinate, kernels);
for(; sul.x < slr.x; ++sul.x, ++dul.x)
{
typename SrcIter::column_iterator sc = sul.columnIterator();
typename DestIter::column_iterator dc = dul.columnIterator();
resamplingConvolveLine(sc, sc+hold, src, dc, dc+hnew, dest,
kernels, mapCoordinate);
}
}
template <class SrcIter, class SrcAcc,
class DestIter, class DestAcc,
class Kernel>
inline void
resamplingConvolveY(triple<SrcIter, SrcIter, SrcAcc> src,
triple<DestIter, DestIter, DestAcc> dest,
Kernel const & kernel,
Rational<int> const & samplingRatio, Rational<int> const & offset)
{
resamplingConvolveY(src.first, src.second, src.third,
dest.first, dest.second, dest.third,
kernel, samplingRatio, offset);
}
/********************************************************/
/* */
/* resamplingConvolveImage */
/* */
/********************************************************/
/** \brief Apply two separable resampling filters successively, the first in x-direction,
the second in y-direction.
This function is a shorthand for the concatenation of a call to
\ref resamplingConvolveX() and \ref resamplingConvolveY()
with the given kernels. See there for detailed documentation.
<b> Declarations:</b>
pass arguments explicitly:
\code
namespace vigra {
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor,
class KernelX, class KernelY>
void resamplingConvolveImage(SrcIterator sul,SrcIterator slr, SrcAccessor src,
DestIterator dul, DestIterator dlr, DestAccessor dest,
KernelX const & kx,
Rational<int> const & samplingRatioX, Rational<int> const & offsetX,
KernelY const & ky,
Rational<int> const & samplingRatioY, Rational<int> const & offsetY);
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories :
\code
namespace vigra {
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor,
class KernelX, class KernelY>
void
resamplingConvolveImage(triple<SrcIterator, SrcIterator, SrcAccessor> src,
triple<DestIterator, DestIterator, DestAccessor> dest,
KernelX const & kx,
Rational<int> const & samplingRatioX, Rational<int> const & offsetX,
KernelY const & ky,
Rational<int> const & samplingRatioY, Rational<int> const & offsetY);
}
\endcode
<b> Usage:</b>
<b>\#include</b> \<<a href="resampling__convolution_8hxx-source.html">vigra/resampling_convolution.hxx</a>\>
\code
Rational<int> xratio(2), yratio(3), offset(0);
FImage src(w,h),
dest(rational_cast<int>(xratio*w), rational_cast<int>(yratio*h));
float sigma = 2.0;
Gaussian<float> smooth(sigma);
...
// simpultaneously enlarge and smooth source image
resamplingConvolveImage(srcImageRange(src), destImageRange(dest),
smooth, xratio, offset,
smooth, yratio, offset);
\endcode
*/
doxygen_overloaded_function(template <...> void resamplingConvolveImage)
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor,
class KernelX, class KernelY>
void resamplingConvolveImage(SrcIterator sul,SrcIterator slr, SrcAccessor src,
DestIterator dul, DestIterator dlr, DestAccessor dest,
KernelX const & kx,
Rational<int> const & samplingRatioX, Rational<int> const & offsetX,
KernelY const & ky,
Rational<int> const & samplingRatioY, Rational<int> const & offsetY)
{
typedef typename
NumericTraits<typename SrcAccessor::value_type>::RealPromote
TmpType;
BasicImage<TmpType> tmp(dlr.x - dul.x, slr.y - sul.y);
resamplingConvolveX(srcIterRange(sul, slr, src),
destImageRange(tmp),
kx, samplingRatioX, offsetX);
resamplingConvolveY(srcImageRange(tmp),
destIterRange(dul, dlr, dest),
ky, samplingRatioY, offsetY);
}
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor,
class KernelX, class KernelY>
inline void
resamplingConvolveImage(triple<SrcIterator, SrcIterator, SrcAccessor> src,
triple<DestIterator, DestIterator, DestAccessor> dest,
KernelX const & kx,
Rational<int> const & samplingRatioX, Rational<int> const & offsetX,
KernelY const & ky,
Rational<int> const & samplingRatioY, Rational<int> const & offsetY)
{
resamplingConvolveImage(src.first, src.second, src.third,
dest.first, dest.second, dest.third,
kx, samplingRatioX, offsetX,
ky, samplingRatioY, offsetY);
}
/** \brief Two-fold down-sampling for image pyramid construction.
Sorry, no \ref detailedDocumentation() available yet.
<b> Declarations:</b>
<b>\#include</b> \<<a href="resampling__convolution_8hxx-source.html">vigra/resampling_convolution.hxx</a>\><br>
Namespace: vigra
pass arguments explicitly:
\code
namespace vigra {
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor>
void pyramidReduceBurtFilter(SrcIterator sul, SrcIterator slr, SrcAccessor src,
DestIterator dul, DestIterator dlr, DestAccessor dest,
double centerValue = 0.4);
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories :
\code
namespace vigra {
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor>
void pyramidReduceBurtFilter(triple<SrcIterator, SrcIterator, SrcAccessor> src,
triple<DestIterator, DestIterator, DestAccessor> dest,
double centerValue = 0.4);
}
\endcode
use a \ref vigra::ImagePyramid :
\code
namespace vigra {
template <class Image, class Alloc>
void pyramidReduceBurtFilter(ImagePyramid<Image, Alloc> & pyramid, int fromLevel, int toLevel,
double centerValue = 0.4);
}
\endcode
*/
doxygen_overloaded_function(template <...> void pyramidReduceBurtFilter)
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor>
void pyramidReduceBurtFilter(SrcIterator sul, SrcIterator slr, SrcAccessor src,
DestIterator dul, DestIterator dlr, DestAccessor dest,
double centerValue = 0.4)
{
vigra_precondition(0.25 <= centerValue && centerValue <= 0.5,
"pyramidReduceBurtFilter(): centerValue must be between 0.25 and 0.5.");
int wold = slr.x - sul.x;
int wnew = dlr.x - dul.x;
int hold = slr.y - sul.y;
int hnew = dlr.y - dul.y;
vigra_precondition(wnew == (wold + 1) / 2 && hnew == (hold + 1) / 2,
"pyramidReduceBurtFilter(): oldSize = ceil(newSize / 2) required.");
vigra_precondition(wnew == (wold + 1) / 2 && hnew == (hold + 1) / 2,
"pyramidReduceBurtFilter(): oldSize = ceil(newSize / 2) required.");
Rational<int> samplingRatio(1,2), offset(0);
resampling_detail::MapTargetToSourceCoordinate mapCoordinate(samplingRatio, offset);
ArrayVector<Kernel1D<double> > kernels(1);
kernels[0].initExplicitly(-2, 2) = 0.25 - centerValue / 2.0, 0.25, centerValue, 0.25, 0.25 - centerValue / 2.0;
typedef typename
NumericTraits<typename SrcAccessor::value_type>::RealPromote
TmpType;
typedef BasicImage<TmpType> TmpImage;
typedef typename TmpImage::traverser TmpIterator;
BasicImage<TmpType> tmp(wnew, hold);
TmpIterator tul = tmp.upperLeft();
for(; sul.y < slr.y; ++sul.y, ++tul.y)
{
typename SrcIterator::row_iterator sr = sul.rowIterator();
typename TmpIterator::row_iterator tr = tul.rowIterator();
// FIXME: replace with reduceLineBurtFilter()
resamplingConvolveLine(sr, sr+wold, src, tr, tr+wnew, tmp.accessor(),
kernels, mapCoordinate);
}
tul = tmp.upperLeft();
for(; dul.x < dlr.x; ++dul.x, ++tul.x)
{
typename DestIterator::column_iterator dc = dul.columnIterator();
typename TmpIterator::column_iterator tc = tul.columnIterator();
resamplingConvolveLine(tc, tc+hold, tmp.accessor(), dc, dc+hnew, dest,
kernels, mapCoordinate);
}
}
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor>
inline
void pyramidReduceBurtFilter(triple<SrcIterator, SrcIterator, SrcAccessor> src,
triple<DestIterator, DestIterator, DestAccessor> dest,
double centerValue = 0.4)
{
pyramidReduceBurtFilter(src.first, src.second, src.third,
dest.first, dest.second, dest.third, centerValue);
}
template <class Image, class Alloc>
inline
void pyramidReduceBurtFilter(ImagePyramid<Image, Alloc> & pyramid, int fromLevel, int toLevel,
double centerValue = 0.4)
{
vigra_precondition(fromLevel < toLevel,
"pyramidReduceBurtFilter(): fromLevel must be smaller than toLevel.");
vigra_precondition(pyramid.lowestLevel() <= fromLevel && toLevel <= pyramid.highestLevel(),
"pyramidReduceBurtFilter(): fromLevel and toLevel must be between the lowest and highest pyramid levels (inclusive).");
for(int i=fromLevel+1; i <= toLevel; ++i)
pyramidReduceBurtFilter(srcImageRange(pyramid[i-1]), destImageRange(pyramid[i]), centerValue);
}
/** \brief Two-fold up-sampling for image pyramid reconstruction.
Sorry, no \ref detailedDocumentation() available yet.
<b> Declarations:</b>
<b>\#include</b> \<<a href="resampling__convolution_8hxx-source.html">vigra/resampling_convolution.hxx</a>\><br>
Namespace: vigra
pass arguments explicitly:
\code
namespace vigra {
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor>
void pyramidExpandBurtFilter(SrcIterator sul, SrcIterator slr, SrcAccessor src,
DestIterator dul, DestIterator dlr, DestAccessor dest,
double centerValue = 0.4);
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories :
\code
namespace vigra {
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor>
void pyramidExpandBurtFilter(triple<SrcIterator, SrcIterator, SrcAccessor> src,
triple<DestIterator, DestIterator, DestAccessor> dest,
double centerValue = 0.4);
}
\endcode
use a \ref vigra::ImagePyramid :
\code
namespace vigra {
template <class Image, class Alloc>
void pyramidExpandBurtFilter(ImagePyramid<Image, Alloc> & pyramid, int fromLevel, int toLevel,
double centerValue = 0.4);
}
\endcode
*/
doxygen_overloaded_function(template <...> void pyramidExpandBurtFilter)
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor>
void pyramidExpandBurtFilter(SrcIterator sul, SrcIterator slr, SrcAccessor src,
DestIterator dul, DestIterator dlr, DestAccessor dest,
double centerValue = 0.4)
{
vigra_precondition(0.25 <= centerValue && centerValue <= 0.5,
"pyramidExpandBurtFilter(): centerValue must be between 0.25 and 0.5.");
int wold = slr.x - sul.x;
int wnew = dlr.x - dul.x;
int hold = slr.y - sul.y;
int hnew = dlr.y - dul.y;
vigra_precondition(wold == (wnew + 1) / 2 && hold == (hnew + 1) / 2,
"pyramidExpandBurtFilter(): oldSize = ceil(newSize / 2) required.");
vigra_precondition(wold == (wnew + 1) / 2 && hold == (hnew + 1) / 2,
"pyramidExpandBurtFilter(): oldSize = ceil(newSize / 2) required.");
Rational<int> samplingRatio(2), offset(0);
resampling_detail::MapTargetToSourceCoordinate mapCoordinate(samplingRatio, offset);
ArrayVector<Kernel1D<double> > kernels(2);
kernels[0].initExplicitly(-1, 1) = 0.5 - centerValue, 2.0*centerValue, 0.5 - centerValue;
kernels[1].initExplicitly(-1, 0) = 0.5, 0.5;
typedef typename
NumericTraits<typename SrcAccessor::value_type>::RealPromote
TmpType;
typedef BasicImage<TmpType> TmpImage;
typedef typename TmpImage::traverser TmpIterator;
BasicImage<TmpType> tmp(wnew, hold);
TmpIterator tul = tmp.upperLeft();
for(; sul.y < slr.y; ++sul.y, ++tul.y)
{
typename SrcIterator::row_iterator sr = sul.rowIterator();
typename TmpIterator::row_iterator tr = tul.rowIterator();
// FIXME: replace with expandLineBurtFilter()
resamplingConvolveLine(sr, sr+wold, src, tr, tr+wnew, tmp.accessor(),
kernels, mapCoordinate);
}
tul = tmp.upperLeft();
for(; dul.x < dlr.x; ++dul.x, ++tul.x)
{
typename DestIterator::column_iterator dc = dul.columnIterator();
typename TmpIterator::column_iterator tc = tul.columnIterator();
resamplingConvolveLine(tc, tc+hold, tmp.accessor(), dc, dc+hnew, dest,
kernels, mapCoordinate);
}
}
template <class SrcIterator, class SrcAccessor,
class DestIterator, class DestAccessor>
inline
void pyramidExpandBurtFilter(triple<SrcIterator, SrcIterator, SrcAccessor> src,
triple<DestIterator, DestIterator, DestAccessor> dest,
double centerValue = 0.4)
{
pyramidExpandBurtFilter(src.first, src.second, src.third,
dest.first, dest.second, dest.third, centerValue);
}
template <class Image, class Alloc>
inline
void pyramidExpandBurtFilter(ImagePyramid<Image, Alloc> & pyramid, int fromLevel, int toLevel,
double centerValue = 0.4)
{
vigra_precondition(fromLevel > toLevel,
"pyramidExpandBurtFilter(): fromLevel must be larger than toLevel.");
vigra_precondition(pyramid.lowestLevel() <= toLevel && fromLevel <= pyramid.highestLevel(),
"pyramidExpandBurtFilter(): fromLevel and toLevel must be between the lowest and highest pyramid levels (inclusive).");
for(int i=fromLevel-1; i >= toLevel; --i)
pyramidExpandBurtFilter(srcImageRange(pyramid[i+1]), destImageRange(pyramid[i]), centerValue);
}
/** \brief Create a Laplacian pyramid.
Sorry, no \ref detailedDocumentation() available yet.
<b>\#include</b> \<<a href="resampling__convolution_8hxx-source.html">vigra/resampling_convolution.hxx</a>\><br>
Namespace: vigra
*/
template <class Image, class Alloc>
inline
void pyramidReduceBurtLaplacian(ImagePyramid<Image, Alloc> & pyramid, int fromLevel, int toLevel,
double centerValue = 0.4)
{
using namespace functor;
pyramidReduceBurtFilter(pyramid, fromLevel, toLevel, centerValue);
for(int i=fromLevel; i < toLevel; ++i)
{
typename ImagePyramid<Image, Alloc>::value_type tmpImage(pyramid[i].size());
pyramidExpandBurtFilter(srcImageRange(pyramid[i+1]), destImageRange(tmpImage), centerValue);
combineTwoImages(srcImageRange(tmpImage), srcImage(pyramid[i]), destImage(pyramid[i]),
Arg1() - Arg2());
}
}
/** \brief Reconstruct a Laplacian pyramid.
Sorry, no \ref detailedDocumentation() available yet.
<b>\#include</b> \<<a href="resampling__convolution_8hxx-source.html">vigra/resampling_convolution.hxx</a>\><br>
Namespace: vigra
*/
template <class Image, class Alloc>
inline
void pyramidExpandBurtLaplacian(ImagePyramid<Image, Alloc> & pyramid, int fromLevel, int toLevel,
double centerValue = 0.4)
{
using namespace functor;
vigra_precondition(fromLevel > toLevel,
"pyramidExpandBurtLaplacian(): fromLevel must be larger than toLevel.");
vigra_precondition(pyramid.lowestLevel() <= toLevel && fromLevel <= pyramid.highestLevel(),
"pyramidExpandBurtLaplacian(): fromLevel and toLevel must be between the lowest and highest pyramid levels (inclusive).");
for(int i=fromLevel-1; i >= toLevel; --i)
{
typename ImagePyramid<Image, Alloc>::value_type tmpImage(pyramid[i].size());
pyramidExpandBurtFilter(srcImageRange(pyramid[i+1]), destImageRange(tmpImage), centerValue);
combineTwoImages(srcImageRange(tmpImage), srcImage(pyramid[i]), destImage(pyramid[i]),
Arg1() - Arg2());
}
}
//@}
} // namespace vigra
#endif /* VIGRA_RESAMPLING_CONVOLUTION_HXX */
|