VIGRA - VIGRA: vigra/combineimages.hxx Source File

[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

# vigra/combineimages.hxx

    00001 /************************************************************************/
    00002 /*                                                                      */
    00003 /*               Copyright 1998-2002 by Ullrich Koethe                  */
    00004 /*       Cognitive Systems Group, University of Hamburg, Germany        */
    00005 /*                                                                      */
    00006 /*    This file is part of the VIGRA computer vision library.           */
    00007 /*    ( Version 1.6.0, Aug 13 2008 )                                    */
    00008 /*    The VIGRA Website is                                              */
    00009 /*        http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/      */
    00010 /*    Please direct questions, bug reports, and contributions to        */
    00011 /*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
    00012 /*        vigra@informatik.uni-hamburg.de                               */
    00013 /*                                                                      */
    00014 /*    Permission is hereby granted, free of charge, to any person       */
    00015 /*    obtaining a copy of this software and associated documentation    */
    00016 /*    files (the "Software"), to deal in the Software without           */
    00017 /*    restriction, including without limitation the rights to use,      */
    00018 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
    00019 /*    sell copies of the Software, and to permit persons to whom the    */
    00020 /*    Software is furnished to do so, subject to the following          */
    00021 /*    conditions:                                                       */
    00022 /*                                                                      */
    00023 /*    The above copyright notice and this permission notice shall be    */
    00024 /*    included in all copies or substantial portions of the             */
    00025 /*    Software.                                                         */
    00026 /*                                                                      */
    00027 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
    00028 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
    00029 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
    00030 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
    00031 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
    00032 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
    00033 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
    00034 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */
    00035 /*                                                                      */
    00036 /************************************************************************/
    00037
    00038
    00039 #ifndef VIGRA_COMBINEIMAGES_HXX
    00040 #define VIGRA_COMBINEIMAGES_HXX
    00041
    00042 #include "utilities.hxx"
    00043 #include "numerictraits.hxx"
    00044 #include "functortraits.hxx"
    00045 #include <cmath>
    00046
    00047 namespace vigra {
    00048
    00049 /** \addtogroup CombineAlgo Algorithms to Combine Images
    00050
    00051     Apply functor to calculate a pixelwise transformation depending on multiple images.
    00052     Note that the binary functors of the STL may be used with these functions.
    00053 */
    00054 //@{
    00055
    00056 /********************************************************/
    00057 /*                                                      */
    00058 /*                    combine...Lines                   */
    00059 /*                                                      */
    00060 /********************************************************/
    00061
    00062 template <class SrcIterator1, class SrcAccessor1,
    00063           class SrcIterator2, class SrcAccessor2,
    00064           class DestIterator, class DestAccessor, class Functor>
    00065 void
    00066 combineTwoLines(SrcIterator1 s1,
    00067                 SrcIterator1 s1end, SrcAccessor1 src1,
    00068                 SrcIterator2 s2, SrcAccessor2 src2,
    00069                 DestIterator d, DestAccessor dest,
    00070                 Functor const & f)
    00071 {
    00072     for(; s1 != s1end; ++s1, ++s2, ++d)
    00073         dest.set(f(src1(s1), src2(s2)), d);
    00074 }
    00075
    00076 template <class SrcIterator1, class SrcAccessor1,
    00077           class SrcIterator2, class SrcAccessor2,
    00078           class MaskIterator, class MaskAccessor,
    00079           class DestIterator, class DestAccessor, class Functor>
    00080 void
    00081 combineTwoLinesIf(SrcIterator1 s1,
    00082                   SrcIterator1 s1end, SrcAccessor1 src1,
    00083                   SrcIterator2 s2, SrcAccessor2 src2,
    00084                   MaskIterator m, MaskAccessor mask,
    00085                   DestIterator d, DestAccessor dest,
    00086                   Functor const & f)
    00087 {
    00088     for(; s1 != s1end; ++s1, ++s2, ++m, ++d)
    00089         if(mask(m))
    00090             dest.set(f(src1(s1), src2(s2)), d);
    00091 }
    00092
    00093 template <class SrcIterator1, class SrcAccessor1,
    00094           class SrcIterator2, class SrcAccessor2,
    00095           class SrcIterator3, class SrcAccessor3,
    00096           class DestIterator, class DestAccessor, class Functor>
    00097 void
    00098 combineThreeLines(SrcIterator1 s1,
    00099                   SrcIterator1 s1end, SrcAccessor1 src1,
    00100                   SrcIterator2 s2, SrcAccessor2 src2,
    00101                   SrcIterator3 s3, SrcAccessor3 src3,
    00102                   DestIterator d, DestAccessor dest,
    00103                   Functor const & f)
    00104 {
    00105     for(; s1 != s1end; ++s1, ++s2, ++s3, ++d)
    00106         dest.set(f(src1(s1), src2(s2), src3(s3)), d);
    00107 }
    00108
    00109 /********************************************************/
    00110 /*                                                      */
    00111 /*                    combineTwoImages                  */
    00112 /*                                                      */
    00113 /********************************************************/
    00114
    00115 /** \brief Combine two source images into destination image.
    00116
    00117     The transformation given by the functor is applied to the source
    00118     pixels and the result written into the corresponding destination pixel.
    00119     This is typically used for operations like add and subtract.
    00120     The function uses accessors to access the pixel data.
    00121     Note that the binary functors of the STL can be used in addition to
    00122     the functors specifically defined in \ref CombineFunctor.
    00123     Creation of new functors is easiest by using \ref FunctorExpressions.
    00124
    00125     <b> Declarations:</b>
    00126
    00127     pass arguments explicitly:
    00128     \code
    00129     namespace vigra {
    00130         template <class SrcImageIterator1, class SrcAccessor1,
    00131               class SrcImageIterator2, class SrcAccessor2,
    00132               class DestImageIterator, class DestAccessor,
    00133               class Functor>
    00134         void
    00135         combineTwoImages(SrcImageIterator1 src1_upperleft,
    00136                  SrcImageIterator1 src1_lowerright, SrcAccessor1 sa1,
    00137                  SrcImageIterator2 src2_upperleft, SrcAccessor2 sa2,
    00138                  DestImageIterator dest_upperleft, DestAccessor da,
    00139                  Functor const & f)
    00140     }
    00141     \endcode
    00142
    00143
    00144     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00145     \code
    00146     namespace vigra {
    00147         template <class SrcImageIterator1, class SrcAccessor1,
    00148               class SrcImageIterator2, class SrcAccessor2,
    00149               class DestImageIterator, class DestAccessor,
    00150               class Functor>
    00151         void
    00152         combineTwoImages(triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
    00153                  pair<SrcImageIterator2, SrcAccessor2> src2,
    00154                  pair<DestImageIterator, DestAccessor> dest,
    00155                  Functor const & f)
    00156     }
    00157     \endcode
    00158
    00159     <b> Usage:</b>
    00160
    00161         <b>\#include</b> <<a href="combineimages_8hxx-source.html">vigra/combineimages.hxx</a>><br>
    00162         Namespace: vigra
    00163
    00164     \code
    00165     #include <functional>     // for plus
    00166
    00167     vigra::combineTwoImages(
    00168                 srcIterRange(src1.upperLeft(), src1.lowerRight()),
    00169                 srcIter(src2.upperLeft()),
    00170                 destIter(dest.upperLeft()),
    00171                 std::plus<SrcValueType>());
    00172
    00173     \endcode
    00174
    00175     Note that <TT>SrcValueType</TT> must be replaced with the appropriate type (e.g.
    00176     the promote type of the input images' pixel type, see also
    00177     \ref NumericPromotionTraits)
    00178
    00179     <b> Required Interface:</b>
    00180
    00181     \code
    00182     SrcImageIterator1 src1_upperleft, src1_lowerright;
    00183     SrcImageIterator2 src2_upperleft;
    00184     DestImageIterator dest_upperleft;
    00185     SrcImageIterator1::row_iterator sx1 = src1_upperleft.rowIterator();
    00186     SrcImageIterator2::row_iterator sx2 = src2_upperleft.rowIterator();
    00187     DestImageIterator::row_iterator dx = dest_upperleft.rowIterator();
    00188
    00189     SrcAccessor1 src1_accessor;
    00190     SrcAccessor2 src2_accessor;
    00191     DestAccessor dest_accessor;
    00192
    00193     Functor functor;
    00194
    00195     dest_accessor.set(
    00196           functor(src1_accessor(sx1), src2_accessor(sx2)),
    00197           dx);
    00198
    00199     \endcode
    00200
    00201
    00202 */
    00203 doxygen_overloaded_function(template <...> void combineTwoImages)
    00204
    00205 template <class SrcImageIterator1, class SrcAccessor1,
    00206           class SrcImageIterator2, class SrcAccessor2,
    00207           class DestImageIterator, class DestAccessor,
    00208           class Functor>
    00209 void
    00210 combineTwoImages(SrcImageIterator1 src1_upperleft,
    00211                  SrcImageIterator1 src1_lowerright, SrcAccessor1 sa1,
    00212                  SrcImageIterator2 src2_upperleft, SrcAccessor2 sa2,
    00213                  DestImageIterator dest_upperleft, DestAccessor da,
    00214                  Functor const & f)
    00215 {
    00216     int w = src1_lowerright.x - src1_upperleft.x;
    00217
    00218     for(; src1_upperleft.y < src1_lowerright.y;
    00219             ++src1_upperleft.y, ++src2_upperleft.y, ++dest_upperleft.y)
    00220     {
    00221         combineTwoLines(src1_upperleft.rowIterator(),
    00222                         src1_upperleft.rowIterator() + w, sa1,
    00223                         src2_upperleft.rowIterator(), sa2,
    00224                         dest_upperleft.rowIterator(), da, f);
    00225     }
    00226 }
    00227
    00228 template <class SrcImageIterator1, class SrcAccessor1,
    00229           class SrcImageIterator2, class SrcAccessor2,
    00230           class DestImageIterator, class DestAccessor,
    00231           class Functor>
    00232 inline
    00233 void
    00234 combineTwoImages(triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
    00235              pair<SrcImageIterator2, SrcAccessor2> src2,
    00236              pair<DestImageIterator, DestAccessor> dest,
    00237              Functor const & f)
    00238 {
    00239     combineTwoImages(src1.first, src1.second, src1.third,
    00240                      src2.first, src2.second,
    00241              dest.first, dest.second, f);
    00242 }
    00243
    00244 /********************************************************/
    00245 /*                                                      */
    00246 /*                  combineTwoImagesIf                  */
    00247 /*                                                      */
    00248 /********************************************************/
    00249
    00250 /** \brief Combine ROI of two source images into destination image.
    00251
    00252     The transformation given by the functor is applied to all source
    00253     pixels in the ROI (i.e. whenever the return value of the mask's accessor
    00254     is not zero)
    00255     and the result written into the corresponding destination pixel.
    00256     This is typically used for operations like add and subtract.
    00257     The function uses accessors to access the pixel data.
    00258     Note that the binary functors of the STL can be used in addition to
    00259     the functors specifically defined in \ref CombineFunctor.
    00260     Creation of new functors is easiest by using \ref FunctorExpressions.
    00261
    00262     <b> Declarations:</b>
    00263
    00264     pass arguments explicitly:
    00265     \code
    00266     namespace vigra {
    00267         template <class SrcImageIterator1, class SrcAccessor1,
    00268               class SrcImageIterator2, class SrcAccessor2,
    00269               class MaskImageIterator, class MaskAccessor,
    00270               class DestImageIterator, clas DestAccessor,
    00271               class Functor>
    00272         void
    00273         combineTwoImagesIf(SrcImageIterator1 src1_upperleft,
    00274                    SrcImageIterator1 src1_lowerright, SrcAccessor1 sa1,
    00275                    SrcImageIterator2 src2_upperleft, SrcAccessor2 sa2,
    00276                    MaskImageIterator mask_upperleft, MaskAccessor ma,
    00277                    DestImageIterator dest_upperleft, DestAccessor da,
    00278                    Functor const & f)
    00279     }
    00280     \endcode
    00281
    00282
    00283     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00284     \code
    00285     namespace vigra {
    00286         template <class SrcImageIterator1, class SrcAccessor1,
    00287               class SrcImageIterator2, class SrcAccessor2,
    00288               class MaskImageIterator, class MaskAccessor,
    00289               class DestImageIterator, clas DestAccessor,
    00290               class Functor>
    00291         void
    00292         combineTwoImagesIf(triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
    00293                    pair<SrcImageIterator2, SrcAccessor2> src2,
    00294                    pair<MaskImageIterator, MaskAccessor> mask,
    00295                    pair<DestImageIterator, DestAccessor> dest,
    00296                    Functor const & f)
    00297     }
    00298     \endcode
    00299
    00300     <b> Usage:</b>
    00301
    00302         <b>\#include</b> <<a href="combineimages_8hxx-source.html">vigra/combineimages.hxx</a>><br>
    00303         Namespace: vigra
    00304
    00305     \code
    00306     #include <functional>     // for plus
    00307
    00308     vigra::combineTwoImagesIf(
    00309                 srcIterRange(src1.upperLeft(), src1.lowerRight()),
    00310                 srcIter(src2.upperLeft()),
    00311                 maskIter(mask.upperLeft()),
    00312                 destIter(dest.upperLeft()),
    00313                 std::plus<SrcValueType>());
    00314
    00315     \endcode
    00316
    00317     Note that <TT>SrcValueType</TT> must be replaced with the appropriate type (e.g.
    00318     the promote type of the input images' pixel type, see also
    00319     \ref NumericPromotionTraits)
    00320
    00321     <b> Required Interface:</b>
    00322
    00323     \code
    00324     SrcImageIterator1 src1_upperleft, src1_lowerright;
    00325     SrcImageIterator2 src2_upperleft;
    00326     MaskImageIterator mask_upperleft;
    00327     DestImageIterator dest_upperleft;
    00328     SrcImageIterator1::row_iterator sx1 = src1_upperleft.rowIterator();
    00329     SrcImageIterator2::row_iterator sx2 = src2_upperleft.rowIterator();
    00330     MaskImageIterator::row_iterator mx = mask_upperleft.rowIterator();
    00331     DestImageIterator::row_iterator dx = dest_upperleft.rowIterator();
    00332
    00333
    00334     SrcAccessor1 src1_accessor;
    00335     SrcAccessor2 src2_accessor;
    00336     MaskAccessor mask_accessor;
    00337     DestAccessor dest_accessor;
    00338
    00339     Functor functor;
    00340
    00341     if(mask_accessor(mx))
    00342        dest_accessor.set(
    00343           functor(src1_accessor(sx1), src2_accessor(sx2)),
    00344           dx);
    00345
    00346     \endcode
    00347
    00348 */
    00349 doxygen_overloaded_function(template <...> void combineTwoImagesIf)
    00350
    00351 template <class SrcImageIterator1, class SrcAccessor1,
    00352           class SrcImageIterator2, class SrcAccessor2,
    00353           class MaskImageIterator, class MaskAccessor,
    00354           class DestImageIterator, class DestAccessor,
    00355           class Functor>
    00356 void
    00357 combineTwoImagesIf(SrcImageIterator1 src1_upperleft,
    00358                    SrcImageIterator1 src1_lowerright, SrcAccessor1 sa1,
    00359                    SrcImageIterator2 src2_upperleft, SrcAccessor2 sa2,
    00360                    MaskImageIterator mask_upperleft, MaskAccessor ma,
    00361                    DestImageIterator dest_upperleft, DestAccessor da,
    00362                    Functor const & f)
    00363 {
    00364     int w = src1_lowerright.x - src1_upperleft.x;
    00365
    00366     for(; src1_upperleft.y < src1_lowerright.y;
    00367           ++src1_upperleft.y, ++src2_upperleft.y,
    00368           ++dest_upperleft.y, ++mask_upperleft.y)
    00369     {
    00370         combineTwoLinesIf(src1_upperleft.rowIterator(),
    00371                           src1_upperleft.rowIterator() + w, sa1,
    00372                           src2_upperleft.rowIterator(), sa2,
    00373                           mask_upperleft.rowIterator(), ma,
    00374                           dest_upperleft.rowIterator(), da, f);
    00375     }
    00376 }
    00377
    00378 template <class SrcImageIterator1, class SrcAccessor1,
    00379           class SrcImageIterator2, class SrcAccessor2,
    00380           class MaskImageIterator, class MaskAccessor,
    00381           class DestImageIterator, class DestAccessor,
    00382           class Functor>
    00383 inline
    00384 void
    00385 combineTwoImagesIf(triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
    00386                pair<SrcImageIterator2, SrcAccessor2> src2,
    00387                pair<MaskImageIterator, MaskAccessor> mask,
    00388                pair<DestImageIterator, DestAccessor> dest,
    00389                Functor const & f)
    00390 {
    00391     combineTwoImagesIf(src1.first, src1.second, src1.third,
    00392                        src2.first, src2.second,
    00393                        mask.first, mask.second,
    00394                        dest.first, dest.second, f);
    00395 }
    00396
    00397 /********************************************************/
    00398 /*                                                      */
    00399 /*                  combineThreeImages                  */
    00400 /*                                                      */
    00401 /********************************************************/
    00402
    00403 /** \brief Combine three source images into destination image.
    00404
    00405     The transformation given by the functor is applied to the source
    00406     pixels and the result written into the corresponding destination pixel.
    00407     The function uses accessors to access the pixel data.
    00408     Creation of new functors is easiest by using \ref FunctorExpressions.
    00409
    00410     <b> Declarations:</b>
    00411
    00412     pass arguments explicitly:
    00413     \code
    00414     namespace vigra {
    00415         template <class SrcImageIterator1, class SrcAccessor1,
    00416               class SrcImageIterator2, class SrcAccessor2,
    00417               class SrcImageIterator3, class SrcAccessor3,
    00418               class DestImageIterator, class DestAccessor,
    00419               class Functor>
    00420         void
    00421         combineThreeImages(SrcImageIterator1 src1_upperleft,
    00422                    SrcImageIterator1 src1_lowerright, SrcAccessor1 sa1,
    00423                    SrcImageIterator2 src2_upperleft, SrcAccessor2 sa2,
    00424                    SrcImageIterator3 src2_upperleft, SrcAccessor3 sa3,
    00425                    DestImageIterator dest_upperleft, DestAccessor da,
    00426                    Functor const & f)
    00427     }
    00428     \endcode
    00429
    00430
    00431     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00432     \code
    00433     namespace vigra {
    00434         template <class SrcImageIterator1, class SrcAccessor1,
    00435               class SrcImageIterator2, class SrcAccessor2,
    00436               class SrcImageIterator3, class SrcAccessor3,
    00437               class DestImageIterator, class DestAccessor,
    00438               class Functor>
    00439         void
    00440         combineThreeImages(triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
    00441                  pair<SrcImageIterator2, SrcAccessor2> src2,
    00442                  pair<SrcImageIterator3, SrcAccessor3> src3,
    00443                  pair<DestImageIterator, DestAccessor> dest,
    00444                  Functor const & f)
    00445     }
    00446     \endcode
    00447
    00448     <b> Usage:</b>
    00449
    00450         <b>\#include</b> <<a href="combineimages_8hxx-source.html">vigra/combineimages.hxx</a>><br>
    00451         Namespace: vigra
    00452
    00453     \code
    00454     vigra::combineThreeImages(
    00455                 srcIterRange(src1.upperLeft(), src1.lowerRight()),
    00456                 srcIter(src2.upperLeft()),
    00457                 srcIter(src3.upperLeft()),
    00458                 destIter(dest.upperLeft()),
    00459                 SomeThreeArgumentFunctor());
    00460
    00461     \endcode
    00462
    00463     <b> Required Interface:</b>
    00464
    00465     \code
    00466     SrcImageIterator1 src1_upperleft, src1_lowerright;
    00467     SrcImageIterator2 src2_upperleft;
    00468     SrcImageIterator3 src3_upperleft;
    00469     DestImageIterator dest_upperleft;
    00470     SrcImageIterator1::row_iterator sx1 = src1_upperleft.rowIterator();
    00471     SrcImageIterator2::row_iterator sx2 = src2_upperleft.rowIterator();
    00472     SrcImageIterator3::row_iterator sx3 = src3_upperleft.rowIterator();
    00473     DestImageIterator::row_iterator dx = dest_upperleft.rowIterator();
    00474
    00475     SrcAccessor1 src1_accessor;
    00476     SrcAccessor2 src2_accessor;
    00477     SrcAccessor3 src3_accessor;
    00478     DestAccessor dest_accessor;
    00479
    00480     Functor functor;
    00481
    00482     dest_accessor.set(
    00483           functor(src1_accessor(sx1),
    00484                   src2_accessor(sx2),
    00485                   src3_accessor(sx3)),
    00486           dx);
    00487
    00488     \endcode
    00489
    00490
    00491 */
    00492 doxygen_overloaded_function(template <...> void combineThreeImages)
    00493
    00494 template <class SrcImageIterator1, class SrcAccessor1,
    00495           class SrcImageIterator2, class SrcAccessor2,
    00496           class SrcImageIterator3, class SrcAccessor3,
    00497           class DestImageIterator, class DestAccessor,
    00498           class Functor>
    00499 void
    00500 combineThreeImages(SrcImageIterator1 src1_upperleft,
    00501                    SrcImageIterator1 src1_lowerright, SrcAccessor1 sa1,
    00502                    SrcImageIterator2 src2_upperleft, SrcAccessor2 sa2,
    00503                    SrcImageIterator3 src3_upperleft, SrcAccessor3 sa3,
    00504                    DestImageIterator dest_upperleft, DestAccessor da,
    00505                    Functor const & f)
    00506 {
    00507     int w = src1_lowerright.x - src1_upperleft.x;
    00508
    00509     for(; src1_upperleft.y < src1_lowerright.y;
    00510         ++src1_upperleft.y, ++src2_upperleft.y, ++src3_upperleft.y,
    00511         ++dest_upperleft.y)
    00512     {
    00513         combineThreeLines(src1_upperleft.rowIterator(),
    00514                           src1_upperleft.rowIterator() + w, sa1,
    00515                           src2_upperleft.rowIterator(), sa2,
    00516                           src3_upperleft.rowIterator(), sa3,
    00517                           dest_upperleft.rowIterator(), da, f);
    00518     }
    00519 }
    00520
    00521 template <class SrcImageIterator1, class SrcAccessor1,
    00522           class SrcImageIterator2, class SrcAccessor2,
    00523           class SrcImageIterator3, class SrcAccessor3,
    00524           class DestImageIterator, class DestAccessor,
    00525           class Functor>
    00526 inline
    00527 void
    00528 combineThreeImages(triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
    00529              pair<SrcImageIterator2, SrcAccessor2> src2,
    00530              pair<SrcImageIterator3, SrcAccessor3> src3,
    00531              pair<DestImageIterator, DestAccessor> dest,
    00532              Functor const & f)
    00533 {
    00534     combineThreeImages(src1.first, src1.second, src1.third,
    00535                      src2.first, src2.second,
    00536                      src3.first, src3.second,
    00537                      dest.first, dest.second, f);
    00538 }
    00539
    00540
    00541 //@}
    00542
    00543 /** \addtogroup CombineFunctor Functors to Combine Images
    00544
    00545     Common functors with several arguments
    00546 */
    00547 //@{
    00548
    00549 /********************************************************/
    00550 /*                                                      */
    00551 /*                    MagnitudeFunctor                  */
    00552 /*                                                      */
    00553 /********************************************************/
    00554
    00555 /** Calculate the magnitude from two arguments.
    00556     Can be used in conjunction with \ref gradientBasedTransform().
    00557
    00558     If the gradient is represented by a vector-valued image instead of
    00559     a pair of scalar images, use \ref vigra::VectorNormFunctor.
    00560
    00561     <b> Traits defined:</b>
    00562
    00563     <tt>FunctorTraits::isBinaryFunctor</tt> are true (<tt>VigraTrueType</tt>)
    00564 */
    00565 template <class ValueType>
    00566 class MagnitudeFunctor
    00567 {
    00568   public:
    00569         /** the functor's first argument type
    00570         */
    00571     typedef ValueType first_argument_type;
    00572
    00573         /** the functor's second argument type
    00574         */
    00575     typedef ValueType second_argument_type;
    00576
    00577         /** the functor's result type
    00578         */
    00579     typedef typename SquareRootTraits<typename NormTraits<ValueType>::SquaredNormType>::SquareRootResult result_type;
    00580
    00581         /** \deprecated use first_argument_type, second_argument_type, result_type
    00582         */
    00583     typedef ValueType value_type;
    00584
    00585         /** calculate transform '<TT>sqrt(squaredNorm(v1) + squaredNorm(v2))</TT>'.
    00586
    00587         */
    00588     result_type operator()(first_argument_type const & v1, second_argument_type const & v2) const
    00589     {
    00590         return VIGRA_CSTD::sqrt(squaredNorm(v1) + squaredNorm(v2));
    00591     }
    00592 };
    00593
    00594 template <class T>
    00595 class FunctorTraits<MagnitudeFunctor<T> >
    00596 : public FunctorTraitsBase<MagnitudeFunctor<T> >
    00597 {
    00598 public:
    00599     typedef VigraTrueType isBinaryFunctor;
    00600 };
    00601
    00602 /********************************************************/
    00603 /*                                                      */
    00604 /*             RGBGradientMagnitudeFunctor              */
    00605 /*                                                      */
    00606 /********************************************************/
    00607
    00608
    00609 /** Calculate the gradient magnitude from RGB arguments.
    00610     Can be used in conjunction with \ref gradientBasedTransform().
    00611
    00612     <b> Traits defined:</b>
    00613
    00614     <tt>FunctorTraits::isBinaryFunctor</tt> are true (<tt>VigraTrueType</tt>)
    00615 */
    00616 template <class ValueType>
    00617 class RGBGradientMagnitudeFunctor
    00618 {
    00619   public:
    00620         /** the functor's first argument type
    00621         */
    00622     typedef RGBValue<ValueType> first_argument_type;
    00623
    00624         /** the functor's second argument type
    00625         */
    00626     typedef RGBValue<ValueType> second_argument_type;
    00627
    00628         /** the functor's result type
    00629         */
    00630     typedef typename NumericTraits<ValueType>::RealPromote result_type;
    00631
    00632         /** \deprecated use first_argument_type, second_argument_type, result_type
    00633         */
    00634     typedef ValueType value_type;
    00635
    00636         /** Calculate the gradient magnitude form given RGB components.
    00637             The function returns
    00638
    00639             \f[ \sqrt{|\nabla red|^2 + |\nabla green|^2 + |\nabla blue|^2}
    00640             \f]
    00641
    00642             where \f$|\nabla red|^2\f$ is defined by <TT>gx.red()*gx.red() + gy.red()*gy.red()</TT>.
    00643
    00644             <TT>ValueType</TT> (the RGB's component type) must support addition, multiplication,
    00645             abd <TT>sqrt()</TT>.
    00646         */
    00647     result_type
    00648     operator()(first_argument_type const & gx, second_argument_type const & gy) const
    00649     {
    00650         return VIGRA_CSTD::sqrt(gx.red()*gx.red() + gx.green()*gx.green() +
    00651                     gx.blue()*gx.blue() + gy.red()*gy.red() +
    00652                     gy.green()*gy.green() + gy.blue()*gy.blue());
    00653     }
    00654 };
    00655
    00656 template <class T>
    00657 class FunctorTraits<RGBGradientMagnitudeFunctor<T> >
    00658 : public FunctorTraitsBase<RGBGradientMagnitudeFunctor<T> >
    00659 {
    00660 public:
    00661     typedef VigraTrueType isBinaryFunctor;
    00662 };
    00663
    00664 //@}
    00665
    00666 } // namespace vigra
    00667
    00668 #endif // VIGRA_COMBINEIMAGES_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python VIGRA 1.6.0 (13 Aug 2008)