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

vigra/localminmax.hxx |

    00001 /************************************************************************/
    00002 /*                                                                      */
    00003 /*               Copyright 1998-2002 by Ullrich Koethe                  */
    00004 /*                                                                      */
    00005 /*    This file is part of the VIGRA computer vision library.           */
    00006 /*    The VIGRA Website is                                              */
    00007 /*        http://hci.iwr.uni-heidelberg.de/vigra/                       */
    00008 /*    Please direct questions, bug reports, and contributions to        */
    00009 /*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
    00010 /*        vigra@informatik.uni-hamburg.de                               */
    00011 /*                                                                      */
    00012 /*    Permission is hereby granted, free of charge, to any person       */
    00013 /*    obtaining a copy of this software and associated documentation    */
    00014 /*    files (the "Software"), to deal in the Software without           */
    00015 /*    restriction, including without limitation the rights to use,      */
    00016 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
    00017 /*    sell copies of the Software, and to permit persons to whom the    */
    00018 /*    Software is furnished to do so, subject to the following          */
    00019 /*    conditions:                                                       */
    00020 /*                                                                      */
    00021 /*    The above copyright notice and this permission notice shall be    */
    00022 /*    included in all copies or substantial portions of the             */
    00023 /*    Software.                                                         */
    00024 /*                                                                      */
    00025 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
    00026 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
    00027 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
    00028 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
    00029 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
    00030 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
    00031 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
    00032 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */
    00033 /*                                                                      */
    00034 /************************************************************************/
    00035
    00036
    00037 #ifndef VIGRA_LOCALMINMAX_HXX
    00038 #define VIGRA_LOCALMINMAX_HXX
    00039
    00040 #include <vector>
    00041 #include <functional>
    00042 #include "utilities.hxx"
    00043 #include "stdimage.hxx"
    00044 #include "initimage.hxx"
    00045 #include "labelimage.hxx"
    00046 #include "pixelneighborhood.hxx"
    00047
    00048 namespace vigra {
    00049
    00050 /** \addtogroup LocalMinMax Local Minima and Maxima
    00051
    00052     Detect local minima and maxima of the gray level,
    00053     including extremal plateaus larger than 1 pixel
    00054 */
    00055 //@{
    00056
    00057 namespace detail {
    00058
    00059 template <class SrcIterator, class SrcAccessor,
    00060           class DestIterator, class DestAccessor,
    00061           class DestValue, class Neighborhood,
    00062           class Compare>
    00063 void
    00064 localMinMax(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00065                 DestIterator dul, DestAccessor da,
    00066                 DestValue marker, Neighborhood,
    00067                 Compare compare)
    00068 {
    00069     int w = slr.x - sul.x - 2;
    00070     int h = slr.y - sul.y - 2;
    00071
    00072     int i,x,y;
    00073
    00074     sul += Diff2D(1,1);
    00075     dul += Diff2D(1,1);
    00076
    00077     for(y=0; y<h; ++y, ++sul.y, ++dul.y)
    00078     {
    00079         SrcIterator  sx = sul;
    00080         DestIterator dx = dul;
    00081
    00082         for(x=0; x<w; ++x, ++sx.x, ++dx.x)
    00083         {
    00084             typename SrcAccessor::value_type v = sa(sx);
    00085             NeighborhoodCirculator<SrcIterator, Neighborhood> sc(sx);
    00086             for(i = 0; i < Neighborhood::DirectionCount; ++i, ++sc)
    00087             {
    00088                 if(!compare(v, sa(sc)))
    00089                     break;
    00090             }
    00091
    00092             if(i == Neighborhood::DirectionCount)
    00093                 da.set(marker, dx);
    00094         }
    00095     }
    00096 }
    00097
    00098 } // namespace detail
    00099
    00100
    00101 /********************************************************/
    00102 /*                                                      */
    00103 /*                       localMinima                    */
    00104 /*                                                      */
    00105 /********************************************************/
    00106
    00107 /** \brief Find local minima in an image.
    00108
    00109     The minima are found only when the have a size of one pixel.
    00110     Use \ref extendedLocalMinima() to find minimal plateaus. Minima are
    00111     marked in the destination image with the given marker value
    00112     (default is 1), all other destination pixels remain unchanged.
    00113     <TT>SrcAccessor::value_type</TT> must be less-comparable.
    00114     A pixel at the image border will never be marked as minimum.
    00115     Pass \ref vigra::EightNeighborCode or \ref vigra::FourNeighborCode
    00116     to determine the neighborhood where pixel values are compared.
    00117     The function uses accessors.
    00118
    00119     <b> Declarations:</b>
    00120
    00121     pass arguments explicitly:
    00122     \code
    00123     namespace vigra {
    00124         template <class SrcIterator, class SrcAccessor,
    00125                   class DestIterator, class DestAccessor,
    00126                   class DestValue = DestAccessor::value_type,
    00127                   class Neighborhood = EightNeighborCode>
    00128         void
    00129         localMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00130                     DestIterator dul, DestAccessor da,
    00131                     DestValue marker = NumericTraits<DestValue>::one(),
    00132                     Neighborhood neighborhood = EightNeighborCode())
    00133     }
    00134     \endcode
    00135
    00136     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00137     \code
    00138     namespace vigra {
    00139         template <class SrcIterator, class SrcAccessor,
    00140                   class DestIterator, class DestAccessor,
    00141                   class DestValue = DestAccessor::value_type,
    00142                   class Neighborhood = EightNeighborCode>
    00143         void
    00144         localMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00145                     pair<DestIterator, DestAccessor> dest,
    00146                     DestValue marker = NumericTraits<DestValue>::one(),
    00147                     Neighborhood neighborhood = EightNeighborCode())
    00148     }
    00149     \endcode
    00150
    00151     <b> Usage:</b>
    00152
    00153         <b>\#include</b> <<a href="localminmax_8hxx-source.html">vigra/localminmax.hxx</a>><br>
    00154     Namespace: vigra
    00155
    00156     \code
    00157     vigra::BImage src(w,h), minima(w,h);
    00158
    00159     // init destiniation image
    00160     minima = 0;
    00161
    00162     vigra::localMinima(srcImageRange(src), destImage(minima));
    00163     \endcode
    00164
    00165     <b> Required Interface:</b>
    00166
    00167     \code
    00168     SrcImageIterator src_upperleft, src_lowerright;
    00169     DestImageIterator dest_upperleft;
    00170
    00171     SrcAccessor src_accessor;
    00172     DestAccessor dest_accessor;
    00173
    00174     SrcAccessor::value_type u = src_accessor(src_upperleft);
    00175
    00176     u < u
    00177
    00178     DestValue marker;
    00179     dest_accessor.set(marker, dest_upperleft);
    00180     \endcode
    00181
    00182 */
    00183 doxygen_overloaded_function(template <...> void localMinima)
    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 doxygen_overloaded_function(template <...> void localMaxima)
    00334
    00335 template <class SrcIterator, class SrcAccessor,
    00336           class DestIterator, class DestAccessor,
    00337           class DestValue, class Neighborhood>
    00338 inline void
    00339 localMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00340             DestIterator dul, DestAccessor da,
    00341             DestValue marker, Neighborhood neighborhood)
    00342 {
    00343     detail::localMinMax(sul, slr, sa, dul, da, marker, neighborhood,
    00344                     std::greater<typename SrcAccessor::value_type>());
    00345 }
    00346
    00347 template <class SrcIterator, class SrcAccessor,
    00348           class DestIterator, class DestAccessor, class DestValue>
    00349 inline void
    00350 localMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00351             DestIterator dul, DestAccessor da,
    00352             DestValue marker)
    00353 {
    00354     localMaxima(sul, slr, sa, dul, da, marker, EightNeighborCode());
    00355 }
    00356
    00357 template <class SrcIterator, class SrcAccessor,
    00358           class DestIterator, class DestAccessor>
    00359 inline void
    00360 localMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00361             DestIterator dul, DestAccessor da)
    00362 {
    00363     localMaxima(sul, slr, sa, dul, da,
    00364                 NumericTraits<typename DestAccessor::value_type>::one(),
    00365                 EightNeighborCode());
    00366 }
    00367
    00368 template <class SrcIterator, class SrcAccessor,
    00369           class DestIterator, class DestAccessor,
    00370           class DestValue, class Neighborhood>
    00371 inline void
    00372 localMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00373             pair<DestIterator, DestAccessor> dest,
    00374             DestValue marker, Neighborhood neighborhood)
    00375 {
    00376     localMaxima(src.first, src.second, src.third,
    00377                 dest.first, dest.second, marker, neighborhood);
    00378 }
    00379
    00380 template <class SrcIterator, class SrcAccessor,
    00381           class DestIterator, class DestAccessor, class DestValue>
    00382 inline void
    00383 localMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00384             pair<DestIterator, DestAccessor> dest,
    00385             DestValue marker)
    00386 {
    00387     localMaxima(src.first, src.second, src.third,
    00388                 dest.first, dest.second, marker, EightNeighborCode());
    00389 }
    00390
    00391 template <class SrcIterator, class SrcAccessor,
    00392           class DestIterator, class DestAccessor>
    00393 inline void
    00394 localMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00395             pair<DestIterator, DestAccessor> dest)
    00396 {
    00397     localMaxima(src.first, src.second, src.third,
    00398                 dest.first, dest.second,
    00399                 NumericTraits<typename DestAccessor::value_type>::one(),
    00400                 EightNeighborCode());
    00401 }
    00402
    00403 namespace detail {
    00404
    00405 template <class SrcIterator, class SrcAccessor,
    00406           class DestIterator, class DestAccessor, class DestValue,
    00407           class Neighborhood, class Compare, class Equal>
    00408 void
    00409 extendedLocalMinMax(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00410             DestIterator dul, DestAccessor da, DestValue marker,
    00411             Neighborhood /*neighborhood*/, Compare compare, Equal equal)
    00412 {
    00413     typedef typename SrcAccessor::value_type SrcType;
    00414
    00415     int w = slr.x - sul.x;
    00416     int h = slr.y - sul.y;
    00417
    00418     int i,x,y;
    00419
    00420     BasicImage<int> labels(w,h);
    00421
    00422     int number_of_regions =
    00423         labelImage(sul, slr, sa, labels.upperLeft(), labels.accessor(),
    00424                    (Neighborhood::DirectionCount == 8), equal);
    00425
    00426     // assume that a region is a extremum until the opposite is proved
    00427     std::vector<unsigned char> isExtremum(number_of_regions+1, (unsigned char)1);
    00428
    00429     BasicImage<int>::traverser ly = labels.upperLeft();
    00430
    00431     for(y=0; y<h; ++y, ++sul.y, ++ly.y)
    00432     {
    00433         SrcIterator  sx = sul;
    00434         BasicImage<int>::traverser lx(ly);
    00435
    00436         for(x=0; x<w; ++x, ++sx.x, ++lx.x)
    00437         {
    00438             int lab = *lx;
    00439             if(x == 0 || y == 0 || x == w-1 || y == h-1)
    00440             {
    00441                 // mark all regions that touch the image border as non-extremum
    00442                 isExtremum[lab] = 0;
    00443                 continue;
    00444             }
    00445
    00446             SrcType v = sa(sx);
    00447             NeighborhoodCirculator<SrcIterator, Neighborhood> sc(sx);
    00448             NeighborhoodCirculator<BasicImage<int>::traverser, Neighborhood> lc(lx);
    00449             for(i=0; i<Neighborhood::DirectionCount; ++i, ++sc, ++lc)
    00450             {
    00451                 if(lab != *lc && compare(sa(sc),v))
    00452                     isExtremum[lab] = 0;
    00453             }
    00454
    00455         }
    00456     }
    00457
    00458     ly = labels.upperLeft();
    00459     for(y=0; y<h; ++y, ++dul.y, ++ly.y)
    00460     {
    00461         DestIterator  xd = dul;
    00462         BasicImage<int>::Iterator lx(ly);
    00463
    00464         for(x=0; x<w; ++x, ++xd.x, ++lx.x)
    00465         {
    00466             if(isExtremum[*lx])
    00467                 da.set(marker, xd);
    00468         }
    00469     }
    00470 }
    00471
    00472 } // namespace detail
    00473
    00474 /********************************************************/
    00475 /*                                                      */
    00476 /*                 extendedLocalMinima                  */
    00477 /*                                                      */
    00478 /********************************************************/
    00479
    00480 /** \brief Find local minimal regions in an image.
    00481
    00482     This function finds regions of uniform pixel value
    00483     whose neighboring regions are all have smaller values
    00484     (minimal plateaus of arbitrary size). By default, the pixels
    00485     in a plateau have exactly identical values. By passing an <tt>EqualityFunctor</tt>
    00486     with tolerance, one can allow for plateaus that are not quite constant
    00487     (this is often necessary with float pixel values). Pass
    00488     \ref vigra::EightNeighborCode or \ref vigra::FourNeighborCode
    00489     to determine the neighborhood where pixel values are compared.
    00490
    00491
    00492     Minimal regions are
    00493     marked in the destination image with the given marker value
    00494     (default is 1), all other destination pixels remain unchanged.
    00495     <TT>SrcAccessor::value_type</TT> must be equality-comparable and
    00496     less-comparable.
    00497     A pixel or region touching the image border will never be marked as minimum or
    00498     minimal plateau.
    00499     The function uses accessors.
    00500
    00501     <b> Declarations:</b>
    00502
    00503     pass arguments explicitly:
    00504     \code
    00505     namespace vigra {
    00506         template <class SrcIterator, class SrcAccessor,
    00507                   class DestIterator, class DestAccessor,
    00508                   class DestValue = DestAccessor::value_type,
    00509                   class Neighborhood = EightNeighborCode,
    00510                   class EqualityFunctor = std::equal_to<typename SrcAssessor::value_type> >
    00511         void
    00512         extendedLocalMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00513                             DestIterator dul, DestAccessor da,
    00514                             DestValue marker = NumericTraits<DestValue>::one(),
    00515                             Neighborhood neighborhood = EightNeighborCode(),
    00516                             EqualityFunctor equal = EqualityFunctor())
    00517     }
    00518     \endcode
    00519
    00520     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00521     \code
    00522     namespace vigra {
    00523         template <class SrcIterator, class SrcAccessor,
    00524                   class DestIterator, class DestAccessor,
    00525                   class DestValue = DestAccessor::value_type,
    00526                   class Neighborhood = EightNeighborCode,
    00527                   class EqualityFunctor = std::equal_to<typename SrcAssessor::value_type> >
    00528         void
    00529         extendedLocalMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00530                             pair<DestIterator, DestAccessor> dest,
    00531                             DestValue marker = NumericTraits<DestValue>::one(),
    00532                             Neighborhood neighborhood = EightNeighborCode(),
    00533                             EqualityFunctor equal = EqualityFunctor())
    00534     }
    00535     \endcode
    00536
    00537     <b> Usage:</b>
    00538
    00539         <b>\#include</b> <<a href="localminmax_8hxx-source.html">vigra/localminmax.hxx</a>><br>
    00540     Namespace: vigra
    00541
    00542     \code
    00543
    00544     // optional: define an equality functor
    00545     template <class T>
    00546     struct EqualWithToleranceFunctor
    00547     {
    00548         EqualWithToleranceFunctor(T tolerance)
    00549         : t(tolerance)
    00550         {}
    00551
    00552         bool operator()(T l, T r) const
    00553         {
    00554             return vigra::abs(l-r) <= t;
    00555         }
    00556
    00557         T t;
    00558     };
    00559
    00560     vigra::BImage src(w,h), minima(w,h);
    00561
    00562     // init destiniation image
    00563     minima.init(0);
    00564
    00565     vigra::extendedLocalMinima(srcImageRange(src), destImage(minima));
    00566
    00567     // allow plateaus with tolerance
    00568     minima.init(0);
    00569     vigra::extendedLocalMinima(srcImageRange(src), destImage(minima), 1.0,
    00570                                EqualWithToleranceFunctor<unsigned char>(1));
    00571     \endcode
    00572
    00573     <b> Required Interface:</b>
    00574
    00575     \code
    00576     SrcImageIterator src_upperleft, src_lowerright;
    00577     DestImageIterator dest_upperleft;
    00578
    00579     SrcAccessor src_accessor;
    00580     DestAccessor dest_accessor;
    00581
    00582     SrcAccessor::value_type u = src_accessor(src_upperleft);
    00583
    00584     EqualityFunctor equal;
    00585     u == u
    00586     equal(u, u);
    00587     u < u
    00588
    00589     DestValue marker;
    00590     dest_accessor.set(marker, dest_upperleft);
    00591     \endcode
    00592
    00593 */
    00594 doxygen_overloaded_function(template <...> void extendedLocalMinima)
    00595
    00596 template <class SrcIterator, class SrcAccessor,
    00597           class DestIterator, class DestAccessor, class DestValue,
    00598           class Neighborhood, class EqualityFunctor>
    00599 inline void
    00600 extendedLocalMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00601             DestIterator dul, DestAccessor da, DestValue marker,
    00602             Neighborhood neighborhood, EqualityFunctor equal)
    00603 {
    00604     typedef typename SrcAccessor::value_type SrcType;
    00605
    00606     detail::extendedLocalMinMax(sul, slr, sa, dul, da,
    00607                                 marker, neighborhood,
    00608                                 std::less<SrcType>(), equal);
    00609 }
    00610
    00611 template <class SrcIterator, class SrcAccessor,
    00612           class DestIterator, class DestAccessor, class DestValue,
    00613           class Neighborhood>
    00614 inline void
    00615 extendedLocalMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00616             DestIterator dul, DestAccessor da, DestValue marker,
    00617             Neighborhood neighborhood)
    00618 {
    00619     typedef typename SrcAccessor::value_type SrcType;
    00620
    00621     extendedLocalMinima(sul, slr, sa, dul, da,
    00622                         marker, neighborhood, std::equal_to<SrcType>());
    00623 }
    00624
    00625 template <class SrcIterator, class SrcAccessor,
    00626           class DestIterator, class DestAccessor, class DestValue>
    00627 inline void
    00628 extendedLocalMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00629             DestIterator dul, DestAccessor da, DestValue marker)
    00630 {
    00631     typedef typename SrcAccessor::value_type SrcType;
    00632
    00633     extendedLocalMinima(sul, slr, sa, dul, da,
    00634                         marker, EightNeighborCode());
    00635 }
    00636
    00637 template <class SrcIterator, class SrcAccessor,
    00638           class DestIterator, class DestAccessor>
    00639 inline void
    00640 extendedLocalMinima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00641             DestIterator dul, DestAccessor da)
    00642 {
    00643     extendedLocalMinima(sul, slr, sa, dul, da,
    00644                 NumericTraits<typename DestAccessor::value_type>::one());
    00645 }
    00646
    00647 template <class SrcIterator, class SrcAccessor,
    00648           class DestIterator, class DestAccessor, class DestValue,
    00649           class Neighborhood, class EqualityFunctor>
    00650 inline void
    00651 extendedLocalMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00652             pair<DestIterator, DestAccessor> dest,
    00653             DestValue marker, Neighborhood neighborhood,
    00654             EqualityFunctor equal)
    00655 {
    00656     extendedLocalMinima(src.first, src.second, src.third,
    00657                 dest.first, dest.second, marker, neighborhood, equal);
    00658 }
    00659
    00660 template <class SrcIterator, class SrcAccessor,
    00661           class DestIterator, class DestAccessor, class DestValue,
    00662           class Neighborhood>
    00663 inline void
    00664 extendedLocalMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00665             pair<DestIterator, DestAccessor> dest,
    00666             DestValue marker, Neighborhood neighborhood)
    00667 {
    00668     extendedLocalMinima(src.first, src.second, src.third,
    00669                         dest.first, dest.second, marker, neighborhood);
    00670 }
    00671
    00672 template <class SrcIterator, class SrcAccessor,
    00673           class DestIterator, class DestAccessor, class DestValue>
    00674 inline void
    00675 extendedLocalMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00676             pair<DestIterator, DestAccessor> dest,
    00677             DestValue marker)
    00678 {
    00679     extendedLocalMinima(src.first, src.second, src.third,
    00680                         dest.first, dest.second, marker);
    00681 }
    00682
    00683 template <class SrcIterator, class SrcAccessor,
    00684           class DestIterator, class DestAccessor>
    00685 inline void
    00686 extendedLocalMinima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00687             pair<DestIterator, DestAccessor> dest)
    00688 {
    00689     extendedLocalMinima(src.first, src.second, src.third,
    00690                         dest.first, dest.second);
    00691 }
    00692
    00693 /********************************************************/
    00694 /*                                                      */
    00695 /*                 extendedLocalMaxima                  */
    00696 /*                                                      */
    00697 /********************************************************/
    00698
    00699 /** \brief Find local maximal regions in an image.
    00700
    00701     This function finds regions of uniform pixel value
    00702     whose neighboring regions are all have smaller values
    00703     (maximal plateaus of arbitrary size). By default, the pixels
    00704     in a plateau have exactly identical values. By passing an <tt>EqualityFunctor</tt>
    00705     with tolerance, one can allow for plateaus that are not quite constant
    00706     (this is often necessary with float pixel values). Pass
    00707     \ref vigra::EightNeighborCode or \ref vigra::FourNeighborCode
    00708     to determine the neighborhood where pixel values are compared.
    00709
    00710
    00711     Maximal regions are
    00712     marked in the destination image with the given marker value
    00713     (default is 1), all other destination pixels remain unchanged.
    00714     <TT>SrcAccessor::value_type</TT> must be equality-comparable and
    00715     less-comparable.
    00716     A pixel or region touching the image border will never be marked as maximum or
    00717     maximal plateau.
    00718     The function uses accessors.
    00719
    00720     <b> Declarations:</b>
    00721
    00722     pass arguments explicitly:
    00723     \code
    00724     namespace vigra {
    00725         template <class SrcIterator, class SrcAccessor,
    00726                   class DestIterator, class DestAccessor,
    00727                   class DestValue = DestAccessor::value_type,
    00728                   class Neighborhood = EightNeighborCode,
    00729                   class EqualityFunctor = std::equal_to<typename SrcAssessor::value_type> >
    00730         void
    00731         extendedLocalMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00732                             DestIterator dul, DestAccessor da,
    00733                             DestValue marker = NumericTraits<DestValue>::one(),
    00734                             Neighborhood neighborhood = EightNeighborCode(),
    00735                             EqualityFunctor equal = EqualityFunctor())
    00736     }
    00737     \endcode
    00738
    00739     use argument objects in conjunction with \ref ArgumentObjectFactories :
    00740     \code
    00741     namespace vigra {
    00742         template <class SrcIterator, class SrcAccessor,
    00743                   class DestIterator, class DestAccessor,
    00744                   class DestValue = DestAccessor::value_type,
    00745                   class Neighborhood = EightNeighborCode,
    00746                   class EqualityFunctor = std::equal_to<typename SrcAssessor::value_type> >
    00747         void
    00748         extendedLocalMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00749                             pair<DestIterator, DestAccessor> dest,
    00750                             DestValue marker = NumericTraits<DestValue>::one(),
    00751                             Neighborhood neighborhood = EightNeighborCode(),
    00752                             EqualityFunctor equal = EqualityFunctor())
    00753     }
    00754     \endcode
    00755
    00756     <b> Usage:</b>
    00757
    00758         <b>\#include</b> <<a href="localminmax_8hxx-source.html">vigra/localminmax.hxx</a>><br>
    00759     Namespace: vigra
    00760
    00761     \code
    00762
    00763     // optional: define an equality functor
    00764     template <class T>
    00765     struct EqualWithToleranceFunctor
    00766     {
    00767         EqualWithToleranceFunctor(T tolerance)
    00768         : t(tolerance)
    00769         {}
    00770
    00771         bool operator()(T l, T r) const
    00772         {
    00773             return vigra::abs(l-r) <= t;
    00774         }
    00775
    00776         T t;
    00777     };
    00778
    00779     vigra::BImage src(w,h), maxima(w,h);
    00780
    00781     // init destiniation image
    00782     maxima.init(0);
    00783
    00784     vigra::extendedLocalMaxima(srcImageRange(src), destImage(maxima));
    00785
    00786     // allow plateaus with tolerance
    00787     maxima.init(0);
    00788     vigra::extendedLocalMaxima(srcImageRange(src), destImage(maxima), 1.0,
    00789                                EqualWithToleranceFunctor<unsigned char>(1));
    00790     \endcode
    00791
    00792     <b> Required Interface:</b>
    00793
    00794     \code
    00795     SrcImageIterator src_upperleft, src_lowerright;
    00796     DestImageIterator dest_upperleft;
    00797
    00798     SrcAccessor src_accessor;
    00799     DestAccessor dest_accessor;
    00800
    00801     SrcAccessor::value_type u = src_accessor(src_upperleft);
    00802
    00803     EqualityFunctor equal;
    00804     u == u
    00805     equal(u, u);
    00806     u < u
    00807
    00808     DestValue marker;
    00809     dest_accessor.set(marker, dest_upperleft);
    00810     \endcode
    00811
    00812 */
    00813 doxygen_overloaded_function(template <...> void extendedLocalMaxima)
    00814
    00815 template <class SrcIterator, class SrcAccessor,
    00816           class DestIterator, class DestAccessor, class DestValue,
    00817           class Neighborhood, class EqualityFunctor>
    00818 inline void
    00819 extendedLocalMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00820             DestIterator dul, DestAccessor da, DestValue marker,
    00821             Neighborhood neighborhood, EqualityFunctor equal)
    00822 {
    00823     typedef typename SrcAccessor::value_type SrcType;
    00824
    00825     detail::extendedLocalMinMax(sul, slr, sa, dul, da,
    00826                                 marker, neighborhood,
    00827                                 std::greater<SrcType>(), equal);
    00828 }
    00829
    00830 template <class SrcIterator, class SrcAccessor,
    00831           class DestIterator, class DestAccessor, class DestValue,
    00832           class Neighborhood>
    00833 inline void
    00834 extendedLocalMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00835             DestIterator dul, DestAccessor da, DestValue marker,
    00836             Neighborhood neighborhood)
    00837 {
    00838     typedef typename SrcAccessor::value_type SrcType;
    00839
    00840     extendedLocalMaxima(sul, slr, sa, dul, da,
    00841                         marker, neighborhood, std::equal_to<SrcType>());
    00842 }
    00843
    00844 template <class SrcIterator, class SrcAccessor,
    00845           class DestIterator, class DestAccessor, class DestValue>
    00846 inline void
    00847 extendedLocalMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00848             DestIterator dul, DestAccessor da, DestValue marker)
    00849 {
    00850     typedef typename SrcAccessor::value_type SrcType;
    00851
    00852     extendedLocalMaxima(sul, slr, sa, dul, da,
    00853                         marker, EightNeighborCode());
    00854 }
    00855
    00856 template <class SrcIterator, class SrcAccessor,
    00857           class DestIterator, class DestAccessor>
    00858 inline void
    00859 extendedLocalMaxima(SrcIterator sul, SrcIterator slr, SrcAccessor sa,
    00860             DestIterator dul, DestAccessor da)
    00861 {
    00862     extendedLocalMaxima(sul, slr, sa, dul, da,
    00863                 NumericTraits<typename DestAccessor::value_type>::one());
    00864 }
    00865
    00866 template <class SrcIterator, class SrcAccessor,
    00867           class DestIterator, class DestAccessor, class DestValue,
    00868           class Neighborhood, class EqualityFunctor>
    00869 inline void
    00870 extendedLocalMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00871             pair<DestIterator, DestAccessor> dest,
    00872             DestValue marker, Neighborhood neighborhood,
    00873             EqualityFunctor equal)
    00874 {
    00875     extendedLocalMaxima(src.first, src.second, src.third,
    00876                 dest.first, dest.second, marker, neighborhood, equal);
    00877 }
    00878
    00879 template <class SrcIterator, class SrcAccessor,
    00880           class DestIterator, class DestAccessor, class DestValue,
    00881           class Neighborhood>
    00882 inline void
    00883 extendedLocalMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00884             pair<DestIterator, DestAccessor> dest,
    00885             DestValue marker, Neighborhood neighborhood)
    00886 {
    00887     extendedLocalMaxima(src.first, src.second, src.third,
    00888                         dest.first, dest.second, marker, neighborhood);
    00889 }
    00890
    00891 template <class SrcIterator, class SrcAccessor,
    00892           class DestIterator, class DestAccessor, class DestValue>
    00893 inline void
    00894 extendedLocalMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00895             pair<DestIterator, DestAccessor> dest,
    00896             DestValue marker)
    00897 {
    00898     extendedLocalMaxima(src.first, src.second, src.third,
    00899                         dest.first, dest.second, marker);
    00900 }
    00901
    00902 template <class SrcIterator, class SrcAccessor,
    00903           class DestIterator, class DestAccessor>
    00904 inline void
    00905 extendedLocalMaxima(triple<SrcIterator, SrcIterator, SrcAccessor> src,
    00906             pair<DestIterator, DestAccessor> dest)
    00907 {
    00908     extendedLocalMaxima(src.first, src.second, src.third,
    00909                         dest.first, dest.second);
    00910 }
    00911
    00912 //@}
    00913
    00914 } // namespace vigra
    00915
    00916 #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.7.1 (3 Dec 2010)