/usr/include/vigra/multi_resize.hxx is in libvigraimpex-dev 1.10.0+dfsg-3ubuntu2.
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 | /************************************************************************/
/* */
/* 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_MULTI_RESIZE_HXX
#define VIGRA_MULTI_RESIZE_HXX
#include <vector>
#include "resizeimage.hxx"
#include "navigator.hxx"
#include "multi_shape.hxx"
namespace vigra {
namespace detail {
template <class SrcIterator, class Shape, class SrcAccessor,
class DestIterator, class DestAccessor, class Kernel>
void
internalResizeMultiArrayOneDimension(
SrcIterator si, Shape const & sshape, SrcAccessor src,
DestIterator di, Shape const & dshape, DestAccessor dest,
Kernel const & spline, unsigned int d)
{
enum { N = 1 + SrcIterator::level };
typedef typename NumericTraits<typename DestAccessor::value_type>::RealPromote TmpType;
typedef MultiArrayNavigator<SrcIterator, N> SNavigator;
typedef MultiArrayNavigator<DestIterator, N> DNavigator;
SNavigator snav( si, sshape, d );
DNavigator dnav( di, dshape, d );
int ssize = sshape[d];
int dsize = dshape[d];
vigra_precondition(ssize > 1,
"resizeMultiArraySplineInterpolation(): "
"Source array too small.\n");
Rational<int> ratio(dsize - 1, ssize - 1);
Rational<int> offset(0);
resampling_detail::MapTargetToSourceCoordinate mapCoordinate(ratio, offset);
int period = lcm(ratio.numerator(), ratio.denominator());
ArrayVector<double> const & prefilterCoeffs = spline.prefilterCoefficients();
ArrayVector<Kernel1D<double> > kernels(period);
createResamplingKernels(spline, mapCoordinate, kernels);
// temporary array to hold the current line to enable in-place operation
ArrayVector<TmpType> tmp( ssize );
typename ArrayVector<TmpType>::iterator t = tmp.begin(), tend = tmp.end();
typename AccessorTraits<TmpType>::default_accessor ta;
for( ; snav.hasMore(); snav++, dnav++ )
{
// first copy source to temp for maximum cache efficiency
copyLine( snav.begin(), snav.end(), src, t, ta);
for(unsigned int b = 0; b < prefilterCoeffs.size(); ++b)
{
recursiveFilterLine(t, tend, ta, t, ta,
prefilterCoeffs[b], BORDER_TREATMENT_REFLECT);
}
resamplingConvolveLine(t, tend, ta,
dnav.begin(), dnav.begin() + dsize, dest,
kernels, mapCoordinate);
}
}
} // namespace detail
/** \addtogroup GeometricTransformations Geometric Transformations
*/
//@{
/***************************************************************/
/* */
/* resizeMultiArraySplineInterpolation */
/* */
/***************************************************************/
/** \brief Resize MultiArray using B-spline interpolation.
<b> Declarations:</b>
pass arbitrary-dimensional array views:
\code
namespace vigra {
template <unsigned int N, class T1, class S1,
class T2, class S2,
class Kernel = BSpline<3, double> >
void
resizeMultiArraySplineInterpolation(MultiArrayView<N, T1, S1> const & source,
MultiArrayView<N, T2, S2> dest,
Kernel const & spline = BSpline<3, double>());
}
\endcode
\deprecatedAPI{resizeMultiArraySplineInterpolation}
pass \ref MultiIteratorPage "MultiIterators" and \ref DataAccessors :
\code
namespace vigra {
template <class SrcIterator, class Shape, class SrcAccessor,
class DestIterator, class DestAccessor,
class Kernel = BSpline<3, double> >
void
resizeMultiArraySplineInterpolation(
SrcIterator si, Shape const & sshape, SrcAccessor src,
DestIterator di, Shape const & dshape, DestAccessor dest,
Kernel const & spline = BSpline<3, double>());
}
\endcode
use argument objects in conjunction with \ref ArgumentObjectFactories :
\code
namespace vigra {
template <class SrcIterator, class Shape, class SrcAccessor,
class DestIterator, class DestAccessor,
class Kernel = BSpline<3, double> >
void
resizeMultiArraySplineInterpolation(
triple<SrcIterator, Shape, SrcAccessor> src,
triple<DestIterator, Shape, DestAccessor> dest,
Kernel const & spline = BSpline<3, double>());
}
\endcode
\deprecatedEnd
The function implements separable spline interpolation algorithm described in
M. Unser, A. Aldroubi, M. Eden, <i>"B-Spline Signal Processing"</i>
IEEE Transactions on Signal Processing, vol. 41, no. 2, pp. 821-833 (part I),
pp. 834-848 (part II), 1993.
to obtain optimal interpolation quality and speed. You may pass the function
a spline of arbitrary order (e.g. <TT>BSpline<ORDER, double></tt> or
<TT>CatmullRomSpline<double></tt>). The default is a third order spline
which gives a twice continuously differentiable interpolant.
The implementation ensures that image values are interpolated rather
than smoothed by first calling a recursive (sharpening) prefilter as
described in the above paper. Then the actual interpolation is done
using \ref resamplingConvolveLine().
The range of both the input and output images (resp. regions)
must be given. The input image must have a size of at
least 4x4, the destination of at least 2x2. The scaling factors are then calculated
accordingly. If the source image is larger than the destination, it
is smoothed (band limited) using a recursive
exponential filter. The source value_type (SrcAccessor::value_type) must
be a linear algebra, i.e. it must support addition, subtraction,
and multiplication (+, -, *), multiplication with a scalar
real number and \ref NumericTraits "NumericTraits".
The function uses accessors.
<b> Usage:</b>
<b>\#include</b> \<vigra/multi_resize.hxx\><br>
Namespace: vigra
\code
MultiArray<3, float> src(Shape3(5, 7, 10)),
dest(Shape3(9, 13, 19)); // double the size
// use default cubic spline interpolator
resizeMultiArraySplineInterpolation(src, dest);
// use linear interpolator
resizeMultiArraySplineInterpolation(src, dest, BSpline<1, double>());
\endcode
\deprecatedUsage{resizeMultiArraySplineInterpolation}
\code
vigra::MultiArray<3, float> src(Shape3(5, 7, 10)),
dest(Shape3(9, 13, 19)); // double the size
// use linear interpolator
vigra::resizeMultiArraySplineInterpolation(srcMultiArrayRange(src),
destMultiArrayRange(dest), BSpline<1, double>());
// use default cubic spline interpolator
vigra::resizeMultiArraySplineInterpolation(
srcMultiArrayRange(src),
destMultiArrayRange(dest));
\endcode
<b> Required Interface:</b>
The source and destination iterators must be compatible with \ref vigra::MultiIterator. The array value
types must be models of \ref LinearSpace.
\deprecatedEnd
*/
doxygen_overloaded_function(template <...> void resizeMultiArraySplineInterpolation)
template <class SrcIterator, class Shape, class SrcAccessor,
class DestIterator, class DestAccessor,
class Kernel>
void
resizeMultiArraySplineInterpolation(
SrcIterator si, Shape const & sshape, SrcAccessor src,
DestIterator di, Shape const & dshape, DestAccessor dest,
Kernel const & spline)
{
enum { N = 1 + SrcIterator::level };
typedef typename NumericTraits<typename DestAccessor::value_type>::RealPromote TmpType;
typedef typename AccessorTraits<TmpType>::default_accessor TmpAccessor;
if(N==1)
{
detail::internalResizeMultiArrayOneDimension(si, sshape, src,
di, dshape, dest, spline, 0);
}
else
{
unsigned int d = 0;
Shape tmpShape(sshape);
tmpShape[d] = dshape[d];
MultiArray<N, TmpType> tmp(tmpShape);
TmpAccessor ta;
detail::internalResizeMultiArrayOneDimension(si, sshape, src,
tmp.traverser_begin(), tmpShape, ta, spline, d);
d = 1;
for(; d<N-1; ++d)
{
tmpShape[d] = dshape[d];
MultiArray<N, TmpType> dtmp(tmpShape);
detail::internalResizeMultiArrayOneDimension(tmp.traverser_begin(), tmp.shape(), ta,
dtmp.traverser_begin(), tmpShape, ta, spline, d);
dtmp.swap(tmp);
}
detail::internalResizeMultiArrayOneDimension(tmp.traverser_begin(), tmp.shape(), ta,
di, dshape, dest, spline, d);
}
}
template <class SrcIterator, class Shape, class SrcAccessor,
class DestIterator, class DestAccessor>
inline void
resizeMultiArraySplineInterpolation(
SrcIterator si, Shape const & sshape, SrcAccessor src,
DestIterator di, Shape const & dshape, DestAccessor dest)
{
resizeMultiArraySplineInterpolation(si, sshape, src, di, dshape, dest, BSpline<3, double>());
}
template <class SrcIterator, class Shape, class SrcAccessor,
class DestIterator, class DestAccessor,
class Kernel>
inline void
resizeMultiArraySplineInterpolation(triple<SrcIterator, Shape, SrcAccessor> src,
triple<DestIterator, Shape, DestAccessor> dest,
Kernel const & spline)
{
resizeMultiArraySplineInterpolation(src.first, src.second, src.third,
dest.first, dest.second, dest.third, spline);
}
template <class SrcIterator, class Shape, class SrcAccessor,
class DestIterator, class DestAccessor>
inline void
resizeMultiArraySplineInterpolation(triple<SrcIterator, Shape, SrcAccessor> src,
triple<DestIterator, Shape, DestAccessor> dest)
{
resizeMultiArraySplineInterpolation(src.first, src.second, src.third,
dest.first, dest.second, dest.third);
}
template <unsigned int N, class T1, class S1,
class T2, class S2,
class Kernel>
inline void
resizeMultiArraySplineInterpolation(MultiArrayView<N, T1, S1> const & source,
MultiArrayView<N, T2, S2> dest,
Kernel const & spline)
{
resizeMultiArraySplineInterpolation(srcMultiArrayRange(source),
destMultiArrayRange(dest), spline);
}
template <unsigned int N, class T1, class S1,
class T2, class S2>
inline void
resizeMultiArraySplineInterpolation(MultiArrayView<N, T1, S1> const & source,
MultiArrayView<N, T2, S2> dest)
{
resizeMultiArraySplineInterpolation(srcMultiArrayRange(source),
destMultiArrayRange(dest));
}
//@}
} // namespace vigra
#endif // VIGRA_MULTI_RESIZE_HXX
|