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

vigra/combineimages.hxx |

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