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

details vigra/combineimages.hxx VIGRA

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.5.0, Dec 07 2006 )                                    */
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 /*        koethe@informatik.uni-hamburg.de          or                  */
00012 /*        vigra@kogs1.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 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 template <class SrcImageIterator1, class SrcAccessor1,
00348           class SrcImageIterator2, class SrcAccessor2,
00349           class MaskImageIterator, class MaskAccessor,
00350           class DestImageIterator, class DestAccessor,
00351           class Functor>
00352 void
00353 combineTwoImagesIf(SrcImageIterator1 src1_upperleft, 
00354                    SrcImageIterator1 src1_lowerright, SrcAccessor1 sa1,
00355                    SrcImageIterator2 src2_upperleft, SrcAccessor2 sa2,
00356                    MaskImageIterator mask_upperleft, MaskAccessor ma,
00357                    DestImageIterator dest_upperleft, DestAccessor da,
00358                    Functor const & f)
00359 {
00360     int w = src1_lowerright.x - src1_upperleft.x;
00361     
00362     for(; src1_upperleft.y < src1_lowerright.y;
00363           ++src1_upperleft.y, ++src2_upperleft.y, 
00364           ++dest_upperleft.y, ++mask_upperleft.y)
00365     {
00366         combineTwoLinesIf(src1_upperleft.rowIterator(), 
00367                           src1_upperleft.rowIterator() + w, sa1, 
00368                           src2_upperleft.rowIterator(), sa2, 
00369                           mask_upperleft.rowIterator(), ma, 
00370                           dest_upperleft.rowIterator(), da, f);
00371     }
00372 }
00373     
00374 template <class SrcImageIterator1, class SrcAccessor1,
00375           class SrcImageIterator2, class SrcAccessor2,
00376           class MaskImageIterator, class MaskAccessor,
00377           class DestImageIterator, class DestAccessor,
00378           class Functor>
00379 inline
00380 void
00381 combineTwoImagesIf(triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
00382                pair<SrcImageIterator2, SrcAccessor2> src2,
00383                pair<MaskImageIterator, MaskAccessor> mask,
00384                pair<DestImageIterator, DestAccessor> dest,
00385                Functor const & f)
00386 {
00387     combineTwoImagesIf(src1.first, src1.second, src1.third, 
00388                        src2.first, src2.second, 
00389                        mask.first, mask.second, 
00390                        dest.first, dest.second, f);
00391 }
00392 
00393 /********************************************************/
00394 /*                                                      */
00395 /*                  combineThreeImages                  */
00396 /*                                                      */
00397 /********************************************************/
00398 
00399 /** \brief Combine three source images into destination image.
00400 
00401     The transformation given by the functor is applied to the source 
00402     pixels and the result written into the corresponding destination pixel.
00403     The function uses accessors to access the pixel data.
00404     Creation of new functors is easiest by using \ref FunctorExpressions.
00405     
00406     <b> Declarations:</b>
00407     
00408     pass arguments explicitly:
00409     \code
00410     namespace vigra {
00411         template <class SrcImageIterator1, class SrcAccessor1,
00412               class SrcImageIterator2, class SrcAccessor2,
00413               class SrcImageIterator3, class SrcAccessor3,
00414               class DestImageIterator, class DestAccessor,
00415               class Functor>
00416         void
00417         combineThreeImages(SrcImageIterator1 src1_upperleft, 
00418                    SrcImageIterator1 src1_lowerright, SrcAccessor1 sa1,
00419                    SrcImageIterator2 src2_upperleft, SrcAccessor2 sa2,
00420                    SrcImageIterator3 src2_upperleft, SrcAccessor3 sa3,
00421                    DestImageIterator dest_upperleft, DestAccessor da,
00422                    Functor const & f)
00423     }
00424     \endcode
00425     
00426     
00427     use argument objects in conjunction with \ref ArgumentObjectFactories:
00428     \code
00429     namespace vigra {
00430         template <class SrcImageIterator1, class SrcAccessor1,
00431               class SrcImageIterator2, class SrcAccessor2,
00432               class SrcImageIterator3, class SrcAccessor3,
00433               class DestImageIterator, class DestAccessor,
00434               class Functor>
00435         void
00436         combineThreeImages(triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
00437                  pair<SrcImageIterator2, SrcAccessor2> src2,
00438                  pair<SrcImageIterator3, SrcAccessor3> src3,
00439                  pair<DestImageIterator, DestAccessor> dest,
00440                  Functor const & f)
00441     }
00442     \endcode
00443     
00444     <b> Usage:</b>
00445     
00446         <b>\#include</b> "<a href="combineimages_8hxx-source.html">vigra/combineimages.hxx</a>"<br>
00447         Namespace: vigra
00448     
00449     \code
00450     vigra::combineThreeImages(
00451                 srcIterRange(src1.upperLeft(), src1.lowerRight()), 
00452                 srcIter(src2.upperLeft()), 
00453                 srcIter(src3.upperLeft()), 
00454                 destIter(dest.upperLeft()),  
00455                 SomeThreeArgumentFunctor());
00456     
00457     \endcode
00458 
00459     <b> Required Interface:</b>
00460     
00461     \code
00462     SrcImageIterator1 src1_upperleft, src1_lowerright;
00463     SrcImageIterator2 src2_upperleft;
00464     SrcImageIterator3 src3_upperleft;
00465     DestImageIterator dest_upperleft;
00466     SrcImageIterator1::row_iterator sx1 = src1_upperleft.rowIterator();
00467     SrcImageIterator2::row_iterator sx2 = src2_upperleft.rowIterator();
00468     SrcImageIterator3::row_iterator sx3 = src3_upperleft.rowIterator();
00469     DestImageIterator::row_iterator dx = dest_upperleft.rowIterator();
00470     
00471     SrcAccessor1 src1_accessor;
00472     SrcAccessor2 src2_accessor;
00473     SrcAccessor3 src3_accessor;
00474     DestAccessor dest_accessor;
00475     
00476     Functor functor;
00477 
00478     dest_accessor.set(
00479           functor(src1_accessor(sx1), 
00480                   src2_accessor(sx2), 
00481                   src3_accessor(sx3)), 
00482           dx);
00483 
00484     \endcode
00485     
00486     
00487 */
00488 template <class SrcImageIterator1, class SrcAccessor1,
00489           class SrcImageIterator2, class SrcAccessor2,
00490           class SrcImageIterator3, class SrcAccessor3,
00491           class DestImageIterator, class DestAccessor,
00492           class Functor>
00493 void
00494 combineThreeImages(SrcImageIterator1 src1_upperleft, 
00495                    SrcImageIterator1 src1_lowerright, SrcAccessor1 sa1,
00496                    SrcImageIterator2 src2_upperleft, SrcAccessor2 sa2,
00497                    SrcImageIterator3 src3_upperleft, SrcAccessor3 sa3,
00498                    DestImageIterator dest_upperleft, DestAccessor da,
00499                    Functor const & f)
00500 {
00501     int w = src1_lowerright.x - src1_upperleft.x;
00502     
00503     for(; src1_upperleft.y < src1_lowerright.y;
00504         ++src1_upperleft.y, ++src2_upperleft.y, ++src3_upperleft.y, 
00505         ++dest_upperleft.y)
00506     {
00507         combineThreeLines(src1_upperleft.rowIterator(), 
00508                           src1_upperleft.rowIterator() + w, sa1, 
00509                           src2_upperleft.rowIterator(), sa2, 
00510                           src3_upperleft.rowIterator(), sa3, 
00511                           dest_upperleft.rowIterator(), da, f);
00512     }
00513 }
00514     
00515 template <class SrcImageIterator1, class SrcAccessor1,
00516           class SrcImageIterator2, class SrcAccessor2,
00517           class SrcImageIterator3, class SrcAccessor3,
00518           class DestImageIterator, class DestAccessor,
00519           class Functor>
00520 inline
00521 void
00522 combineThreeImages(triple<SrcImageIterator1, SrcImageIterator1, SrcAccessor1> src1,
00523              pair<SrcImageIterator2, SrcAccessor2> src2,
00524              pair<SrcImageIterator3, SrcAccessor3> src3,
00525              pair<DestImageIterator, DestAccessor> dest,
00526              Functor const & f)
00527 {
00528     combineThreeImages(src1.first, src1.second, src1.third, 
00529                      src2.first, src2.second, 
00530                      src3.first, src3.second, 
00531                      dest.first, dest.second, f);
00532 }
00533 
00534     
00535 //@}
00536 
00537 /** \addtogroup CombineFunctor Functors to Combine Images
00538 
00539     Common functors with several arguments
00540 */
00541 //@{
00542 
00543 /********************************************************/
00544 /*                                                      */
00545 /*                    MagnitudeFunctor                  */
00546 /*                                                      */
00547 /********************************************************/
00548 
00549 /** Calculate the magnitude from two arguments.
00550     Can be used in conjunction with \ref gradientBasedTransform().
00551     
00552     If the gradient is represented by a vector-valued image instead of 
00553     a pair of scalar images, use \ref vigra::VectorNormFunctor.
00554 
00555     <b> Traits defined:</b>
00556     
00557     <tt>FunctorTraits::isBinaryFunctor</tt> are true (<tt>VigraTrueType<tt>)    
00558 */
00559 template <class ValueType>
00560 class MagnitudeFunctor
00561 {
00562   public:
00563         /** the functor's first argument type
00564         */
00565     typedef ValueType first_argument_type;
00566     
00567         /** the functor's second argument type
00568         */
00569     typedef ValueType second_argument_type;
00570     
00571         /** the functor's result type
00572         */
00573     typedef typename SquareRootTraits<typename NormTraits<ValueType>::SquaredNormType>::SquareRootResult result_type;
00574     
00575         /** \deprecated use first_argument_type, second_argument_type, result_type
00576         */
00577     typedef ValueType value_type;
00578     
00579         /** calculate transform '<TT>sqrt(squaredNorm(v1) + squaredNorm(v2))</TT>'. 
00580             
00581         */
00582     result_type operator()(first_argument_type const & v1, second_argument_type const & v2) const
00583     {
00584         return VIGRA_CSTD::sqrt(squaredNorm(v1) + squaredNorm(v2));
00585     }
00586 };
00587 
00588 template <class T>
00589 class FunctorTraits<MagnitudeFunctor<T> >
00590 : public FunctorTraitsBase<MagnitudeFunctor<T> >
00591 {
00592 public:
00593     typedef VigraTrueType isBinaryFunctor;
00594 };
00595 
00596 /********************************************************/
00597 /*                                                      */
00598 /*             RGBGradientMagnitudeFunctor              */
00599 /*                                                      */
00600 /********************************************************/
00601 
00602 
00603 /** Calculate the gradient magnitude from RGB arguments.
00604     Can be used in conjunction with \ref gradientBasedTransform().
00605 
00606     <b> Traits defined:</b>
00607     
00608     <tt>FunctorTraits::isBinaryFunctor</tt> are true (<tt>VigraTrueType<tt>)    
00609 */
00610 template <class ValueType>
00611 class RGBGradientMagnitudeFunctor
00612 {
00613   public:
00614         /** the functor's first argument type
00615         */
00616     typedef RGBValue<ValueType> first_argument_type;
00617     
00618         /** the functor's second argument type
00619         */
00620     typedef RGBValue<ValueType> second_argument_type;
00621     
00622         /** the functor's result type
00623         */
00624     typedef typename NumericTraits<ValueType>::RealPromote result_type;
00625     
00626         /** \deprecated use first_argument_type, second_argument_type, result_type
00627         */
00628     typedef ValueType value_type;
00629     
00630         /** Calculate the gradient magnitude form given RGB components.
00631             The function returns 
00632             
00633             \f[ \sqrt{|\nabla red|^2 + |\nabla green|^2 + |\nabla blue|^2}
00634             \f]
00635             
00636             where \f$|\nabla red|^2\f$ is defined by <TT>gx.red()*gx.red() + gy.red()*gy.red()</TT>.
00637             
00638             <TT>ValueType</TT> (the RGB's component type) must support addition, multiplication, 
00639             abd <TT>sqrt()</TT>.
00640         */
00641     result_type 
00642     operator()(first_argument_type const & gx, second_argument_type const & gy) const
00643     {
00644         return VIGRA_CSTD::sqrt(gx.red()*gx.red() + gx.green()*gx.green() +
00645                     gx.blue()*gx.blue() + gy.red()*gy.red() + 
00646                     gy.green()*gy.green() + gy.blue()*gy.blue());
00647     }
00648 };
00649 
00650 template <class T>
00651 class FunctorTraits<RGBGradientMagnitudeFunctor<T> >
00652 : public FunctorTraitsBase<RGBGradientMagnitudeFunctor<T> >
00653 {
00654 public:
00655     typedef VigraTrueType isBinaryFunctor;
00656 };
00657 
00658 //@}
00659 
00660 } // namespace vigra
00661 
00662 #endif // VIGRA_COMBINEIMAGES_HXX

© Ullrich Köthe (koethe@informatik.uni-hamburg.de)
Cognitive Systems Group, University of Hamburg, Germany

html generated using doxygen and Python
VIGRA 1.5.0 (7 Dec 2006)