LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiMedianFilter.h

00001 /*
00002  * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 /*----------------------------------------------------------------
00024  * project ....: LTI Digital Image/Signal Processing Library
00025  * file .......: ltiMedianFilter.h
00026  * authors ....: Guy Wafo Moudhe
00027  * organization: LTI, RWTH Aachen
00028  * creation ...: 16.3.2001
00029  * revisions ..: $Id: ltiMedianFilter.h,v 1.12 2006/02/08 11:27:55 ltilib Exp $
00030  */
00031 
00032 #ifndef _LTI_MEDIAN_FILTER_H_
00033 #define _LTI_MEDIAN_FILTER_H_
00034 
00035 #include "ltiFilter.h"
00036 #include "ltiImage.h"
00037 #include "ltiVector.h"
00038 #include "ltiQuickMedian.h"
00039 
00040 namespace lti {
00041 
00042   /**
00043    * This class implements the median filter.
00044    * The median filter is a non-linear filter.
00045    * It takes the median value (see lti::quickMedian) of a n*n kernel.
00046    *
00047    * The algorithm used for lti::channel uses the straightforward method, and
00048    * is not as fast as the histogram-based method used for lti::channel8.
00049    */
00050   class medianFilter : public filter {
00051   public:
00052     /**
00053      * the parameters for the class medianFilter
00054      */
00055     class parameters : public filter::parameters {
00056     public:
00057       /**
00058        * default constructor
00059        */
00060       parameters();
00061 
00062       /**
00063        * copy constructor
00064        * @param other the parameters object to be copied
00065        */
00066       parameters(const parameters& other);
00067 
00068       /**
00069        * destructor
00070        */
00071       ~parameters();
00072 
00073       /**
00074        * returns name of this type
00075        */
00076       const char* getTypeName() const;
00077 
00078       /**
00079        * copy the contents of a parameters object
00080        * @param other the parameters object to be copied
00081        * @return a reference to this parameters object
00082        */
00083       parameters& copy(const parameters& other);
00084 
00085       /**
00086        * copy the contents of a parameters object
00087        * @param other the parameters object to be copied
00088        * @return a reference to this parameters object
00089        */
00090       parameters& operator=(const parameters& other);
00091 
00092       /**
00093        * returns a pointer to a clone of the parameters
00094        */
00095       virtual functor::parameters* clone() const;
00096 
00097       /**
00098        * write the parameters in the given ioHandler
00099        * @param handler the ioHandler to be used
00100        * @param complete if true (the default) the enclosing begin/end will
00101        *        be also written, otherwise only the data block will be written.
00102        * @return true if write was successful
00103        */
00104       virtual bool write(ioHandler& handler,const bool complete=true) const;
00105 
00106       /**
00107        * write the parameters in the given ioHandler
00108        * @param handler the ioHandler to be used
00109        * @param complete if true (the default) the enclosing begin/end will
00110        *        be also written, otherwise only the data block will be written.
00111        * @return true if write was successful
00112        */
00113       virtual bool read(ioHandler& handler,const bool complete=true);
00114 
00115 #     ifdef _LTI_MSC_6
00116       /**
00117        * this function is required by MSVC only, as a workaround for a
00118        * very awful bug, which exists since MSVC V.4.0, and still by
00119        * V.6.0 with all bugfixes (so called "service packs") remains
00120        * there...  This method is also public due to another bug, so please
00121        * NEVER EVER call this method directly: use read() instead
00122        */
00123       bool readMS(ioHandler& handler,const bool complete=true);
00124 
00125       /**
00126        * this function is required by MSVC only, as a workaround for a
00127        * very awful bug, which exists since MSVC V.4.0, and still by
00128        * V.6.0 with all bugfixes (so called "service packs") remains
00129        * there...  This method is also public due to another bug, so please
00130        * NEVER EVER call this method directly: use write() instead
00131        */
00132       bool writeMS(ioHandler& handler,const bool complete=true) const;
00133 #     endif
00134 
00135       // ------------------------------------------------
00136       // the parameters
00137       // ------------------------------------------------
00138 
00139       //TODO: comment the parameters of your functor
00140       // If you add more parameters manually, do not forget to do following:
00141       // 1. indicate in the default constructor the default values
00142       // 2. make sure that the copy member also copy your new parameters
00143       // 3. make sure that the read and write members also read and
00144       //    write your parameters
00145 
00146 
00147       /**
00148        * size of the kernel to be used (default 3, which means a 3x3 kernel);
00149        */
00150       int kernelSize;
00151 
00152     };
00153 
00154     /**
00155      * default constructor
00156      */
00157     medianFilter();
00158 
00159     /**
00160      * default constructor
00161      */
00162     medianFilter(const parameters& par);
00163 
00164     /**
00165      * copy constructor
00166      * @param other the object to be copied
00167      */
00168     medianFilter(const medianFilter& other);
00169 
00170     /**
00171      * destructor
00172      */
00173     virtual ~medianFilter();
00174 
00175     /**
00176      * returns the name of this type ("medianFilter")
00177      */
00178     virtual const char* getTypeName() const;
00179 
00180     /**
00181      * operates on the given %parameter.
00182      * @param srcdest channel with the source data.  The result
00183      *                 will be left here too.
00184      * @return true if successful, false otherwise.
00185      */
00186     bool apply(channel& srcdest) const;
00187 
00188     /**
00189      * operates on the given %parameter.
00190      * @param srcdest channel8 with the source data.  The result
00191      *                 will be left here too.
00192      * @return true if successful, false otherwise.
00193      */
00194     bool apply(channel8& srcdest) const;
00195 
00196     /**
00197      * operates on a copy of the given %parameters.
00198      * @param src channel with the source data.
00199      * @param dest channel where the result will be left.
00200      * @return true if successful, false otherwise.
00201      */
00202     bool apply(const channel& src,channel& dest) const;
00203 
00204     /**
00205      * operates on a copy of the given %parameters.
00206      * @param src channel8 with the source data.
00207      * @param dest channel8 where the result will be left.
00208      * @return true if successful, false otherwise.
00209      */
00210     bool apply(const channel8& src,channel8& dest) const;
00211 
00212     /**
00213      * copy data of "other" functor.
00214      * @param other the functor to be copied
00215      * @return a reference to this functor object
00216      */
00217     medianFilter& copy(const medianFilter& other);
00218 
00219     /**
00220      * returns a pointer to a clone of this functor.
00221      */
00222     virtual functor* clone() const;
00223 
00224     /**
00225      * returns used parameters
00226      */
00227     const parameters& getParameters() const;
00228 
00229     /**
00230      * shortcut for resizing the kernel.  Following code using the shortcut
00231      *
00232      * \code
00233      * medianFilter theMedFilter;
00234      * theMedFilter.setKernelSize(5);
00235      * \endcode
00236      *
00237      * is equivalent to
00238      *
00239      * \code
00240      * medianFilter theMedFilter;
00241      *
00242      * medianFilter::parameters param(theMedFilter.getParameters);
00243      * param.kernelSize = 5;
00244      * theMedFilter.setParameters(param);
00245      * \endcode
00246      */
00247     void setKernelSize(const int& newKernelSize);
00248   protected:
00249 
00250     /**
00251      * runs inside the image src
00252      */
00253     void histogramMethodMiddle(const channel8& src,
00254                                channel8& dest,
00255                                ivector& histogram,
00256                                int& lessThanMedian,
00257                                const int& row,
00258                                int& col,
00259                                ubyte& median,
00260                                const int& sizeOfKernel) const;
00261 
00262     /**
00263      * applies the histogramMethod for the type boundary Zero
00264      */
00265     bool histogramMethodZero(const channel8& src,
00266                               channel8& dest,
00267                               const int& sizeOfKernel) const;
00268 
00269     /**
00270      * applies the histogramMethod for the type boundary Constant
00271      */
00272     bool histogramMethodConstant(const channel8& src,
00273                                  channel8& dest,
00274                                  const int& sizeOfKernel) const;
00275 
00276     /**
00277      * applies the histogramMethod for the type boundary Periodic
00278      */
00279     bool histogramMethodPeriodic(const channel8& src,
00280                                  channel8& dest,
00281                                  const int& sizeOfKernel) const;
00282 
00283     /**
00284      * applies the histogramMethod for the type boundary Mirror
00285      */
00286     bool histogramMethodMirror(const channel8& src,
00287                                channel8& dest,
00288                                const int& sizeOfKernel) const;
00289 
00290     /**
00291      * applies the histogramMethod for the type boundary NoBoundary
00292      */
00293     bool histogramMethodNoBoundary(const channel8& src,
00294                                    channel8& dest,
00295                                    const int& sizeOfKernel) const;
00296 
00297     /**
00298      * the histogramMethod apply the median filter to a matrix
00299      * of type channel8.In difference with the function realMedian,
00300      * histogramMethod use a histogram,which avoid to sort each time
00301      * the kernel
00302      */
00303     bool histogramMethod(const channel8& src, channel8& dest) const;
00304 
00305     /**
00306      * realMedian is a template function which apply the median filter
00307      * to a matrix of type T.
00308      * The median filter does not depend on
00309      * the type of the elements of a matrix.  The implementation must
00310      * be here due to a bug of the MSVC++
00311      */
00312     template <class T>
00313     bool realMedian(const matrix<T>& src, matrix<T>& dest) const {
00314 
00315       if (src.empty()) {
00316         dest.clear();
00317         return true;
00318       }
00319 
00320       const parameters& param = getParameters();
00321 
00322       if (param.kernelSize <= 1) {
00323         dest.copy(src);
00324         return true;
00325       }
00326 
00327       // Median Filter
00328       int i,j,row,col,z;
00329       int k=0;
00330 
00331       // the method can only be applied with a even value of kernelSize
00332       const int sizeOfKernel = param.kernelSize+((param.kernelSize%2 == 0) ? 1:0);
00333       const int limit = sizeOfKernel/2;
00334 
00335       lti::quickMedian<T> quickmedia;
00336       vector<T> vect(sizeOfKernel*sizeOfKernel,T(0));
00337 
00338       //resizes the destination matrix
00339       dest.resize(src.rows(),src.columns(),T(0),false,false);
00340 
00341       const int lastCol = src.lastColumn()-limit;
00342       const int lastRow = src.lastRow()-limit;
00343 
00344       //runs through the src's columns
00345       for(row=limit;row<=lastRow;++row) {
00346         const int r=row+limit;
00347         for(col=limit;col<=lastCol;++col) {  //runs through the src's rows
00348           const int c=col+limit;
00349           for(i=row-limit;i<=r;++i) { //runs through the rows within the kernel
00350             //runs through the columns within the kernel
00351             for(j=col-limit;j<=c;++j) {
00352               //gives the value from the kernel to the vector
00353               vect.at(k)=src[i][j];
00354               k++;
00355             }
00356           }
00357           //fills the destination matrix
00358           dest.at(row,col)=quickmedia.apply(vect);
00359           k=0;
00360         }
00361       }
00362 
00363       // boundary conditions
00364 
00365       switch (param.boundaryType) {
00366       case lti::Zero:
00367         for(row=limit;row<=lastRow;++row) {  //runs the left columns
00368           z = sizeOfKernel*(sizeOfKernel-limit-1);
00369           vect.fill(T(0),0,z-1);
00370           const int r=row+limit;
00371           for(col=0;col<limit;++col) {
00372             const int c=col+limit;
00373             z=sizeOfKernel*(sizeOfKernel-limit-1-col);
00374             for(i=row-limit;i<=r;++i) {
00375               for(j=0;j<=c;++j){
00376                 vect.at(z)=src[i][j];
00377                 z++;
00378               }
00379             }
00380             dest.at(row,col)=quickmedia.apply(vect);
00381           }
00382           //runs the right columns
00383           for(col=lastCol+1;col<=src.lastColumn();++col) {
00384             z=sizeOfKernel*(sizeOfKernel-(limit+1)-(src.lastColumn()-col));
00385             vect.fill(T(0),0,z-1);
00386             for(i=row-limit;i<=r;++i) {
00387               for(j=col-limit;j<=src.lastColumn();++j) {
00388                 vect.at(z)=src[i][j];
00389                 z++;
00390               }
00391             }
00392             dest.at(row,col)=quickmedia.apply(vect);
00393           }
00394         }
00395         for(row=0;row<limit;++row) { //runs the rows at the top
00396           z=sizeOfKernel*(sizeOfKernel-limit-1);
00397           vect.fill(T(0),0,z-1);
00398           const int r=row+limit;
00399           // runs the rows at the top in the middle
00400           for(col=limit;col<=lastCol;++col) {
00401             const int c=col+limit;
00402             z=sizeOfKernel*(sizeOfKernel-(limit+1)-row);
00403 
00404             for(i=0;i<=r;++i) {
00405 
00406               for(j=col-limit;j<=c;++j) {
00407 
00408                 vect.at(z)=src[i][j];
00409                 z++;
00410               }
00411             }
00412             dest.at(row,col)=quickmedia.apply(vect);
00413           }
00414 
00415           // runs at the top,left in the corner
00416           for(col=0;col<limit;++col) {
00417             const int c=col+limit;
00418             z=sizeOfKernel*sizeOfKernel-(limit+1)*(limit+1+row+col)-col*row;
00419             vect.fill(T(0),0,z-1);
00420             for(i=0;i<=r;++i) {
00421 
00422               for(j=0;j<=c;++j) {
00423 
00424                 vect.at(z)=src[i][j];
00425                 z++;
00426               }
00427             }
00428             dest.at(row,col)=quickmedia.apply(vect);
00429           }
00430           //runs at the top,right in the corner
00431           for(col=lastCol+1;col<=src.lastColumn();++col) {
00432 
00433             z=sizeOfKernel*sizeOfKernel-(limit+1)*
00434               (limit+1+row+(src.lastColumn()-col))-row*(src.lastColumn()-col);
00435             vect.fill(T(0),0,z-1);
00436             for(i=0;i<=r;++i) {
00437               for(j=col-limit;j<=src.lastColumn();++j){
00438                 vect.at(z)=src[i][j];
00439                 z++;
00440               }
00441             }
00442             dest.at(row,col)=quickmedia.apply(vect);
00443           }
00444         }
00445         //runs the rows at the bottom
00446         for(row=lastRow+1;row<=src.lastRow();++row) {
00447           z=sizeOfKernel*(sizeOfKernel-limit-1);
00448           vect.fill(T(0),0,z-1);
00449           //runs the rows at the bottom in the middle
00450           for(col=limit;col<=lastCol;++col) {
00451             const int c=col+limit;
00452             z=sizeOfKernel*(sizeOfKernel-(limit+1)-(src.lastRow()-row));
00453             vect.fill(T(0),0,z-1);
00454             for(i=row-limit;i<=src.lastRow();++i) {
00455               for(j=col-limit;j<=c;++j) {
00456                 vect.at(z)=src[i][j];
00457                 z++;
00458               }
00459             }
00460             dest.at(row,col)=quickmedia.apply(vect);
00461           }
00462           //runs at the bottom,left in the corner
00463           for(col=0;col<limit;++col) {
00464             const int c=col+limit;
00465             z=sizeOfKernel*sizeOfKernel-(limit+1)*
00466               (limit+1+(src.lastRow()-row)+col)-col*(src.lastRow()-row);
00467             vect.fill(T(0),0,z-1);
00468             for(i=row-limit;i<=src.lastRow();++i) {
00469 
00470               for(j=0;j<=c;++j) {
00471 
00472                 vect.at(z)=src[i][j];
00473                 z++;
00474               }
00475             }
00476             dest.at(row,col)=quickmedia.apply(vect);
00477           }
00478           //runs at the bottom,right in the corner
00479           for(col=lastCol+1;col<=src.lastColumn();++col) {
00480 
00481             z=sizeOfKernel*sizeOfKernel-(limit+1)*
00482               (limit+1+(src.lastRow()-row)+(src.lastColumn()-col))-
00483               (src.lastRow()-row)*(src.lastColumn()-col);
00484             vect.fill(T(0),0,z-1);
00485             for (i=row-limit;i<=src.lastRow();++i) {
00486               for (j=col-limit;j<=src.lastColumn();++j) {
00487                 vect.at(z)=src[i][j];
00488                 z++;
00489               }
00490             }
00491             dest.at(row,col)=quickmedia.apply(vect);
00492           }
00493         }
00494         break;
00495       case lti::Mirror:
00496         for(row=limit;row<=lastRow;++row) {   //runs the columns left
00497           const int r=row+limit;
00498           for(col=0;col<limit;++col) {
00499             const int c=col+limit;
00500             z=0;
00501             for(i=row-limit;i<=r;++i) {
00502 
00503               for(j=col-limit;j<=c;++j) {
00504 
00505                 if(j<0) {
00506                   vect.at(z)=src[i][-j-1];
00507                   z++;
00508                 }
00509                 else{// if(j>=0){
00510                   vect.at(z)=src[i][j];
00511                   z++;
00512                 }
00513               }
00514             }
00515             dest.at(row,col)=quickmedia.apply(vect);
00516           }
00517 
00518           for(col=lastCol+1;col<=src.lastColumn();++col) {
00519             //runs the columns right
00520             const int c=col+limit;
00521             z=0;
00522             for(i=row-limit;i<=r;++i) {
00523               for(j=col-limit;j<=c;++j) {
00524                 if(j<=src.lastColumn()) {
00525                   vect.at(z)=src[i][j];
00526                   z++;
00527                 }
00528                 else{// if(j>src.lastColumn()) {
00529                   vect.at(z)=src[i][src.lastColumn()+(src.columns()-j)];
00530                   z++;
00531                 }
00532               }
00533             }
00534             dest.at(row,col)=quickmedia.apply(vect);
00535           }
00536         }
00537         for(row=0;row<limit;++row) {   //runs the rows at the top
00538           const int r=row+limit;
00539           // runs the rows at the top in the middle
00540           for(col=limit;col<=lastCol;++col) {
00541             const int c=col+limit;
00542             z=0;
00543             for(i=row-limit;i<=r;++i) {
00544 
00545               for(j=col-limit;j<=c;++j) {
00546 
00547                 if(i<0) {
00548                   vect.at(z)=src[-i-1][j];
00549                   z++;
00550                 }
00551                 else { //if(i>=0) {
00552                   vect.at(z)=src[i][j];
00553                   z++;
00554                 }
00555               }
00556             }
00557             dest.at(row,col)=quickmedia.apply(vect);
00558           }
00559 
00560           for(col=0;col<limit;++col) {   // runs at the top,left in the corner
00561             const int c=col+limit;
00562             z=0;
00563             for(i=row-limit;i<=r;++i) {
00564 
00565               for(j=col-limit;j<=c;++j) {
00566                 if(i<0 && j<0){
00567                   vect.at(z)=src[-i-1][-j-1];
00568                   z++;
00569                 }
00570                 else if(i>=0 && j<0) {
00571                   vect.at(z)=src[i][-j-1];
00572                   z++;
00573                 }
00574                 else if(i<0 && j>=0) {
00575                   vect.at(z)=src[-i-1][j];
00576                   z++;
00577                 }
00578                 else {   //if(i>=0 && j>=0) {
00579                   vect.at(z)=src[i][j];
00580                   z++;
00581                 }
00582               }
00583             }
00584 
00585             dest.at(row,col)=quickmedia.apply(vect);
00586           }
00587           //runs at the top,right in the corner
00588           for(col=lastCol+1;col<src.columns();++col) {
00589             const int c=col+limit;
00590             z=0;
00591             for(i=row-limit;i<=r;++i) {
00592               for(j=col-limit;j<=c;++j) {
00593                 if(i<0 && j<=src.lastColumn()) {
00594                   vect.at(z)=src[-i-1][j];
00595                   z++;
00596                 }
00597                 else if(i<0 && j>src.lastColumn()) {
00598                   vect.at(z)=src[-i-1][src.lastColumn()+(src.columns()-j)];
00599                   z++;
00600                 }
00601                 else if(i>=0 && j>src.lastColumn()) {
00602                   vect.at(z)=src[i][src.lastColumn()+(src.columns()-j)];
00603                   z++;
00604                 }
00605                 else { //if(i>=0 && j<=src.lastColumn()) {
00606                   vect.at(z)=src[i][j];
00607                   z++;
00608                 }
00609               }
00610             }
00611             dest.at(row,col)=quickmedia.apply(vect);
00612           }
00613         }
00614         //runs the rows at the bottom
00615         for(row=lastRow+1;row<=src.lastRow();++row) {
00616           const int r=row+limit;
00617           //runs the rows at the bottom in the middle
00618           for(col=limit;col<=lastCol;++col) {
00619             const int c=col+limit;
00620             z=0;
00621             for(i=row-limit;i<=r;++i) {
00622               for(j=col-limit;j<=c;++j) {
00623                 if(i<=src.lastRow()) {
00624                   vect.at(z)=src[i][j];
00625                   z++;
00626                 }
00627                 else {// if(i>src.lastRow()) {
00628                   vect.at(z)=src[src.lastRow()+(src.rows()-i)][j];
00629                   z++;
00630                 }
00631               }
00632             }
00633             dest.at(row,col)=quickmedia.apply(vect);
00634           }
00635           for(col=0;col<limit;++col) { //runs at the bottom,left in the corner
00636             const int c=col+limit;
00637             z=0;
00638             for(i=row-limit;i<=r;++i) {
00639               for(j=col-limit;j<=c;++j) {
00640                 if(i<=src.lastRow() && j<0) {
00641                   vect.at(z)=src[i][-j-1];
00642                   z++;
00643                 }
00644                 else if(i<=src.lastRow() && j>=0) {
00645                   vect.at(z)=src[i][j];
00646                   z++;
00647                 }
00648                 else if(i>src.lastRow() && j<0) {
00649                   vect.at(z)=src[src.lastRow()+(src.rows()-i)][-j-1];
00650                   z++;
00651                 }
00652                 else if(i>src.lastRow() && j>=0) {
00653                   vect.at(z)=src[src.lastRow()+(src.rows()-i)][j];
00654                   z++;
00655                 }
00656               }
00657             }
00658             dest.at(row,col)=quickmedia.apply(vect);
00659           }
00660           //runs at the bottom,right in the corner
00661           for(col=lastCol+1;col<src.columns();++col) {
00662             const int c=col+limit;
00663             z=0;
00664             for(i=row-limit;i<=r;++i) {
00665               for(j=col-limit;j<=c;++j) {
00666                 if(i<=src.lastRow() && j<=src.lastColumn()) {
00667                   vect.at(z)=src[i][j];
00668                   z++;
00669                 }
00670                 else if(i<=src.lastRow() && j>src.lastColumn()) {
00671                   vect.at(z)=src[i][src.lastColumn()+(src.columns()-j)];
00672                   z++;
00673                 }
00674                 else if(i>src.lastRow() && j<=src.lastColumn()) {
00675                   vect.at(z)=src[src.lastRow()+(src.rows()-i)][j];
00676                   z++;
00677                 }
00678                 else if(i>src.lastRow() && j>src.lastColumn()) {
00679                   vect.at(z)=src[src.lastRow()+(src.rows()-i)]
00680                     [src.lastColumn()+(src.columns()-j)];
00681                   z++;
00682                 }
00683               }
00684             }
00685             dest.at(row,col)=quickmedia.apply(vect);
00686           }
00687         }
00688         break;
00689       case lti::Periodic:
00690         for(row=limit;row<=lastRow;++row) {          //runs the left columns
00691           const int r=row+limit;
00692           for(col=0;col<limit;++col) {
00693             const int c=col+limit;
00694             z=0;
00695             for(i=row-limit;i<=r;++i) {
00696 
00697               for(j=col-limit;j<=c;++j) {
00698 
00699                 if(j<0) {
00700                   vect.at(z)=src[i][src.columns()+j];
00701                   z++;
00702                 }
00703                 else{// if(j>=0) {
00704                   vect.at(z)=src[i][j];
00705                   z++;
00706                 }
00707               }
00708             }
00709             dest.at(row,col)=quickmedia.apply(vect);
00710           }
00711 
00712           //runs right the columns
00713           for(col=lastCol+1;col<=src.lastColumn();++col) {
00714             const int c=col+limit;
00715             z=0;
00716             for(i=row-limit;i<=r;++i) {
00717               for(j=col-limit;j<=c;++j) {
00718                 if(j<=src.lastColumn()) {
00719                   vect.at(z)=src[i][j];
00720                   z++;
00721                 }
00722                 else{// if(j>src.lastColumn()) {
00723                   vect.at(z)=src[i][j-src.columns()];
00724                   z++;
00725                 }
00726               }
00727             }
00728             dest.at(row,col)=quickmedia.apply(vect);
00729           }
00730         }
00731         for(row=0;row<limit;++row) {                //runs the rows at the top
00732           const int r=row+limit;
00733           // runs the rows at the top in the middle
00734           for(col=limit;col<=lastCol;++col) {
00735             const int c=col+limit;
00736             z=0;
00737             for(i=row-limit;i<=r;++i) {
00738 
00739               for(j=col-limit;j<=c;++j) {
00740 
00741                 if(i<0) {
00742                   vect.at(z)=src[i+src.rows()][j];
00743                   z++;
00744                 }
00745                 else{//if(i>=0) {
00746                   vect.at(z)=src[i][j];
00747                   z++;
00748                 }
00749               }
00750             }
00751             dest.at(row,col)=quickmedia.apply(vect);
00752           }
00753            // runs at the top,left in the corner
00754           for(col=0;col<limit;++col) {
00755             const int c=col+limit;
00756             z=0;
00757             for(i=row-limit;i<=r;++i) {
00758 
00759               for(j=col-limit;j<=c;++j) {
00760                 if(i<0 && j<0) {
00761                   vect.at(z)=src[src.rows()+i][src.columns()+j];
00762                   z++;
00763                 }
00764                 else if(i>=0 && j<0) {
00765                   vect.at(z)=src[i][src.columns()+j];
00766                   z++;
00767                 }
00768                 else if(i<0 && j>=0) {
00769                   vect.at(z)=src[src.rows()+i][j];
00770                   z++;
00771                 }
00772                 else if(i>=0 && j>=0) {
00773                   vect.at(z)=src[i][j];
00774                   z++;
00775                 }
00776               }
00777             }
00778 
00779             dest.at(row,col)=quickmedia.apply(vect);
00780           }
00781           //runs at the top,right in the corner
00782           for(col=lastCol+1;col<src.columns();++col) {
00783             const int c=col+limit;
00784             z=0;
00785             for(i=row-limit;i<=r;++i) {
00786               for(j=col-limit;j<=c;++j) {
00787                 if(i<0 && j<=src.lastColumn()) {
00788                   vect.at(z)=src[src.rows()+i][j];
00789                   z++;
00790                 }
00791                 else if(i<0 && j>src.lastColumn()) {
00792                   vect.at(z)=src[src.rows()+i][j-src.columns()];
00793                   z++;
00794                 }
00795                 else if(i>=0 && j>src.lastColumn()) {
00796                   vect.at(z)=src[i][j-src.columns()];
00797                   z++;
00798                 }
00799                 else {//if(i>=0 && j<=src.lastColumn()) {
00800                   vect.at(z)=src[i][j];
00801                   z++;
00802                 }
00803               }
00804             }
00805             dest.at(row,col)=quickmedia.apply(vect);
00806           }
00807 
00808         }
00809         //runs the rows at the bottom
00810         for(row=lastRow+1;row<=src.lastRow();++row) {
00811           const int r=row+limit;
00812           //runs the rows at the bottom in the middle
00813           for(col=limit;col<=lastCol;++col) {
00814             const int c=col+limit;
00815             z=0;
00816             for(i=row-limit;i<=r;++i) {
00817               for(j=col-limit;j<=c;++j) {
00818                 if(i<=src.lastRow()) {
00819                   vect.at(z)=src[i][j];
00820                   z++;
00821                 }
00822                 else{// if(i>src.lastRow()) {
00823                   vect.at(z)=src[i-src.rows()][j];
00824                   z++;
00825                 }
00826               }
00827             }
00828             dest.at(row,col)=quickmedia.apply(vect);
00829           }
00830           for(col=0;col<limit;++col) {  //runs at the bottom,left in the corner
00831             const int c=col+limit;
00832             z=0;
00833             for(i=row-limit;i<=r;++i) {
00834               for(j=col-limit;j<=c;++j) {
00835                 if(i<=src.lastRow() && j<0) {
00836                   vect.at(z)=src[i][src.columns()+j];
00837                   z++;
00838                 }
00839                 else if(i<=src.lastRow() && j>=0) {
00840                   vect.at(z)=src[i][j];
00841                   z++;
00842                 }
00843                 else if(i>src.lastRow() && j<0) {
00844                   vect.at(z)=src[i-src.rows()][src.columns()+j];
00845                   z++;
00846                 }
00847                 else if(i>src.lastRow() && j>=0) {
00848                   vect.at(z)=src[i-src.rows()][j];
00849                   z++;
00850                 }
00851               }
00852             }
00853             dest.at(row,col)=quickmedia.apply(vect);
00854           }
00855           //runs at the bottom,right in the corner
00856           for(col=lastCol+1;col<src.columns();++col) {
00857             const int c=col+limit;
00858             z=0;
00859             for(i=row-limit;i<=r;++i) {
00860               for(j=col-limit;j<=c;++j) {
00861                 if(i<=src.lastRow() && j<=src.lastColumn()) {
00862                   vect.at(z)=src[i][j];
00863                   z++;
00864                 }
00865                 else if(i<=src.lastRow() && j>src.lastColumn()) {
00866                   vect.at(z)=src[i][j-src.columns()];
00867                   z++;
00868                 }
00869                 else if(i>src.lastRow() && j<=src.lastColumn()) {
00870                   vect.at(z)=src[i-src.rows()][j];
00871                   z++;
00872                 }
00873                 else if(i>src.lastRow() && j>src.lastColumn()) {
00874                   vect.at(z)=src[i-src.rows()][j-src.columns()];
00875                   z++;
00876                 }
00877               }
00878             }
00879             dest.at(row,col)=quickmedia.apply(vect);
00880           }
00881 
00882         }
00883         break;
00884 
00885       case lti::Constant:
00886         for(row=limit;row<=lastRow;++row) {          //runs the left columns
00887           const int r=row+limit;
00888           for(col=0;col<limit;++col) {
00889             const int c=col+limit;
00890             z=0;
00891             for(i=row-limit;i<=r;++i) {
00892 
00893               for(j=col-limit;j<=c;++j) {
00894 
00895                 if(j<0) {
00896                   vect.at(z)=src[i][0];
00897                   z++;
00898                 }
00899                 else{// if(j>=0) {
00900                   vect.at(z)=src[i][j];
00901                   z++;
00902                 }
00903               }
00904             }
00905             dest.at(row,col)=quickmedia.apply(vect);
00906           }
00907 
00908           //runs the right columns
00909           for(col=lastCol+1;col<=src.lastColumn();++col) {
00910             const int c=col+limit;
00911             z=0;
00912             for(i=row-limit;i<=r;++i) {
00913               for(j=col-limit;j<=c;++j) {
00914                 if(j<=src.lastColumn()) {
00915                   vect.at(z)=src[i][j];
00916                   z++;
00917                 }
00918                 else{// if(j>src.lastColumn()) {
00919                   vect.at(z)=src[i][src.lastColumn()];
00920                   z++;
00921                 }
00922               }
00923             }
00924             dest.at(row,col)=quickmedia.apply(vect);
00925           }
00926         }
00927         for(row=0;row<limit;++row) {                //runs the rows at the top
00928           const int r=row+limit;
00929           // runs the rows at the top in the middle
00930           for(col=limit;col<=lastCol;++col) {
00931             const int c=col+limit;
00932             z=0;
00933             for(i=row-limit;i<=r;++i) {
00934 
00935               for(j=col-limit;j<=c;++j) {
00936 
00937                 if(i<0) {
00938                   vect.at(z)=src[0][j];
00939                   z++;
00940                 }
00941                 else{//if(i>=0) {
00942                   vect.at(z)=src[i][j];
00943                   z++;
00944                 }
00945               }
00946             }
00947             dest.at(row,col)=quickmedia.apply(vect);
00948           }
00949           // runs at the top,left in the corner
00950           for(col=0;col<limit;++col) {
00951             const int c=col+limit;
00952             z=0;
00953             for(i=row-limit;i<=r;++i) {
00954 
00955               for(j=col-limit;j<=c;++j) {
00956                 if(i<0 && j<0){
00957                   vect.at(z)=src[0][0];
00958                   z++;
00959                 }
00960                 else if(i>=0 && j<0) {
00961                   vect.at(z)=src[i][0];
00962                   z++;
00963                 }
00964                 else if(i<0 && j>=0) {
00965                   vect.at(z)=src[0][j];
00966                   z++;
00967                 }
00968                 else if(i>=0 && j>=0) {
00969                   vect.at(z)=src[i][j];
00970                   z++;
00971                 }
00972               }
00973             }
00974 
00975             dest.at(row,col)=quickmedia.apply(vect);
00976           }
00977           //runs at the top,right in the corner
00978           for(col=lastCol+1;col<src.columns();++col) {
00979             const int c=col+limit;
00980             z=0;
00981             for(i=row-limit;i<=r;++i) {
00982               for(j=col-limit;j<=c;++j) {
00983                 if(i<0 && j<=src.lastColumn()) {
00984                   vect.at(z)=src[0][j];
00985                   z++;
00986                 }
00987                 else if(i<0 && j>src.lastColumn()) {
00988                   vect.at(z)=src[0][src.lastColumn()];
00989                   z++;
00990                 }
00991                 else if(i>=0 && j>src.lastColumn()) {
00992                   vect.at(z)=src[i][src.lastColumn()];
00993                   z++;
00994                 }
00995                 else {//if(i>=0 && j<=src.lastColumn()) {
00996                   vect.at(z)=src[i][j];
00997                   z++;
00998                 }
00999               }
01000             }
01001             dest.at(row,col)=quickmedia.apply(vect);
01002           }
01003         }
01004         //runs the rows at the bottom
01005         for(row=lastRow+1;row<=src.lastRow();++row) {
01006           const int r=row+limit;
01007           //runs the rows at the bottom in the middle
01008           for(col=limit;col<=lastCol;++col) {
01009             const int c=col+limit;
01010             z=0;
01011             for(i=row-limit;i<=r;++i) {
01012               for(j=col-limit;j<=c;++j) {
01013                 if(i<=src.lastRow()) {
01014                   vect.at(z)=src[i][j];
01015                   z++;
01016                 }
01017                 else{// if(i>src.lastRow()) {
01018                   vect.at(z)=src[src.lastRow()][j];
01019                   z++;
01020                 }
01021               }
01022             }
01023             dest.at(row,col)=quickmedia.apply(vect);
01024           }
01025           //runs at the bottom,left in the corner
01026           for(col=0;col<limit;++col) {
01027             const int c=col+limit;
01028             z=0;
01029             for(i=row-limit;i<=r;++i) {
01030               for(j=col-limit;j<=c;++j) {
01031                 if(i<=src.lastRow() && j<0) {
01032                   vect.at(z)=src[i][0];
01033                   z++;
01034                 }
01035                 else if(i<=src.lastRow() && j>=0) {
01036                   vect.at(z)=src[i][j];
01037                   z++;
01038                 }
01039                 else if(i>src.lastRow() && j<0) {
01040                   vect.at(z)=src[src.lastRow()][0];
01041                   z++;
01042                 }
01043                 else if(i>src.lastRow() && j>=0) {
01044                   vect.at(z)=src[src.lastRow()][j];
01045                   z++;
01046                 }
01047               }
01048             }
01049             dest.at(row,col)=quickmedia.apply(vect);
01050           }
01051           //runs at the bottom,right in the corner
01052           for(col=lastCol+1;col<src.columns();++col) {
01053             const int c=col+limit;
01054             z=0;
01055             for(i=row-limit;i<=r;++i) {
01056               for(j=col-limit;j<=c;++j) {
01057                 if(i<=src.lastRow() && j<=src.lastColumn()) {
01058                   vect.at(z)=src[i][j];
01059                   z++;
01060                 }
01061                 else if(i<=src.lastRow() && j>src.lastColumn()) {
01062                   vect.at(z)=src[i][src.lastColumn()];
01063                   z++;
01064                 }
01065                 else if(i>src.lastRow() && j<=src.lastColumn()) {
01066                   vect.at(z)=src[src.lastRow()][j];
01067                   z++;
01068                 }
01069                 else if(i>src.lastRow() && j>src.lastColumn()) {
01070                   vect.at(z)=src[src.lastRow()][src.lastColumn()];
01071                   z++;
01072                 }
01073               }
01074             }
01075             dest.at(row,col)=quickmedia.apply(vect);
01076           }
01077         }
01078 
01079         break;
01080 
01081       default:
01082         break;
01083 
01084       }
01085 
01086       return true;
01087     };
01088 
01089   };
01090 }
01091 
01092 #endif

Generated on Sat Apr 10 15:25:51 2010 for LTI-Lib by Doxygen 1.6.1