ContrastFilter.cpp

Go to the documentation of this file.
00001 /* Import from Gabor API
00002 
00003 Copyright (c) 2002-3 Adriaan Tijsseling
00004 
00005 
00006                              All Rights Reserved
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program. If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 /*
00023         Description:            Abstract class for contrast filter
00024         Original Author:        Yasunobu Honma
00025         Modifications by:       Adriaan Tijsseling (AGT)
00026 */
00027 
00028 #include "ContrastFilter.h"
00029 
00030 namespace celeste
00031 {
00032 float CONTRAST[9][9] = {
00033   {
00034     -0.00601522f,
00035     -0.00815698f,
00036     -0.00576532f,
00037     -0.000761649f,
00038     0.00105624f,
00039     -0.000761649f,
00040     -0.00576532f,
00041     -0.00815698f,
00042     -0.00601522f
00043   },
00044 
00045   {
00046     -0.00815698f,
00047     -0.00235211f,
00048     0.00300229f,
00049     -0.0157626f,
00050     -0.0304662f,
00051     -0.0157626f,
00052     0.00300229f,
00053     -0.00235211f,
00054     -0.00815698f
00055   },
00056 
00057   {
00058     -0.00576532f,
00059     0.00300229f,
00060     -0.0505102f,
00061     -0.115416f,
00062     -0.115769f,
00063     -0.115416f,
00064     -0.0505102f,
00065     0.00300229f,
00066     -0.00576532f
00067   },
00068 
00069   {
00070     -0.000761649f,
00071     -0.0157626f,
00072     -0.115416f,
00073     0.0361012f,
00074     0.273771f,
00075     0.0361012f,
00076     -0.115416f,
00077     -0.0157626f,
00078     -0.000761649f
00079   },
00080 
00081   {
00082     0.00105624f,
00083     -0.0304662f,
00084     -0.115769f,
00085     0.273771f,
00086     0.719623f,
00087     0.273771f,
00088     -0.115769f,
00089     -0.0304662f,
00090     0.00105624f
00091   },
00092 
00093   {
00094     -0.000761649f,
00095     -0.0157626f,
00096     -0.115416f,
00097     0.0361012f,
00098     0.273771f,
00099     0.0361012f,
00100     -0.115416f,
00101     -0.0157626f,
00102     -0.000761649f
00103   },
00104 
00105   {
00106     -0.00576532f,
00107     0.00300229f,
00108     -0.0505102f,
00109     -0.115416f,
00110     -0.115769f,
00111     -0.115416f,
00112     -0.0505102f,
00113     0.00300229f,
00114     -0.00576532f
00115   },
00116 
00117   {
00118     -0.00815698f,
00119     -0.00235211f,
00120     0.00300229f,
00121     -0.0157626f,
00122     -0.0304662f,
00123     -0.0157626f,
00124     0.00300229f,
00125     -0.00235211f,
00126     -0.00815698f
00127   },
00128 
00129   {
00130     -0.00601522f,
00131     -0.00815698f,
00132     -0.00576532f,
00133     -0.000761649f,
00134     0.00105624f,
00135     -0.000761649f,
00136     -0.00576532f,
00137     -0.00815698f,
00138     -0.00601522f
00139   }};
00140 
00141 // construct class and apply filter
00142 ContrastFilter::ContrastFilter( float **img, int height, int width )
00143 {
00144         mHeight = height-8;
00145         mWidth = width-8;
00146 
00147         mContrast = new float*[mHeight];
00148         for ( int i = 0; i < mHeight; i++ )
00149         {
00150                 mContrast[i] = new float[mWidth];
00151                 for ( int j = 0; j < mWidth; j++ )
00152                         mContrast[i][j] = 0.0;
00153         }
00154 
00155         ApplyFilter( img, height, width );
00156 }
00157 
00158 
00159 // free memory
00160 ContrastFilter::~ContrastFilter()
00161 {
00162         if( mContrast != NULL )
00163         {
00164                 for( int y = 0; y < mHeight; y++ )
00165                         delete[] mContrast[y];
00166                 delete[] mContrast;
00167         }
00168 }
00169 
00170 
00171 // apply filter to image
00172 void ContrastFilter::ApplyFilter( float** img, int height, int width )
00173 {
00174         int     x, y, i, j;//, k, l;
00175         float   tmp;
00176 
00177         for( i = 0; i < height-8; i++ ) 
00178                 for( j = 0; j < width-8; j++ )
00179                 {
00180                         tmp = 0.0;
00181                         for( x = 0; x < 9; x++ )
00182                                 for( y = 0; y < 9; y++)
00183                                         tmp += CONTRAST[x][y] * img[i+x][j+y];
00184                         mContrast[i][j] = tmp;
00185                 }
00186 }
00187 
00188 
00189 // write out contrast data to pgm file
00190 void ContrastFilter::Save( void )
00191 {
00192     PGMImage    pgmI;
00193         char            tmpName[256];
00194         
00195         strcpy( tmpName, mFile );
00196         strcat( tmpName, "-contrast.pgm" );
00197         pgmI.WriteScaled( tmpName, mContrast, mHeight, mWidth );
00198 }
00199 
00200 }; // namespace

Generated on Wed Oct 1 01:25:31 2014 for Hugintrunk by  doxygen 1.3.9.1