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

| vigra/initimage.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.3.2, Jan 27 2005 )                                    */
    00008 /*    You may use, modify, and distribute this software according       */
    00009 /*    to the terms stated in the LICENSE file included in               */
    00010 /*    the VIGRA distribution.                                           */
    00011 /*                                                                      */
    00012 /*    The VIGRA Website is                                              */
    00013 /*        http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/      */
    00014 /*    Please direct questions, bug reports, and contributions to        */
    00015 /*        koethe@informatik.uni-hamburg.de                              */
    00016 /*                                                                      */
    00017 /*  THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY EXPRESS OR          */
    00018 /*  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED      */
    00019 /*  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */
    00020 /*                                                                      */
    00021 /************************************************************************/
    00022
    00023
    00024 #ifndef VIGRA_INITIMAGE_HXX
    00025 #define VIGRA_INITIMAGE_HXX
    00026
    00027 #include "vigra/utilities.hxx"
    00028 #include "vigra/iteratortraits.hxx"
    00029 #include "vigra/functortraits.hxx"
    00030
    00031 namespace vigra {
    00032
    00033 /** \addtogroup InitAlgo Algorithms to Initialize Images
    00034
    00035     Init images or image borders
    00036 */
    00037 //@{
    00038
    00039 /********************************************************/
    00040 /*                                                      */
    00041 /*                       initLine                       */
    00042 /*                                                      */
    00043 /********************************************************/
    00044
    00045 template <class DestIterator, class DestAccessor, class VALUETYPE>
    00046 void
    00047 initLineImpl(DestIterator d, DestIterator dend, DestAccessor dest,
    00048              VALUETYPE v, VigraFalseType)
    00049 {
    00050     for(; d != dend; ++d)
    00051         dest.set(v, d);
    00052 }
    00053
    00054 template <class DestIterator, class DestAccessor, class FUNCTOR>
    00055 void
    00056 initLineImpl(DestIterator d, DestIterator dend, DestAccessor dest,
    00057              FUNCTOR const & f, VigraTrueType)
    00058 {
    00059     for(; d != dend; ++d)
    00060         dest.set(f(), d);
    00061 }
    00062
    00063 template <class DestIterator, class DestAccessor, class VALUETYPE>
    00064 inline void
    00065 initLine(DestIterator d, DestIterator dend, DestAccessor dest,
    00066          VALUETYPE v)
    00067 {
    00068     initLineImpl(d, dend, dest, v, typename FunctorTraits<VALUETYPE>::isInitializer());
    00069 }
    00070
    00071 template <class DestIterator, class DestAccessor, class FUNCTOR>
    00072 inline void
    00073 initLineFunctor(DestIterator d, DestIterator dend, DestAccessor dest,
    00074          FUNCTOR f)
    00075 {
    00076     initLineImpl(d, dend, dest, f, VigraTrueType());
    00077 }
    00078
    00079 template <class DestIterator, class DestAccessor,
    00080           class MaskIterator, class MaskAccessor,
    00081           class VALUETYPE>
    00082 void
    00083 initLineIfImpl(DestIterator d, DestIterator dend, DestAccessor dest,
    00084                MaskIterator m, MaskAccessor mask,
    00085                VALUETYPE v, VigraFalseType)
    00086 {
    00087     for(; d != dend; ++d, ++m)
    00088         if(mask(m))
    00089             dest.set(v, d);
    00090 }
    00091
    00092 template <class DestIterator, class DestAccessor,
    00093           class MaskIterator, class MaskAccessor,
    00094           class FUNCTOR>
    00095 void
    00096 initLineIfImpl(DestIterator d, DestIterator dend, DestAccessor dest,
    00097                MaskIterator m, MaskAccessor mask,
    00098                FUNCTOR const & f, VigraTrueType)
    00099 {
    00100     for(; d != dend; ++d, ++m)
    00101         if(mask(m))
    00102             dest.set(f(), d);
    00103 }
    00104
    00105 template <class DestIterator, class DestAccessor,
    00106           class MaskIterator, class MaskAccessor,
    00107           class VALUETYPE>
    00108 inline void
    00109 initLineIf(DestIterator d, DestIterator dend, DestAccessor dest,
    00110            MaskIterator m, MaskAccessor mask,
    00111            VALUETYPE v)
    00112 {
    00113     initLineIfImpl(d, dend, dest, m, mask, v, typename FunctorTraits<VALUETYPE>::isInitializer());
    00114 }
    00115
    00116 template <class DestIterator, class DestAccessor,
    00117           class MaskIterator, class MaskAccessor,
    00118           class FUNCTOR>
    00119 void
    00120 initLineFunctorIf(DestIterator d, DestIterator dend, DestAccessor dest,
    00121                   MaskIterator m, MaskAccessor mask,
    00122                   FUNCTOR f)
    00123 {
    00124     initLineIfImpl(d, dend, dest, m, mask, f, VigraTrueType());
    00125 }
    00126
    00127 /********************************************************/
    00128 /*                                                      */
    00129 /*                        initImage                     */
    00130 /*                                                      */
    00131 /********************************************************/
    00132
    00133 /** \brief Write a value to every pixel in an image or rectangular ROI.
    00134
    00135     This function can be used to init the image.
    00136     It uses an accessor to access the pixel data.
    00137
    00138     <b> Declarations:</b>
    00139
    00140     pass arguments explicitly:
    00141     \code
    00142     namespace vigra {
    00143         template <class ImageIterator, class Accessor, class VALUETYPE>
    00144         void
    00145         initImage(ImageIterator upperleft, ImageIterator lowerright,
    00146               Accessor a, VALUETYPE v)
    00147     }
    00148     \endcode
    00149
    00150     use argument objects in conjunction with \ref ArgumentObjectFactories:
    00151     \code
    00152     namespace vigra {
    00153         template <class ImageIterator, class Accessor, class VALUETYPE>
    00154         void
    00155         initImage(triple<ImageIterator, ImageIterator, Accessor> img, VALUETYPE v)
    00156     }
    00157     \endcode
    00158
    00159     <b> Usage:</b>
    00160
    00161         <b>\#include</b> "<a href="initimage_8hxx-source.html">vigra/initimage.hxx</a>"<br>
    00162         Namespace: vigra
    00163
    00164     \code
    00165     vigra::BImage img(100, 100);
    00166
    00167     // zero the image
    00168     vigra::initImage(destImageRange(img),
    00169                      vigra::NumericTraits<vigra::BImage::PixelType>::zero());
    00170     \endcode
    00171
    00172     <b> Required Interface:</b>
    00173
    00174     \code
    00175     ImageIterator upperleft, lowerright;
    00176     ImageIterator::row_iterator ix = upperleft.rowIterator();
    00177
    00178     Accessor accessor;
    00179     VALUETYPE v;
    00180
    00181     accessor.set(v, ix);
    00182     \endcode
    00183
    00184 */
    00185 template <class ImageIterator, class Accessor, class VALUETYPE>
    00186 void
    00187 initImage(ImageIterator upperleft, ImageIterator lowerright,
    00188           Accessor a,  VALUETYPE v)
    00189 {
    00190     int w = lowerright.x - upperleft.x;
    00191
    00192     for(; upperleft.y < lowerright.y; ++upperleft.y)
    00193     {
    00194         initLine(upperleft.rowIterator(),
    00195                  upperleft.rowIterator() + w, a, v);
    00196     }
    00197 }
    00198
    00199 template <class ImageIterator, class Accessor, class VALUETYPE>
    00200 inline
    00201 void
    00202 initImage(triple<ImageIterator, ImageIterator, Accessor> img, VALUETYPE v)
    00203 {
    00204     initImage(img.first, img.second, img.third, v);
    00205 }
    00206
    00207 /********************************************************/
    00208 /*                                                      */
    00209 /*                        initImage                     */
    00210 /*                                                      */
    00211 /********************************************************/
    00212
    00213 /** \brief Write the result of a functor call to every pixel in an image or rectangular ROI.
    00214
    00215     This function can be used to init the image by calling the given
    00216     functor for each pixel.
    00217     It uses an accessor to access the pixel data.
    00218
    00219     <b> Declarations:</b>
    00220
    00221     pass arguments explicitly:
    00222     \code
    00223     namespace vigra {
    00224         template <class ImageIterator, class Accessor, class FUNCTOR>
    00225         void
    00226         initImageWithFunctor(ImageIterator upperleft, ImageIterator lowerright,
    00227                   Accessor a,  FUNCTOR f);
    00228     }
    00229     \endcode
    00230
    00231     use argument objects in conjunction with \ref ArgumentObjectFactories:
    00232     \code
    00233     namespace vigra {
    00234         template <class ImageIterator, class Accessor, class FUNCTOR>
    00235         void
    00236         initImageWithFunctor(triple<ImageIterator, ImageIterator, Accessor> img, FUNCTOR f);
    00237     }
    00238     \endcode
    00239
    00240     <b> Usage:</b>
    00241
    00242         <b>\#include</b> "<a href="initimage_8hxx-source.html">vigra/initimage.hxx</a>"<br>
    00243         Namespace: vigra
    00244
    00245     \code
    00246     struct Counter {
    00247         Counter() : count(0) {}
    00248
    00249         int operator()() const { return count++; }
    00250
    00251         mutable int count;
    00252     };
    00253
    00254     vigra::IImage img(100, 100);
    00255
    00256     // write the current count in every pixel
    00257     vigra::initImageWithFunctor(destImageRange(img), Counter());
    00258     \endcode
    00259
    00260     <b> Required Interface:</b>
    00261
    00262     \code
    00263     ImageIterator upperleft, lowerright;
    00264     ImageIterator::row_iterator ix = upperleft.rowIterator();
    00265
    00266     Accessor accessor;
    00267     Functor f;
    00268
    00269     accessor.set(f(), ix);
    00270     \endcode
    00271
    00272 */
    00273 template <class ImageIterator, class Accessor, class FUNCTOR>
    00274 void
    00275 initImageWithFunctor(ImageIterator upperleft, ImageIterator lowerright,
    00276           Accessor a,  FUNCTOR f)
    00277 {
    00278     int w = lowerright.x - upperleft.x;
    00279
    00280     for(; upperleft.y < lowerright.y; ++upperleft.y)
    00281     {
    00282         initLineFunctor(upperleft.rowIterator(),
    00283                  upperleft.rowIterator() + w, a, f);
    00284     }
    00285 }
    00286
    00287 template <class ImageIterator, class Accessor, class FUNCTOR>
    00288 inline
    00289 void
    00290 initImageWithFunctor(triple<ImageIterator, ImageIterator, Accessor> img, FUNCTOR f)
    00291 {
    00292     initImageWithFunctor(img.first, img.second, img.third, f);
    00293 }
    00294
    00295 /********************************************************/
    00296 /*                                                      */
    00297 /*                      initImageIf                     */
    00298 /*                                                      */
    00299 /********************************************************/
    00300
    00301 /** \brief Write value to pixel in the image if mask is true.
    00302
    00303     This function can be used to init a region-of-interest of the image.
    00304     It uses an accessor to access the pixel data.
    00305
    00306     <b> Declarations:</b>
    00307
    00308     pass arguments explicitly:
    00309     \code
    00310     namespace vigra {
    00311         template <class ImageIterator, class Accessor,
    00312               class MaskImageIterator, class MaskAccessor,
    00313               class VALUETYPE>
    00314         void
    00315         initImageIf(ImageIterator upperleft, ImageIterator lowerright, Accessor a,
    00316               MaskImageIterator mask_upperleft, MaskAccessor ma,
    00317               VALUETYPE v)
    00318     }
    00319     \endcode
    00320
    00321     use argument objects in conjunction with \ref ArgumentObjectFactories:
    00322     \code
    00323     namespace vigra {
    00324         template <class ImageIterator, class Accessor,
    00325               class MaskImageIterator, class MaskAccessor,
    00326               class VALUETYPE>
    00327         void
    00328         initImageIf(triple<ImageIterator, ImageIterator, Accessor> img,
    00329             pair<MaskImageIterator, MaskAccessor> mask,
    00330             VALUETYPE v)
    00331     }
    00332     \endcode
    00333
    00334     <b> Usage:</b>
    00335
    00336         <b>\#include</b> "<a href="initimage_8hxx-source.html">vigra/initimage.hxx</a>"<br>
    00337         Namespace: vigra
    00338
    00339     \code
    00340     vigra::BImage img(100, 100);
    00341     vigra::BImage mask(100, 100);
    00342
    00343     // zero the ROI
    00344     vigra::initImageIf(destImageRange(img),
    00345                 maskImage(mask),
    00346                 vigra::NumericTraits<vigra::BImage::PixelType>::zero());
    00347     \endcode
    00348
    00349     <b> Required Interface:</b>
    00350
    00351     \code
    00352     ImageIterator upperleft, lowerright;
    00353     MaskImageIterator mask_upperleft;
    00354     ImageIterator::row_iterator ix = upperleft.rowIterator();
    00355     MaskImageIterator::row_iterator mx = mask_upperleft.rowIterator();
    00356
    00357     Accessor accessor;
    00358     MaskAccessor mask_accessor;
    00359     VALUETYPE v;
    00360
    00361     if(mask_accessor(mx)) accessor.set(v, ix);
    00362     \endcode
    00363
    00364 */
    00365 template <class ImageIterator, class Accessor,
    00366           class MaskImageIterator, class MaskAccessor,
    00367           class VALUETYPE>
    00368 void
    00369 initImageIf(ImageIterator upperleft, ImageIterator lowerright, Accessor a,
    00370           MaskImageIterator mask_upperleft, MaskAccessor ma,
    00371           VALUETYPE v)
    00372 {
    00373     int w = lowerright.x - upperleft.x;
    00374
    00375     for(; upperleft.y < lowerright.y; ++upperleft.y, ++mask_upperleft.y)
    00376     {
    00377         initLineIf(upperleft.rowIterator(),
    00378                    upperleft.rowIterator() + w, a,
    00379                    mask_upperleft.rowIterator(), ma, v);
    00380     }
    00381 }
    00382
    00383 template <class ImageIterator, class Accessor,
    00384           class MaskImageIterator, class MaskAccessor,
    00385           class VALUETYPE>
    00386 inline
    00387 void
    00388 initImageIf(triple<ImageIterator, ImageIterator, Accessor> img,
    00389             pair<MaskImageIterator, MaskAccessor> mask,
    00390             VALUETYPE v)
    00391 {
    00392     initImageIf(img.first, img.second, img.third, mask.first, mask.second, v);
    00393 }
    00394
    00395 /********************************************************/
    00396 /*                                                      */
    00397 /*                    initImageBorder                   */
    00398 /*                                                      */
    00399 /********************************************************/
    00400
    00401 /** \brief Write value to the specified border pixels in the image.
    00402
    00403     A pixel is initialized if its distance to the border
    00404     is at most 'borderwidth'.
    00405     It uses an accessor to access the pixel data.
    00406
    00407     <b> Declarations:</b>
    00408
    00409     pass arguments explicitly:
    00410     \code
    00411     namespace vigra {
    00412         template <class ImageIterator, class Accessor, class VALUETYPE>
    00413         void
    00414         initImageBorder(ImageIterator upperleft, ImageIterator lowerright,
    00415                 Accessor a,  int border_width, VALUETYPE v)
    00416     }
    00417     \endcode
    00418
    00419     use argument objects in conjunction with \ref ArgumentObjectFactories:
    00420     \code
    00421     namespace vigra {
    00422         template <class ImageIterator, class Accessor, class VALUETYPE>
    00423         void
    00424         initImageBorder(triple<ImageIterator, ImageIterator, Accessor> img,
    00425                 int border_width, VALUETYPE v)
    00426     }
    00427     \endcode
    00428
    00429     <b> Usage:</b>
    00430
    00431         <b>\#include</b> "<a href="initimage_8hxx-source.html">vigra/initimage.hxx</a>"<br>
    00432         Namespace: vigra
    00433
    00434     \code
    00435     vigra::BImage img(100, 100);
    00436
    00437     // zero a border of 5 pixel
    00438     vigra::initImageBorder(destImageRange(img),
    00439                     5, vigra::NumericTraits<vigra::BImage::PixelType>::zero());
    00440     \endcode
    00441
    00442     <b> Required Interface:</b>
    00443
    00444     see \ref initImage()
    00445
    00446 */
    00447 template <class ImageIterator, class Accessor, class VALUETYPE>
    00448 inline
    00449 void
    00450 initImageBorder(ImageIterator upperleft, ImageIterator lowerright,
    00451                 Accessor a,  int border_width, VALUETYPE v)
    00452 {
    00453     int w = lowerright.x - upperleft.x;
    00454     int h = lowerright.y - upperleft.y;
    00455
    00456     int hb = (border_width > h) ? h : border_width;
    00457     int wb = (border_width > w) ? w : border_width;
    00458
    00459     initImage(upperleft, upperleft+Diff2D(w,hb), a, v);
    00460     initImage(upperleft, upperleft+Diff2D(wb,h), a, v);
    00461     initImage(upperleft+Diff2D(0,h-hb), lowerright, a, v);
    00462     initImage(upperleft+Diff2D(w-wb,0), lowerright, a, v);
    00463 }
    00464
    00465 template <class ImageIterator, class Accessor, class VALUETYPE>
    00466 inline
    00467 void
    00468 initImageBorder(triple<ImageIterator, ImageIterator, Accessor> img,
    00469                 int border_width, VALUETYPE v)
    00470 {
    00471     initImageBorder(img.first, img.second, img.third, border_width, v);
    00472 }
    00473
    00474 //@}
    00475
    00476
    00477 } // namespace vigra
    00478
    00479 #endif // VIGRA_INITIMAGE_HXX

© Ullrich Köthe (koethe@informatik.uni-hamburg.de) Cognitive Systems Group, University of Hamburg, Germany | html generated using doxygen and Python VIGRA 1.3.2 (27 Jan 2005)