VIGRA - VIGRA: vigra/localminmax.hxx Source File

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

# vigra/localminmax.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_LOCALMINMAX_HXX
    00040 #define VIGRA_LOCALMINMAX_HXX
    00041
    00042 #include <vector>
    00043 #include <functional>
    00044 #include "utilities.hxx"
    00045 #include "stdimage.hxx"
    00046 #include "initimage.hxx"
    00047 #include "labelimage.hxx"
    00048 #include "pixelneighborhood.hxx"
    00049
    00050 namespace vigra {
    00051
    00052 /** \addtogroup LocalMinMax Local Minima and Maxima
    00053
    00054     Detect local minima and maxima of the gray level,
    00055     including extremal plateaus larger than 1 pixel
    00056 */
    00057 //@{
    00058
    00059 namespace detail {
    00060
    00061 template <class SrcIterator, class SrcAccessor,
    00062           class DestIterator, class DestAccessor,
    00063           class DestValue, class Neighborhood,
    00064           class Compare>
    00065 void
    00066 localMinMax(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00067                 DestIterator dul, DestAccessor da,
    00068                 DestValue marker, Neighborhood neighborhood,
    00069                 Compare compare)
    00070 {
    00071     int w = slr.x - sul.x - 2;
    00072     int h = slr.y - sul.y - 2;
    00073
    00074     int i,x,y;
    00075
    00076     sul += Diff2D(1,1);
    00077     dul += Diff2D(1,1);
    00078
    00079     for(y=0; y<h; ++y, ++sul.y, ++dul.y)
    00080     {
    00081         SrcIterator  sx = sul;
    00082         DestIterator dx = dul;
    00083
    00084         for(x=0; x<w; ++x, ++sx.x, ++dx.x)
    00085         {
    00086             typename SrcAccessor::value_type v = sa(sx);
    00087             NeighborhoodCirculator<SrcIterator, Neighborhood> sc(sx);
    00088             for(i = 0; i < Neighborhood::DirectionCount; ++i, ++sc)
    00089             {
    00090                 if(!compare(v, sa(sc)))
    00091                     break;
    00092             }
    00093
    00094             if(i == Neighborhood::DirectionCount)
    00095                 da.set(marker, dx);
    00096         }
    00097     }
    00098 }
    00099
    00100 } // namespace detail
    00101
    00102
    00103 /********************************************************/
    00104 /*                                                      */
    00105 /*                       localMinima                    */
    00106 /*                                                      */
    00107 /********************************************************/
    00108
    00109 /** \brief Find local minima in an image.
    00110
    00111     The minima are found only when the have a size of one pixel.
    00112     Use \ref extendedLocalMinima() to find minimal plateaus. Minima are
    00113     marked in the destination image with the given marker value
    00114     (default is 1), all other destination pixels remain unchanged.
    00115     <TT>SrcAccessor::value_type</TT> must be less-comparable.
    00116     A pixel at the image border will never be marked as minimum.
    00117     Pass \ref vigra::EightNeighborCode or \ref vigra::FourNeighborCode
    00118     to determine the neighborhood where pixel values are compared.
    00119     The function uses accessors.
    00120
    00121     <b> Declarations:</b>
    00122
    00123     pass arguments explicitly:
    00124     \code
    00125     namespace vigra {
    00126         template <class SrcIterator, class SrcAccessor,
    00127                   class DestIterator, class DestAccessor,
    00128                   class DestValue = DestAccessor::value_type,
    00129                   class Neighborhood = EightNeighborCode>
    00130         void
    00131         localMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00132                     DestIterator dul, DestAccessor da,
    00133                     DestValue marker = NumericTraits<DestValue>::one(),
    00134                     Neighborhood neighborhood = EightNeighborCode())
    00135     }
    00136     \endcode
    00137
    00138     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00139     \code
    00140     namespace vigra {
    00141         template <class SrcIterator, class SrcAccessor,
    00142                   class DestIterator, class DestAccessor,
    00143                   class DestValue = DestAccessor::value_type,
    00144                   class Neighborhood = EightNeighborCode>
    00145         void
    00146         localMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00147                     pair<DestIterator, DestAccessor> dest,
    00148                     DestValue marker = NumericTraits<DestValue>::one(),
    00149                     Neighborhood neighborhood = EightNeighborCode())
    00150     }
    00151     \endcode
    00152
    00153     <b> Usage:</b>
    00154
    00155         <b>\#include</b> <<a href="localminmax_8hxx-source.html">vigra/localminmax.hxx</a>><br>
    00156     Namespace: vigra
    00157
    00158     \code
    00159     vigra::BImage src(w,h), minima(w,h);
    00160
    00161     // init destiniation image
    00162     minima = 0;
    00163
    00164     vigra::localMinima(srcImageRange(src), destImage(minima));
    00165     \endcode
    00166
    00167     <b> Required Interface:</b>
    00168
    00169     \code
    00170     SrcImageIterator src_upperleft, src_lowerright;
    00171     DestImageIterator dest_upperleft;
    00172
    00173     SrcAccessor src_accessor;
    00174     DestAccessor dest_accessor;
    00175
    00176     SrcAccessor::value_type u = src_accessor(src_upperleft);
    00177
    00178     u < u
    00179
    00180     DestValue marker;
    00181     dest_accessor.set(marker, dest_upperleft);
    00182     \endcode
    00183
    00184 */
    00185 doxygen_overloaded_function(template <...> void localMinima)
    00186
    00187 template <class SrcIterator, class SrcAccessor,
    00188           class DestIterator, class DestAccessor,
    00189           class DestValue, class Neighborhood>
    00190 inline void
    00191 localMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00192             DestIterator dul, DestAccessor da,
    00193             DestValue marker, Neighborhood neighborhood)
    00194 {
    00195     detail::localMinMax(sul, slr, sa, dul, da, marker, neighborhood,
    00196                     std::less<typename SrcAccessor::value_type>());
    00197 }
    00198
    00199 template <class SrcIterator, class SrcAccessor,
    00200           class DestIterator, class DestAccessor, class DestValue>
    00201 inline void
    00202 localMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00203             DestIterator dul, DestAccessor da,
    00204             DestValue marker)
    00205 {
    00206     localMinima(sul, slr, sa, dul, da, marker, EightNeighborCode());
    00207 }
    00208
    00209 template <class SrcIterator, class SrcAccessor,
    00210           class DestIterator, class DestAccessor>
    00211 inline void
    00212 localMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00213             DestIterator dul, DestAccessor da)
    00214 {
    00215     localMinima(sul, slr, sa, dul, da,
    00216                 NumericTraits<typename DestAccessor::value_type>::one(),
    00217                 EightNeighborCode());
    00218 }
    00219
    00220 template <class SrcIterator, class SrcAccessor,
    00221           class DestIterator, class DestAccessor,
    00222           class DestValue, class Neighborhood>
    00223 inline void
    00224 localMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00225             pair<DestIterator, DestAccessor> dest,
    00226             DestValue marker, Neighborhood neighborhood)
    00227 {
    00228     localMinima(src.first, src.second, src.third,
    00229                 dest.first, dest.second, marker, neighborhood);
    00230 }
    00231
    00232 template <class SrcIterator, class SrcAccessor,
    00233           class DestIterator, class DestAccessor, class DestValue>
    00234 inline void
    00235 localMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00236             pair<DestIterator, DestAccessor> dest,
    00237             DestValue marker)
    00238 {
    00239     localMinima(src.first, src.second, src.third,
    00240                 dest.first, dest.second, marker, EightNeighborCode());
    00241 }
    00242
    00243 template <class SrcIterator, class SrcAccessor,
    00244           class DestIterator, class DestAccessor>
    00245 inline void
    00246 localMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00247             pair<DestIterator, DestAccessor> dest)
    00248 {
    00249     localMinima(src.first, src.second, src.third,
    00250                 dest.first, dest.second,
    00251                 NumericTraits<typename DestAccessor::value_type>::one(),
    00252                 EightNeighborCode());
    00253 }
    00254
    00255 /********************************************************/
    00256 /*                                                      */
    00257 /*                       localMaxima                    */
    00258 /*                                                      */
    00259 /********************************************************/
    00260
    00261 /** \brief Find local maxima in an image.
    00262
    00263     The maxima are found only when the have a size of one pixel.
    00264     Use \ref extendedLocalMaxima() to find maximal plateaus. Maxima are
    00265     marked in the destination image with the given marker value
    00266     (default is 1), all other destination pixels remain unchanged.
    00267     <TT>SrcAccessor::value_type</TT> must be less-comparable.
    00268     A pixel at the image border will never be marked as maximum.
    00269     The function uses accessors.
    00270
    00271     <b> Declarations:</b>
    00272
    00273     pass arguments explicitly:
    00274     \code
    00275     namespace vigra {
    00276         template <class SrcIterator, class SrcAccessor,
    00277                   class DestIterator, class DestAccessor,
    00278                   class DestValue = DestAccessor::value_type,
    00279                   class Neighborhood = EightNeighborCode>
    00280         void
    00281         localMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00282                     DestIterator dul, DestAccessor da,
    00283                     DestValue marker = NumericTraits<DestValue>::one(),
    00284                     Neighborhood neighborhood = EightNeighborCode())
    00285     }
    00286     \endcode
    00287
    00288     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00289     \code
    00290     namespace vigra {
    00291         template <class SrcIterator, class SrcAccessor,
    00292                   class DestIterator, class DestAccessor,
    00293                   class DestValue = DestAccessor::value_type,
    00294                   class Neighborhood = EightNeighborCode>
    00295         void
    00296         localMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00297                     pair<DestIterator, DestAccessor> dest,
    00298                     DestValue marker = NumericTraits<DestValue>::one(),
    00299                     Neighborhood neighborhood = EightNeighborCode())
    00300     }
    00301     \endcode
    00302
    00303     <b> Usage:</b>
    00304
    00305         <b>\#include</b> <<a href="localminmax_8hxx-source.html">vigra/localminmax.hxx</a>><br>
    00306     Namespace: vigra
    00307
    00308     \code
    00309     vigra::BImage src(w,h), maxima(w,h);
    00310
    00311     // init destiniation image
    00312     maxima = 0;
    00313
    00314     vigra::localMaxima(srcImageRange(src), destImage(maxima));
    00315     \endcode
    00316
    00317     <b> Required Interface:</b>
    00318
    00319     \code
    00320     SrcImageIterator src_upperleft, src_lowerright;
    00321     DestImageIterator dest_upperleft;
    00322
    00323     SrcAccessor src_accessor;
    00324     DestAccessor dest_accessor;
    00325
    00326     SrcAccessor::value_type u = src_accessor(src_upperleft);
    00327
    00328     u < u
    00329
    00330     DestValue marker;
    00331     dest_accessor.set(marker, dest_upperleft);
    00332     \endcode
    00333
    00334 */
    00335 doxygen_overloaded_function(template <...> void localMaxima)
    00336
    00337 template <class SrcIterator, class SrcAccessor,
    00338           class DestIterator, class DestAccessor,
    00339           class DestValue, class Neighborhood>
    00340 inline void
    00341 localMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00342             DestIterator dul, DestAccessor da,
    00343             DestValue marker, Neighborhood neighborhood)
    00344 {
    00345     detail::localMinMax(sul, slr, sa, dul, da, marker, neighborhood,
    00346                     std::greater<typename SrcAccessor::value_type>());
    00347 }
    00348
    00349 template <class SrcIterator, class SrcAccessor,
    00350           class DestIterator, class DestAccessor, class DestValue>
    00351 inline void
    00352 localMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00353             DestIterator dul, DestAccessor da,
    00354             DestValue marker)
    00355 {
    00356     localMaxima(sul, slr, sa, dul, da, marker, EightNeighborCode());
    00357 }
    00358
    00359 template <class SrcIterator, class SrcAccessor,
    00360           class DestIterator, class DestAccessor>
    00361 inline void
    00362 localMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00363             DestIterator dul, DestAccessor da)
    00364 {
    00365     localMaxima(sul, slr, sa, dul, da,
    00366                 NumericTraits<typename DestAccessor::value_type>::one(),
    00367                 EightNeighborCode());
    00368 }
    00369
    00370 template <class SrcIterator, class SrcAccessor,
    00371           class DestIterator, class DestAccessor,
    00372           class DestValue, class Neighborhood>
    00373 inline void
    00374 localMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00375             pair<DestIterator, DestAccessor> dest,
    00376             DestValue marker, Neighborhood neighborhood)
    00377 {
    00378     localMaxima(src.first, src.second, src.third,
    00379                 dest.first, dest.second, marker, neighborhood);
    00380 }
    00381
    00382 template <class SrcIterator, class SrcAccessor,
    00383           class DestIterator, class DestAccessor, class DestValue>
    00384 inline void
    00385 localMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00386             pair<DestIterator, DestAccessor> dest,
    00387             DestValue marker)
    00388 {
    00389     localMaxima(src.first, src.second, src.third,
    00390                 dest.first, dest.second, marker, EightNeighborCode());
    00391 }
    00392
    00393 template <class SrcIterator, class SrcAccessor,
    00394           class DestIterator, class DestAccessor>
    00395 inline void
    00396 localMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00397             pair<DestIterator, DestAccessor> dest)
    00398 {
    00399     localMaxima(src.first, src.second, src.third,
    00400                 dest.first, dest.second,
    00401                 NumericTraits<typename DestAccessor::value_type>::one(),
    00402                 EightNeighborCode());
    00403 }
    00404
    00405 namespace detail {
    00406
    00407 template <class SrcIterator, class SrcAccessor,
    00408           class DestIterator, class DestAccessor, class DestValue,
    00409           class Neighborhood, class Compare, class Equal>
    00410 void
    00411 extendedLocalMinMax(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00412             DestIterator dul, DestAccessor da, DestValue marker,
    00413             Neighborhood /*neighborhood*/, Compare compare, Equal equal)
    00414 {
    00415     typedef typename SrcAccessor::value_type SrcType;
    00416
    00417     int w = slr.x - sul.x;
    00418     int h = slr.y - sul.y;
    00419
    00420     int i,x,y;
    00421
    00422     BasicImage<int> labels(w,h);
    00423
    00424     int number_of_regions =
    00425         labelImage(sul, slr, sa, labels.upperLeft(), labels.accessor(),
    00426                    (Neighborhood::DirectionCount == 8), equal);
    00427
    00428     // assume that a region is a extremum until the opposite is proved
    00429     std::vector<unsigned char> isExtremum(number_of_regions+1, (unsigned char)1);
    00430
    00431     BasicImage<int>::traverser ly = labels.upperLeft();
    00432
    00433     for(y=0; y<h; ++y, ++sul.y, ++ly.y)
    00434     {
    00435         SrcIterator  sx = sul;
    00436         BasicImage<int>::traverser lx(ly);
    00437
    00438         for(x=0; x<w; ++x, ++sx.x, ++lx.x)
    00439         {
    00440             int lab = *lx;
    00441             if(x == 0 || y == 0 || x == w-1 || y == h-1)
    00442             {
    00443                 // mark all regions that touch the image border as non-extremum
    00444                 isExtremum[lab] = 0;
    00445                 continue;
    00446             }
    00447
    00448             SrcType v = sa(sx);
    00449             NeighborhoodCirculator<SrcIterator, Neighborhood> sc(sx);
    00450             NeighborhoodCirculator<BasicImage<int>::traverser, Neighborhood> lc(lx);
    00451             for(i=0; i<Neighborhood::DirectionCount; ++i, ++sc, ++lc)
    00452             {
    00453                 if(lab != *lc && compare(sa(sc),v))
    00454                     isExtremum[lab] = 0;
    00455             }
    00456
    00457         }
    00458     }
    00459
    00460     ly = labels.upperLeft();
    00461     for(y=0; y<h; ++y, ++dul.y, ++ly.y)
    00462     {
    00463         DestIterator  xd = dul;
    00464         BasicImage<int>::Iterator lx(ly);
    00465
    00466         for(x=0; x<w; ++x, ++xd.x, ++lx.x)
    00467         {
    00468             if(isExtremum[*lx])
    00469                 da.set(marker, xd);
    00470         }
    00471     }
    00472 }
    00473
    00474 } // namespace detail
    00475
    00476 /********************************************************/
    00477 /*                                                      */
    00478 /*                 extendedLocalMinima                  */
    00479 /*                                                      */
    00480 /********************************************************/
    00481
    00482 /** \brief Find local minimal regions in an image.
    00483
    00484     This function finds regions of uniform pixel value
    00485     whose neighboring regions are all have smaller values
    00486     (minimal plateaus of arbitrary size). By default, the pixels
    00487     in a plateau have exactly identical values. By passing an <tt>EqualityFunctor</tt>
    00488     with tolerance, one can allow for plateaus that are not quite constant
    00489     (this is often necessary with float pixel values). Pass
    00490     \ref vigra::EightNeighborCode or \ref vigra::FourNeighborCode
    00491     to determine the neighborhood where pixel values are compared.
    00492
    00493
    00494     Minimal regions are
    00495     marked in the destination image with the given marker value
    00496     (default is 1), all other destination pixels remain unchanged.
    00497     <TT>SrcAccessor::value_type</TT> must be equality-comparable and
    00498     less-comparable.
    00499     A pixel or region touching the image border will never be marked as minimum or
    00500     minimal plateau.
    00501     The function uses accessors.
    00502
    00503     <b> Declarations:</b>
    00504
    00505     pass arguments explicitly:
    00506     \code
    00507     namespace vigra {
    00508         template <class SrcIterator, class SrcAccessor,
    00509                   class DestIterator, class DestAccessor,
    00510                   class DestValue = DestAccessor::value_type,
    00511                   class Neighborhood = EightNeighborCode,
    00512                   class EqualityFunctor = std::equal_to<typename SrcAssessor::value_type> >
    00513         void
    00514         extendedLocalMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00515                             DestIterator dul, DestAccessor da,
    00516                             DestValue marker = NumericTraits<DestValue>::one(),
    00517                             Neighborhood neighborhood = EightNeighborCode(),
    00518                             EqualityFunctor equal = EqualityFunctor())
    00519     }
    00520     \endcode
    00521
    00522     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00523     \code
    00524     namespace vigra {
    00525         template <class SrcIterator, class SrcAccessor,
    00526                   class DestIterator, class DestAccessor,
    00527                   class DestValue = DestAccessor::value_type,
    00528                   class Neighborhood = EightNeighborCode,
    00529                   class EqualityFunctor = std::equal_to<typename SrcAssessor::value_type> >
    00530         void
    00531         extendedLocalMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00532                             pair<DestIterator, DestAccessor> dest,
    00533                             DestValue marker = NumericTraits<DestValue>::one(),
    00534                             Neighborhood neighborhood = EightNeighborCode(),
    00535                             EqualityFunctor equal = EqualityFunctor())
    00536     }
    00537     \endcode
    00538
    00539     <b> Usage:</b>
    00540
    00541         <b>\#include</b> <<a href="localminmax_8hxx-source.html">vigra/localminmax.hxx</a>><br>
    00542     Namespace: vigra
    00543
    00544     \code
    00545
    00546     // optional: define an equality functor
    00547     template <class T>
    00548     struct EqualWithToleranceFunctor
    00549     {
    00550         EqualWithToleranceFunctor(T tolerance)
    00551         : t(tolerance)
    00552         {}
    00553
    00554         bool operator()(T l, T r) const
    00555         {
    00556             return vigra::abs(l-r) <= t;
    00557         }
    00558
    00559         T t;
    00560     };
    00561
    00562     vigra::BImage src(w,h), minima(w,h);
    00563
    00564     // init destiniation image
    00565     minima.init(0);
    00566
    00567     vigra::extendedLocalMinima(srcImageRange(src), destImage(minima));
    00568
    00569     // allow plateaus with tolerance
    00570     minima.init(0);
    00571     vigra::extendedLocalMinima(srcImageRange(src), destImage(minima), 1.0,
    00572                                EqualWithToleranceFunctor<unsigned char>(1));
    00573     \endcode
    00574
    00575     <b> Required Interface:</b>
    00576
    00577     \code
    00578     SrcImageIterator src_upperleft, src_lowerright;
    00579     DestImageIterator dest_upperleft;
    00580
    00581     SrcAccessor src_accessor;
    00582     DestAccessor dest_accessor;
    00583
    00584     SrcAccessor::value_type u = src_accessor(src_upperleft);
    00585
    00586     EqualityFunctor equal;
    00587     u == u
    00588     equal(u, u);
    00589     u < u
    00590
    00591     DestValue marker;
    00592     dest_accessor.set(marker, dest_upperleft);
    00593     \endcode
    00594
    00595 */
    00596 doxygen_overloaded_function(template <...> void extendedLocalMinima)
    00597
    00598 template <class SrcIterator, class SrcAccessor,
    00599           class DestIterator, class DestAccessor, class DestValue,
    00600           class Neighborhood, class EqualityFunctor>
    00601 inline void
    00602 extendedLocalMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00603             DestIterator dul, DestAccessor da, DestValue marker,
    00604             Neighborhood neighborhood, EqualityFunctor equal)
    00605 {
    00606     typedef typename SrcAccessor::value_type SrcType;
    00607
    00608     detail::extendedLocalMinMax(sul, slr, sa, dul, da,
    00609                                 marker, neighborhood,
    00610                                 std::less<SrcType>(), equal);
    00611 }
    00612
    00613 template <class SrcIterator, class SrcAccessor,
    00614           class DestIterator, class DestAccessor, class DestValue,
    00615           class Neighborhood>
    00616 inline void
    00617 extendedLocalMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00618             DestIterator dul, DestAccessor da, DestValue marker,
    00619             Neighborhood neighborhood)
    00620 {
    00621     typedef typename SrcAccessor::value_type SrcType;
    00622
    00623     extendedLocalMinima(sul, slr, sa, dul, da,
    00624                         marker, neighborhood, std::equal_to<SrcType>());
    00625 }
    00626
    00627 template <class SrcIterator, class SrcAccessor,
    00628           class DestIterator, class DestAccessor, class DestValue>
    00629 inline void
    00630 extendedLocalMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00631             DestIterator dul, DestAccessor da, DestValue marker)
    00632 {
    00633     typedef typename SrcAccessor::value_type SrcType;
    00634
    00635     extendedLocalMinima(sul, slr, sa, dul, da,
    00636                         marker, EightNeighborCode());
    00637 }
    00638
    00639 template <class SrcIterator, class SrcAccessor,
    00640           class DestIterator, class DestAccessor>
    00641 inline void
    00642 extendedLocalMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00643             DestIterator dul, DestAccessor da)
    00644 {
    00645     extendedLocalMinima(sul, slr, sa, dul, da,
    00646                 NumericTraits<typename DestAccessor::value_type>::one());
    00647 }
    00648
    00649 template <class SrcIterator, class SrcAccessor,
    00650           class DestIterator, class DestAccessor, class DestValue,
    00651           class Neighborhood, class EqualityFunctor>
    00652 inline void
    00653 extendedLocalMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00654             pair<DestIterator, DestAccessor> dest,
    00655             DestValue marker, Neighborhood neighborhood,
    00656             EqualityFunctor equal)
    00657 {
    00658     extendedLocalMinima(src.first, src.second, src.third,
    00659                 dest.first, dest.second, marker, neighborhood, equal);
    00660 }
    00661
    00662 template <class SrcIterator, class SrcAccessor,
    00663           class DestIterator, class DestAccessor, class DestValue,
    00664           class Neighborhood>
    00665 inline void
    00666 extendedLocalMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00667             pair<DestIterator, DestAccessor> dest,
    00668             DestValue marker, Neighborhood neighborhood)
    00669 {
    00670     extendedLocalMinima(src.first, src.second, src.third,
    00671                         dest.first, dest.second, marker, neighborhood);
    00672 }
    00673
    00674 template <class SrcIterator, class SrcAccessor,
    00675           class DestIterator, class DestAccessor, class DestValue>
    00676 inline void
    00677 extendedLocalMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00678             pair<DestIterator, DestAccessor> dest,
    00679             DestValue marker)
    00680 {
    00681     extendedLocalMinima(src.first, src.second, src.third,
    00682                         dest.first, dest.second, marker);
    00683 }
    00684
    00685 template <class SrcIterator, class SrcAccessor,
    00686           class DestIterator, class DestAccessor>
    00687 inline void
    00688 extendedLocalMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00689             pair<DestIterator, DestAccessor> dest)
    00690 {
    00691     extendedLocalMinima(src.first, src.second, src.third,
    00692                         dest.first, dest.second);
    00693 }
    00694
    00695 /********************************************************/
    00696 /*                                                      */
    00697 /*                 extendedLocalMaxima                  */
    00698 /*                                                      */
    00699 /********************************************************/
    00700
    00701 /** \brief Find local maximal regions in an image.
    00702
    00703     This function finds regions of uniform pixel value
    00704     whose neighboring regions are all have smaller values
    00705     (maximal plateaus of arbitrary size). By default, the pixels
    00706     in a plateau have exactly identical values. By passing an <tt>EqualityFunctor</tt>
    00707     with tolerance, one can allow for plateaus that are not quite constant
    00708     (this is often necessary with float pixel values). Pass
    00709     \ref vigra::EightNeighborCode or \ref vigra::FourNeighborCode
    00710     to determine the neighborhood where pixel values are compared.
    00711
    00712
    00713     Maximal regions are
    00714     marked in the destination image with the given marker value
    00715     (default is 1), all other destination pixels remain unchanged.
    00716     <TT>SrcAccessor::value_type</TT> must be equality-comparable and
    00717     less-comparable.
    00718     A pixel or region touching the image border will never be marked as maximum or
    00719     maximal plateau.
    00720     The function uses accessors.
    00721
    00722     <b> Declarations:</b>
    00723
    00724     pass arguments explicitly:
    00725     \code
    00726     namespace vigra {
    00727         template <class SrcIterator, class SrcAccessor,
    00728                   class DestIterator, class DestAccessor,
    00729                   class DestValue = DestAccessor::value_type,
    00730                   class Neighborhood = EightNeighborCode,
    00731                   class EqualityFunctor = std::equal_to<typename SrcAssessor::value_type> >
    00732         void
    00733         extendedLocalMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00734                             DestIterator dul, DestAccessor da,
    00735                             DestValue marker = NumericTraits<DestValue>::one(),
    00736                             Neighborhood neighborhood = EightNeighborCode(),
    00737                             EqualityFunctor equal = EqualityFunctor())
    00738     }
    00739     \endcode
    00740
    00741     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00742     \code
    00743     namespace vigra {
    00744         template <class SrcIterator, class SrcAccessor,
    00745                   class DestIterator, class DestAccessor,
    00746                   class DestValue = DestAccessor::value_type,
    00747                   class Neighborhood = EightNeighborCode,
    00748                   class EqualityFunctor = std::equal_to<typename SrcAssessor::value_type> >
    00749         void
    00750         extendedLocalMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00751                             pair<DestIterator, DestAccessor> dest,
    00752                             DestValue marker = NumericTraits<DestValue>::one(),
    00753                             Neighborhood neighborhood = EightNeighborCode(),
    00754                             EqualityFunctor equal = EqualityFunctor())
    00755     }
    00756     \endcode
    00757
    00758     <b> Usage:</b>
    00759
    00760         <b>\#include</b> <<a href="localminmax_8hxx-source.html">vigra/localminmax.hxx</a>><br>
    00761     Namespace: vigra
    00762
    00763     \code
    00764
    00765     // optional: define an equality functor
    00766     template <class T>
    00767     struct EqualWithToleranceFunctor
    00768     {
    00769         EqualWithToleranceFunctor(T tolerance)
    00770         : t(tolerance)
    00771         {}
    00772
    00773         bool operator()(T l, T r) const
    00774         {
    00775             return vigra::abs(l-r) <= t;
    00776         }
    00777
    00778         T t;
    00779     };
    00780
    00781     vigra::BImage src(w,h), maxima(w,h);
    00782
    00783     // init destiniation image
    00784     maxima.init(0);
    00785
    00786     vigra::extendedLocalMaxima(srcImageRange(src), destImage(maxima));
    00787
    00788     // allow plateaus with tolerance
    00789     maxima.init(0);
    00790     vigra::extendedLocalMaxima(srcImageRange(src), destImage(maxima), 1.0,
    00791                                EqualWithToleranceFunctor<unsigned char>(1));
    00792     \endcode
    00793
    00794     <b> Required Interface:</b>
    00795
    00796     \code
    00797     SrcImageIterator src_upperleft, src_lowerright;
    00798     DestImageIterator dest_upperleft;
    00799
    00800     SrcAccessor src_accessor;
    00801     DestAccessor dest_accessor;
    00802
    00803     SrcAccessor::value_type u = src_accessor(src_upperleft);
    00804
    00805     EqualityFunctor equal;
    00806     u == u
    00807     equal(u, u);
    00808     u < u
    00809
    00810     DestValue marker;
    00811     dest_accessor.set(marker, dest_upperleft);
    00812     \endcode
    00813
    00814 */
    00815 doxygen_overloaded_function(template <...> void extendedLocalMaxima)
    00816
    00817 template <class SrcIterator, class SrcAccessor,
    00818           class DestIterator, class DestAccessor, class DestValue,
    00819           class Neighborhood, class EqualityFunctor>
    00820 inline void
    00821 extendedLocalMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00822             DestIterator dul, DestAccessor da, DestValue marker,
    00823             Neighborhood neighborhood, EqualityFunctor equal)
    00824 {
    00825     typedef typename SrcAccessor::value_type SrcType;
    00826
    00827     detail::extendedLocalMinMax(sul, slr, sa, dul, da,
    00828                                 marker, neighborhood,
    00829                                 std::greater<SrcType>(), equal);
    00830 }
    00831
    00832 template <class SrcIterator, class SrcAccessor,
    00833           class DestIterator, class DestAccessor, class DestValue,
    00834           class Neighborhood>
    00835 inline void
    00836 extendedLocalMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00837             DestIterator dul, DestAccessor da, DestValue marker,
    00838             Neighborhood neighborhood)
    00839 {
    00840     typedef typename SrcAccessor::value_type SrcType;
    00841
    00842     extendedLocalMaxima(sul, slr, sa, dul, da,
    00843                         marker, neighborhood, std::equal_to<SrcType>());
    00844 }
    00845
    00846 template <class SrcIterator, class SrcAccessor,
    00847           class DestIterator, class DestAccessor, class DestValue>
    00848 inline void
    00849 extendedLocalMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00850             DestIterator dul, DestAccessor da, DestValue marker)
    00851 {
    00852     typedef typename SrcAccessor::value_type SrcType;
    00853
    00854     extendedLocalMaxima(sul, slr, sa, dul, da,
    00855                         marker, EightNeighborCode());
    00856 }
    00857
    00858 template <class SrcIterator, class SrcAccessor,
    00859           class DestIterator, class DestAccessor>
    00860 inline void
    00861 extendedLocalMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00862             DestIterator dul, DestAccessor da)
    00863 {
    00864     extendedLocalMaxima(sul, slr, sa, dul, da,
    00865                 NumericTraits<typename DestAccessor::value_type>::one());
    00866 }
    00867
    00868 template <class SrcIterator, class SrcAccessor,
    00869           class DestIterator, class DestAccessor, class DestValue,
    00870           class Neighborhood, class EqualityFunctor>
    00871 inline void
    00872 extendedLocalMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00873             pair<DestIterator, DestAccessor> dest,
    00874             DestValue marker, Neighborhood neighborhood,
    00875             EqualityFunctor equal)
    00876 {
    00877     extendedLocalMaxima(src.first, src.second, src.third,
    00878                 dest.first, dest.second, marker, neighborhood, equal);
    00879 }
    00880
    00881 template <class SrcIterator, class SrcAccessor,
    00882           class DestIterator, class DestAccessor, class DestValue,
    00883           class Neighborhood>
    00884 inline void
    00885 extendedLocalMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00886             pair<DestIterator, DestAccessor> dest,
    00887             DestValue marker, Neighborhood neighborhood)
    00888 {
    00889     extendedLocalMaxima(src.first, src.second, src.third,
    00890                         dest.first, dest.second, marker, neighborhood);
    00891 }
    00892
    00893 template <class SrcIterator, class SrcAccessor,
    00894           class DestIterator, class DestAccessor, class DestValue>
    00895 inline void
    00896 extendedLocalMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00897             pair<DestIterator, DestAccessor> dest,
    00898             DestValue marker)
    00899 {
    00900     extendedLocalMaxima(src.first, src.second, src.third,
    00901                         dest.first, dest.second, marker);
    00902 }
    00903
    00904 template <class SrcIterator, class SrcAccessor,
    00905           class DestIterator, class DestAccessor>
    00906 inline void
    00907 extendedLocalMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00908             pair<DestIterator, DestAccessor> dest)
    00909 {
    00910     extendedLocalMaxima(src.first, src.second, src.third,
    00911                         dest.first, dest.second);
    00912 }
    00913
    00914 //@}
    00915
    00916 } // namespace vigra
    00917
    00918 #endif // VIGRA_LOCALMINMAX_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)