Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages | Examples

vetDigitalFilter.h

00001 
00023 #ifndef __VETLIB_VETDIGITALFILTER_H__
00024  #define __VETLIB_VETDIGITALFILTER_H__
00025 
00026  #include "../vetDefs.h"
00027  #include "../vetFilter.h"
00028 
00029  #include "../vetFrameT.h"
00030  #include "../vetFrameYUV420.h"
00031  #include "../vetFrameRGB24.h"
00032 
00033  #include "../math/vetMatrix.h"
00034 
00035  #include "../math/vetDFMatrix.h"
00036 
00037 
00038 
00039 class vetDigitalFilterParameters : public vetFilterParameters
00040 {
00041         public:
00042 
00043 //              enum RUNMODE{ DO_NOTHING, SOLARIZE, POSTERIZE, CLAMP, INVERT, EXTRACTBITPLANE };
00044 
00045         protected:
00046 
00047                 vetDFMatrix* currentKernel;
00048                 bool clampNegative;
00049 
00050 
00051                 friend class vetDigitalFilter;
00052 
00053 
00054         public:
00055 
00056                 vetDigitalFilterParameters();
00057                 ~vetDigitalFilterParameters() {}
00058 
00059                 void reset();
00060 
00061                 void setCurrentKernel(vetDFMatrix* data);
00062                 void setClampNegative(bool value = true);
00063 
00064                 bool isClampNegativeEnabled() { return clampNegative; };
00065                 vetDFMatrix* getCurrentKernel() { return currentKernel; };
00066 
00067                 VETRESULT saveToStreamXML(FILE *fp);
00068                 VETRESULT loadFromStreamXML(FILE *fp);
00069 
00070 };
00071 
00072 
00073 
00074 
00075 class vetDigitalFilter :        public vetFilter
00076  {
00077 
00078         protected:
00079 
00080                 vetDigitalFilterParameters* myParams;
00081 
00082         public:
00083 
00084 
00089                 vetDigitalFilter(vetDigitalFilterParameters* initParams = NULL);
00090 
00094                 ~vetDigitalFilter();
00095 
00105                 VETRESULT setParameters(vetDigitalFilterParameters* initParams);
00106 
00112                 vetDigitalFilterParameters& getParameters() { return *myParams; };
00113 
00114 
00124                 VETRESULT setFilterParameters (vetFilterParameters* initParams)
00125                  {
00126                         if (initParams == NULL)
00127                                 return setParameters(NULL);
00128                         else
00129                                 return setParameters(static_cast<vetDigitalFilterParameters*>(initParams));
00130                  };
00131 
00132 
00133 
00139                 vetFilterParameters* getFilterParameters ()
00140                  {
00141                         if (myParams == NULL)
00142                                 return NULL;
00143                         else
00144                                 return static_cast<vetFilterParameters*>(myParams);
00145                  };
00146 
00147 
00153                 VETRESULT reset();
00154 
00155 
00156                 VETRESULT setDefaultKernel(int index);
00157 
00158 
00159                 // necessaria conversione di tipo per quelli definiti dall'utente !!
00160 
00161                 template <class T, class S>
00162                 static int doProcessing(vetFrameT<T> &source, vetFrameT<S> &dest, vetDFMatrix& kernel)
00163                  {
00164                         if (&source == NULL || &dest == NULL || &kernel == NULL)
00165                                 return VETRET_PARAM_ERR;
00166 
00167                         signed long numb;
00168                         unsigned int src_w = source.width;
00169 
00170                         if (kernel.getDim() == 3)
00171                          {
00172                                 for(unsigned int x=0; x < src_w; x++)
00173                                    for(unsigned int y=0; y < source.height; y++)
00174                                         {
00175                                                 if ( x && y && (x != src_w-1) && (y != source.height-1)) //3x3 matrix!
00176                                                  {
00177                                                  numb = (long) (        source.data[(y-1) * src_w + (x-1)] * kernel[0] +
00178                                                                                         source.data[(y-1) * src_w +  x   ] * kernel[1] +
00179                                                                                         source.data[(y-1) * src_w + (x+1)] * kernel[2] +
00180                                                                                         source.data[ y    * src_w + (x-1)] * kernel[3] +
00181                                                                                         source.data[ y    * src_w +  x   ] * kernel[4] +
00182                                                                                         source.data[ y    * src_w + (x+1)] * kernel[5] +
00183                                                                                         source.data[(y+1) * src_w + (x-1)] * kernel[6] +
00184                                                                                         source.data[(y+1) * src_w +  x   ] * kernel[7] +
00185                                                                                         source.data[(y+1) * src_w + (x+1)] * kernel[8]  );
00186 
00187                                                  if ( numb )
00188                                                         numb /= (long)kernel[9];//normalization
00189 
00190                                                 dest.data[y * src_w + x] = (S)numb;
00191 
00192                                                  }
00193                                                 else
00194                                                         dest.data[y * src_w + x] = (S)source.data[y * src_w + x];
00195                                    }
00196                          }
00197                         else if (kernel.getDim() == 5)
00198                          {
00199                                 for(unsigned int x=0; x < src_w; x++)
00200                                    for(unsigned int y=0; y < source.height; y++)
00201                                         {
00202                                                 if ( (x-2) && (y-2) && (x != src_w-2) && (y != source.height-2)) //5x5 matrix!
00203                                                  {
00204                                                  numb = (long) (
00205                                                                                         source.data[(y-2) * src_w + (x-2)] * kernel[0] +
00206                                                                                         source.data[(y-2) * src_w + (x-1)] * kernel[1] +
00207                                                                                         source.data[(y-2) * src_w +  x   ] * kernel[2] +
00208                                                                                         source.data[(y-2) * src_w + (x+1)] * kernel[3] +
00209                                                                                         source.data[(y-2) * src_w + (x+2)] * kernel[4] +
00210                                                                                         source.data[(y-1) * src_w + (x-2)] * kernel[5] +
00211                                                                                         source.data[(y-1) * src_w + (x-1)] * kernel[6] +
00212                                                                                         source.data[(y-1) * src_w +  x   ] * kernel[7] +
00213                                                                                         source.data[(y-1) * src_w + (x+1)] * kernel[8] +
00214                                                                                         source.data[(y-1) * src_w + (x+2)] * kernel[9] +
00215                                                                                         source.data[ y    * src_w + (x-2)] * kernel[10] +
00216                                                                                         source.data[ y    * src_w + (x-1)] * kernel[11] +
00217                                                                                         source.data[ y    * src_w +  x   ] * kernel[12] +
00218                                                                                         source.data[ y    * src_w + (x+1)] * kernel[13] +
00219                                                                                         source.data[ y    * src_w + (x+2)] * kernel[14] +
00220                                                                                         source.data[(y+1) * src_w + (x-2)] * kernel[15] +
00221                                                                                         source.data[(y+1) * src_w + (x-1)] * kernel[16] +
00222                                                                                         source.data[(y+1) * src_w +  x   ] * kernel[17] +
00223                                                                                         source.data[(y+1) * src_w + (x+1)] * kernel[18] +
00224                                                                                         source.data[(y+1) * src_w + (x+2)] * kernel[19] +
00225                                                                                         source.data[(y+2) * src_w + (x-2)] * kernel[20] +
00226                                                                                         source.data[(y+2) * src_w + (x-1)] * kernel[21] +
00227                                                                                         source.data[(y+2) * src_w +  x   ] * kernel[22] +
00228                                                                                         source.data[(y+2) * src_w + (x+1)] * kernel[23] +
00229                                                                                         source.data[(y+2) * src_w + (x+2)] * kernel[24] );
00230 
00231                                                  if ( numb )
00232                                                         numb /= (long)kernel[25];//normalization
00233 
00234                                                 dest.data[y * src_w + x] = (S)numb;
00235 
00236                                                  }
00237                                                 else
00238                                                         dest.data[y * src_w + x] = (S)source.data[y * src_w + x];
00239                                    }
00240 
00241                          }
00242                         else if (kernel.getDim() == 7)
00243                          {
00244                                 for(unsigned int x=0; x < src_w; x++)
00245                                    for(unsigned int y=0; y < source.height; y++)
00246                                         {
00247                                                 if ( (x-3) && (y-3) && (x != src_w-3) && (y != source.height-3)) //7x7 matrix!
00248                                                  {
00249                                                  numb = (long) (
00250                                                                                         source.data[(y-3) * src_w + (x-3)] * kernel[0] +
00251                                                                                         source.data[(y-3) * src_w + (x-2)] * kernel[1] +
00252                                                                                         source.data[(y-3) * src_w + (x-1)] * kernel[2] +
00253                                                                                         source.data[(y-3) * src_w +  x   ] * kernel[3] +
00254                                                                                         source.data[(y-3) * src_w + (x+1)] * kernel[4] +
00255                                                                                         source.data[(y-3) * src_w + (x+2)] * kernel[5] +
00256                                                                                         source.data[(y-3) * src_w + (x+3)] * kernel[6] +
00257                                                                                         source.data[(y-2) * src_w + (x-3)] * kernel[7] +
00258                                                                                         source.data[(y-2) * src_w + (x-2)] * kernel[8] +
00259                                                                                         source.data[(y-2) * src_w + (x-1)] * kernel[9] +
00260                                                                                         source.data[(y-2) * src_w +  x   ] * kernel[10] +
00261                                                                                         source.data[(y-2) * src_w + (x+1)] * kernel[11] +
00262                                                                                         source.data[(y-2) * src_w + (x+2)] * kernel[12] +
00263                                                                                         source.data[(y-2) * src_w + (x+3)] * kernel[13] +
00264                                                                                         source.data[(y-1) * src_w + (x-3)] * kernel[14] +
00265                                                                                         source.data[(y-1) * src_w + (x-2)] * kernel[15] +
00266                                                                                         source.data[(y-1) * src_w + (x-1)] * kernel[16] +
00267                                                                                         source.data[(y-1) * src_w +  x   ] * kernel[17] +
00268                                                                                         source.data[(y-1) * src_w + (x+1)] * kernel[18] +
00269                                                                                         source.data[(y-1) * src_w + (x+2)] * kernel[19] +
00270                                                                                         source.data[(y-1) * src_w + (x+3)] * kernel[20] +
00271                                                                                         source.data[ y    * src_w + (x-3)] * kernel[21] +
00272                                                                                         source.data[ y    * src_w + (x-2)] * kernel[22] +
00273                                                                                         source.data[ y    * src_w + (x-1)] * kernel[23] +
00274                                                                                          source.data[ y    * src_w +  x   ] * kernel[24] +
00275                                                                                         source.data[ y    * src_w + (x+1)] * kernel[25] +
00276                                                                                         source.data[ y    * src_w + (x+2)] * kernel[26] +
00277                                                                                         source.data[ y    * src_w + (x+3)] * kernel[27] +
00278                                                                                         source.data[(y+1) * src_w + (x-3)] * kernel[28] +
00279                                                                                         source.data[(y+1) * src_w + (x-2)] * kernel[29] +
00280                                                                                         source.data[(y+1) * src_w + (x-1)] * kernel[30] +
00281                                                                                         source.data[(y+1) * src_w +  x   ] * kernel[31] +
00282                                                                                         source.data[(y+1) * src_w + (x+1)] * kernel[32] +
00283                                                                                         source.data[(y+1) * src_w + (x+2)] * kernel[33] +
00284                                                                                         source.data[(y+1) * src_w + (x+3)] * kernel[34] +
00285                                                                                         source.data[(y+2) * src_w + (x-3)] * kernel[35] +
00286                                                                                         source.data[(y+2) * src_w + (x-2)] * kernel[36] +
00287                                                                                         source.data[(y+2) * src_w + (x-1)] * kernel[37] +
00288                                                                                         source.data[(y+2) * src_w +  x   ] * kernel[38] +
00289                                                                                         source.data[(y+2) * src_w + (x+1)] * kernel[39] +
00290                                                                                         source.data[(y+2) * src_w + (x+2)] * kernel[40] +
00291                                                                                         source.data[(y+2) * src_w + (x+3)] * kernel[41] +
00292                                                                                         source.data[(y+3) * src_w + (x-3)] * kernel[42] +
00293                                                                                         source.data[(y+3) * src_w + (x-2)] * kernel[43] +
00294                                                                                         source.data[(y+3) * src_w + (x-1)] * kernel[44] +
00295                                                                                         source.data[(y+3) * src_w +  x   ] * kernel[45] +
00296                                                                                         source.data[(y+3) * src_w + (x+1)] * kernel[46] +
00297                                                                                         source.data[(y+3) * src_w + (x+2)] * kernel[47] +
00298                                                                                         source.data[(y+3) * src_w + (x+3)] * kernel[48] );
00299 
00300                                                  if ( numb )
00301                                                         numb /= (long)kernel[49];//normalization
00302 
00303                                                 dest.data[y * src_w + x] = (S)numb;
00304 
00305                                                  }
00306                                                 else
00307                                                         dest.data[y * src_w + x] = (S)source.data[y * src_w + x];
00308                                    }
00309 
00310                          }
00311                         else
00312                                 return VETRET_NOT_IMPLEMENTED;
00313 
00314                    return VETRET_OK;
00315                  }
00316 
00317 
00318                 static int doProcessing(vetFrameRGB24& source, vetFrameRGB24& dest, vetDFMatrix& kernel, bool clamp = true);
00319                 static int doProcessing(vetFrameYUV420& source, vetFrameYUV420& dest, vetDFMatrix& kernel, bool clamp = true);
00320                 static int doProcessing(vetFrameT<unsigned char>& source, vetFrameT<unsigned char>& dest, vetDFMatrix& kernel, bool clamp = true);
00321 
00322 
00323                 static int doRotateKernel(vetDFMatrix& kernel);
00324 
00325 
00326 
00327 
00328                 VETRESULT importFrom(vetFrameYUV420& img);
00329                 VETRESULT importFrom(vetFrameRGB24& img);
00330                 VETRESULT importFrom(vetFrameT<unsigned char>& img);
00331 
00332 
00333 
00334 
00335 };
00336 
00337 
00338 
00339 #endif //__VETLIB_VETDIGITALFILTER_H__
00340 

Generated on Tue Jan 24 11:58:59 2006 for VETLib by  doxygen 1.4.4