Main Page   Class Hierarchy   Compound List   File List   Compound Members  

filter.cpp

00001 /*=============================================================================
00002         File: filter.cpp
00003      Purpose:
00004     Revision: $Id: filter.cpp,v 1.2 2002/05/13 21:07:45 philosophil Exp $
00005   Created by: Philippe Lavoie          (18 February 1999)
00006  Modified by: 
00007 
00008  Copyright notice:
00009           Copyright (C) 1996-1997 Philippe Lavoie
00010  
00011           This library is free software; you can redistribute it and/or
00012           modify it under the terms of the GNU Library General Public
00013           License as published by the Free Software Foundation; either
00014           version 2 of the License, or (at your option) any later version.
00015  
00016           This library is distributed in the hope that it will be useful,
00017           but WITHOUT ANY WARRANTY; without even the implied warranty of
00018           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019           Library General Public License for more details.
00020  
00021           You should have received a copy of the GNU Library General Public
00022           License along with this library; if not, write to the Free
00023           Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024 =============================================================================*/
00025 
00026 #ifndef FILTER_SOURCES
00027 #define FILTER_SOURCES
00028 
00029 #include "filter.h"
00030 #include "vector.h"
00031 
00034 namespace PLib {
00035 
00038   namespace Filter{
00039 
00040     template <class T>
00041       void median(const Basic2DArray<T>& a, Basic2DArray<T>& b){
00042       
00043       Vector<T> med(9) ; 
00044       b.resize(a.rows(),a.cols());
00045       for(int i=a.rows()-2;i>0;--i)
00046         for(int j=a.cols()-2;j>0;--j){
00047           int n = -1 ; 
00048           for(int k=-1;k<2;++k)
00049             for(int l=-1;l<2;++l){
00050               med[++n] = a(i+k,j+l) ;
00051             }
00052           med.qSort();
00053           b(i,j) = med[4] ; 
00054         }
00055       // have to handle the borders
00056       for(int i=0;i<a.rows();++i){
00057         b(i,0) = b(i,1) ; 
00058         b(i,b.cols()-1) = b(i,b.cols()-2) ;
00059       }
00060       for(int i=0;i<a.cols();++i){
00061         b(0,i) = b(1,i) ; 
00062         b(b.rows()-1,i) = b(b.rows()-2,i) ;
00063       }
00064       // and handling the corners
00065       b(0,0) = b(1,1) ; 
00066       b(0,b.cols()-1) = b(1,b.cols()-2) ; 
00067       b(b.rows()-1,0) = b(b.rows()-2,1) ; 
00068       b(b.rows()-1,b.cols()-1) = b(b.rows()-2,b.cols()-2) ;           
00069     }
00070     
00071     template <class T>
00072       void medianT(const Basic2DArray<T>& a, Basic2DArray<T>& b, T value, int op){
00073       
00074       Vector<T> med(9) ; 
00075       b.resize(a.rows(),a.cols());
00076 
00077       if(op>0){
00078 
00079         for(int i=a.rows()-2;i>0;--i)
00080           for(int j=a.cols()-2;j>0;--j){
00081             int n = -1 ; 
00082             for(int k=-1;k<2;++k)
00083               for(int l=-1;l<2;++l){
00084                 med[++n] = a(i+k,j+l) ;
00085               }
00086             med.qSort();
00087             --n ;
00088             while(n>0 && med[n]>=value){
00089               --n ;
00090             }
00091             b(i,j) = med[n/2] ; 
00092           }
00093       }
00094       else{
00095 
00096         for(int i=a.rows()-2;i>0;--i)
00097           for(int j=a.cols()-2;j>0;--j){
00098             int n = -1 ; 
00099             for(int k=-1;k<2;++k)
00100               for(int l=-1;l<2;++l){
00101                 med[++n] = a(i+k,j+l) ;
00102               }
00103             med.qSort();
00104             n=0;
00105             while(n>0 && med[n]<=value){
00106               ++n ;
00107             }
00108             b(i,j) = med[n+(9-n)/2] ; 
00109           }
00110       }
00111       // have to handle the borders
00112       for(int i=0;i<a.rows();++i){
00113         b(i,0) = b(i,1) ; 
00114         b(i,b.cols()-1) = b(i,b.cols()-2) ;
00115       }
00116       for(int i=0;i<a.cols();++i){
00117         b(0,i) = b(1,i) ; 
00118         b(b.rows()-1,i) = b(b.rows()-2,i) ;
00119       }
00120       // and handling the corners
00121       b(0,0) = b(1,1) ; 
00122       b(0,b.cols()-1) = b(1,b.cols()-2) ; 
00123       b(b.rows()-1,0) = b(b.rows()-2,1) ; 
00124       b(b.rows()-1,b.cols()-1) = b(b.rows()-2,b.cols()-2) ;           
00125     }
00126     
00127   }
00128 
00129 }
00130 
00131 #endif

Generated on Tue Jun 24 13:26:55 2003 for NURBS++ by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002