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

| vigra/copyimage.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_COPYIMAGE_HXX
    00025 #define VIGRA_COPYIMAGE_HXX
    00026
    00027 #include "vigra/utilities.hxx"
    00028
    00029 namespace vigra {
    00030
    00031 /** \addtogroup CopyAlgo Algorithms to Copy Images
    00032     Copy images or regions
    00033 */
    00034 //@{
    00035
    00036 /********************************************************/
    00037 /*                                                      */
    00038 /*                       copyLine                       */
    00039 /*                                                      */
    00040 /********************************************************/
    00041
    00042 template <class SrcIterator, class SrcAccessor,
    00043           class DestIterator, class DestAccessor>
    00044 void
    00045 copyLine(SrcIterator s,
    00046          SrcIterator send, SrcAccessor src,
    00047          DestIterator d, DestAccessor dest)
    00048 {
    00049     for(; s != send; ++s, ++d)
    00050         dest.set(src(s), d);
    00051 }
    00052
    00053 template <class SrcIterator, class SrcAccessor,
    00054           class MaskIterator, class MaskAccessor,
    00055           class DestIterator, class DestAccessor>
    00056 void
    00057 copyLineIf(SrcIterator s,
    00058            SrcIterator send, SrcAccessor src,
    00059            MaskIterator m, MaskAccessor mask,
    00060            DestIterator d, DestAccessor dest)
    00061 {
    00062     for(; s != send; ++s, ++d, ++m)
    00063         if(mask(m))
    00064             dest.set(src(s), d);
    00065 }
    00066
    00067 /********************************************************/
    00068 /*                                                      */
    00069 /*                        copyImage                     */
    00070 /*                                                      */
    00071 /********************************************************/
    00072
    00073 /** \brief Copy source image into destination image.
    00074
    00075     If necessary, type conversion takes place.
    00076     The function uses accessors to access the pixel data.
    00077
    00078     <b> Declarations:</b>
    00079
    00080     pass arguments explicitly:
    00081     \code
    00082     namespace vigra {
    00083         template <class SrcImageIterator, class SrcAccessor,
    00084               class DestImageIterator, class DestAccessor>
    00085         void
    00086         copyImage(SrcImageIterator src_upperleft,
    00087               SrcImageIterator src_lowerright, SrcAccessor sa,
    00088               DestImageIterator dest_upperleft, DestAccessor da)
    00089     }
    00090     \endcode
    00091
    00092
    00093     use argument objects in conjunction with \ref ArgumentObjectFactories:
    00094     \code
    00095     namespace vigra {
    00096         template <class SrcImageIterator, class SrcAccessor,
    00097               class DestImageIterator, class DestAccessor>
    00098         void
    00099         copyImage(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00100               pair<DestImageIterator, DestAccessor> dest)
    00101     }
    00102     \endcode
    00103
    00104     <b> Usage:</b>
    00105
    00106         <b>\#include</b> "<a href="copyimage_8hxx-source.html">vigra/copyimage.hxx</a>"<br>
    00107         Namespace: vigra
    00108
    00109     \code
    00110     vigra::copyImage(srcImageRange(src), destImage(dest));
    00111
    00112     \endcode
    00113
    00114     <b> Required Interface:</b>
    00115
    00116     \code
    00117     SrcImageIterator src_upperleft, src_lowerright;
    00118     DestImageIterator      dest_upperleft;
    00119     SrcImageIterator::row_iterator sx = src_upperleft.rowIterator();
    00120     DestImageIterator::row_iterator dx = dest_upperleft.rowIterator();
    00121
    00122     SrcAccessor src_accessor;
    00123     DestAccessor dest_accessor;
    00124
    00125     dest_accessor.set(src_accessor(sx), dx);
    00126
    00127     \endcode
    00128
    00129 */
    00130 template <class SrcImageIterator, class SrcAccessor,
    00131           class DestImageIterator, class DestAccessor>
    00132 void
    00133 copyImage(SrcImageIterator src_upperleft,
    00134           SrcImageIterator src_lowerright, SrcAccessor sa,
    00135           DestImageIterator dest_upperleft, DestAccessor da)
    00136 {
    00137     int w = src_lowerright.x - src_upperleft.x;
    00138
    00139     for(; src_upperleft.y<src_lowerright.y; ++src_upperleft.y, ++dest_upperleft.y)
    00140     {
    00141         copyLine(src_upperleft.rowIterator(),
    00142                  src_upperleft.rowIterator() + w, sa,
    00143                  dest_upperleft.rowIterator(), da);
    00144     }
    00145 }
    00146
    00147 template <class SrcImageIterator, class SrcAccessor,
    00148           class DestImageIterator, class DestAccessor>
    00149 inline
    00150 void
    00151 copyImage(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00152       pair<DestImageIterator, DestAccessor> dest)
    00153 {
    00154     copyImage(src.first, src.second, src.third,
    00155                    dest.first, dest.second);
    00156 }
    00157
    00158 /********************************************************/
    00159 /*                                                      */
    00160 /*                       copyImageIf                    */
    00161 /*                                                      */
    00162 /********************************************************/
    00163
    00164 /** \brief Copy source ROI into destination image.
    00165
    00166     Pixel values are copied whenever the return value of the mask's
    00167     accessor is not zero.
    00168     If necessary, type conversion takes place.
    00169     The function uses accessors to access the pixel data.
    00170
    00171     <b> Declarations:</b>
    00172
    00173     pass arguments explicitly:
    00174     \code
    00175     namespace vigra {
    00176         template <class SrcImageIterator, class SrcAccessor,
    00177               class MaskImageIterator, class MaskAccessor,
    00178               class DestImageIterator, clas DestAccessor>
    00179         void
    00180         copyImageIf(SrcImageIterator src_upperleft,
    00181             SrcImageIterator src_lowerright, SrcAccessor sa,
    00182             MaskImageIterator mask_upperleft, MaskAccessor ma,
    00183             DestImageIterator dest_upperleft, DestAccessor da)
    00184     }
    00185     \endcode
    00186
    00187
    00188     use argument objects in conjunction with \ref ArgumentObjectFactories:
    00189     \code
    00190     namespace vigra {
    00191         template <class SrcImageIterator, class SrcAccessor,
    00192               class MaskImageIterator, class MaskAccessor,
    00193               class DestImageIterator, clas DestAccessor>
    00194         void
    00195         copyImageIf(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00196             pair<MaskImageIterator, MaskAccessor> mask,
    00197             pair<DestImageIterator, DestAccessor> dest)
    00198     }
    00199     \endcode
    00200
    00201     <b> Usage:</b>
    00202
    00203         <b>\#include</b> "<a href="copyimage_8hxx-source.html">vigra/copyimage.hxx</a>"<br>
    00204         Namespace: vigra
    00205
    00206     \code
    00207     vigra::copyImageIf(srcImageRange(src), maskImage(mask), destImage(dest));
    00208
    00209     \endcode
    00210
    00211     <b> Required Interface:</b>
    00212
    00213     \code
    00214     SrcImageIterator src_upperleft, src_lowerright;
    00215     DestImageIterator dest_upperleft;
    00216     MaskImageIterator mask_upperleft;
    00217     SrcImageIterator::row_iterator sx = src_upperleft.rowIterator();
    00218     MaskImageIterator::row_iterator mx = mask_upperleft.rowIterator();
    00219     DestImageIterator::row_iterator dx = dest_upperleft.rowIterator();
    00220
    00221     SrcAccessor src_accessor;
    00222     DestAccessor dest_accessor;
    00223     MaskAccessor mask_accessor;
    00224     Functor functor;
    00225
    00226     if(mask_accessor(mx))
    00227         dest_accessor.set(src_accessor(sx), dx);
    00228
    00229     \endcode
    00230
    00231 */
    00232 template <class SrcImageIterator, class SrcAccessor,
    00233           class MaskImageIterator, class MaskAccessor,
    00234           class DestImageIterator, class DestAccessor>
    00235 void
    00236 copyImageIf(SrcImageIterator src_upperleft,
    00237             SrcImageIterator src_lowerright, SrcAccessor sa,
    00238             MaskImageIterator mask_upperleft, MaskAccessor ma,
    00239         DestImageIterator dest_upperleft, DestAccessor da)
    00240 {
    00241     int w = src_lowerright.x - src_upperleft.x;
    00242
    00243     for(; src_upperleft.y<src_lowerright.y;
    00244              ++src_upperleft.y, ++mask_upperleft.y, ++dest_upperleft.y)
    00245     {
    00246         copyLineIf(src_upperleft.rowIterator(),
    00247                    src_upperleft.rowIterator() + w, sa,
    00248                    mask_upperleft.rowIterator(), ma,
    00249                    dest_upperleft.rowIterator(), da);
    00250     }
    00251 }
    00252
    00253 template <class SrcImageIterator, class SrcAccessor,
    00254           class MaskImageIterator, class MaskAccessor,
    00255           class DestImageIterator, class DestAccessor>
    00256 inline
    00257 void
    00258 copyImageIf(triple<SrcImageIterator, SrcImageIterator, SrcAccessor> src,
    00259         pair<MaskImageIterator, MaskAccessor> mask,
    00260         pair<DestImageIterator, DestAccessor> dest)
    00261 {
    00262     copyImageIf(src.first, src.second, src.third,
    00263                 mask.first, mask.second,
    00264         dest.first, dest.second);
    00265 }
    00266
    00267 //@}
    00268
    00269 } // namespace vigra
    00270
    00271 #endif // VIGRA_COPYIMAGE_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)