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