strong_features_tool.h

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <vector>
00003 #include <cmath>
00004 #include <values.h>
00005 #include "image.h"
00006 #include "gauss_tool.h"
00007 #include "matrix_tool.h"
00008 #include "image_funcs.h"
00009 
00010 #ifndef STRONG_FEATURES_TOOL_H
00011 #define STRONG_FEATURES_TOOL_H
00012 
00013 namespace mimas {
00014 class strong_features_tool
00015 {
00016   private:
00017     image<int>        gauss_im;
00018     image<double>        grad_x, grad_y;
00019     gauss_tool<int>      gauss;
00020     int                     wx, wy;
00021     double                  factor; 
00022 
00023   public:
00024     strong_features_tool(void);
00025     ~strong_features_tool(void);
00026     void findFeatures(image<int> &imagein, image<int> &imageout);
00027 
00028  
00029 };
00030 
00031 strong_features_tool::strong_features_tool()
00032 {
00033   wx=15;
00034   wy=15;
00035 
00036   factor=0.01;
00037 }
00038 
00039 strong_features_tool::~strong_features_tool()
00040 {
00041 }
00042 
00043 void strong_features_tool::findFeatures(image<int> &imagein, image<int> &imageout)
00044 {
00045 
00046   matrix_tool u,d,vt;
00047   image<double> eigimage;
00048   vector<double> eigval;
00049   vector<int> coordx, coordy;
00050 
00051 
00052   eigimage.init(imagein.getWidth(),imagein.getHeight());
00053 
00054   imageout.init(imagein.getWidth(),imagein.getHeight());
00055 
00056   //(1) first gauss the image
00057   gauss.filter( imagein, gauss_im );
00058 
00059   //(2) get the horizontal and vertical gradients
00060   //    grad filter is a simple static function
00061   //    might be an idea to switch the gauss image to a double first?
00062   //filter<int>::gradX( gauss_im, grad_x );
00063   //filter<int>::gradY( gauss_im, grad_y );
00064   gradSobel(gauss_im, grad_x, _dir_x);
00065   gradSobel(gauss_im, grad_y, _dir_y);
00066   //normaliseIt(grad_x, 0.0, 255.0);
00067   //normaliseIt(grad_y, 0.0, 255.0);
00068 
00069   //to save memory, get rid of gauss_im
00070   gauss_im.clear();
00071 
00072 
00073   int centx=wx/2;
00074   int centy=wy/2;
00075 
00076   double smalleig;
00077 
00078   for (int j=centy; j<imagein.getHeight()-centy; j++)
00079     for ( int i=centx; i<imagein.getWidth()-centx; i++)
00080     {
00081       matrix_tool C;
00082 
00083       C.zeroes(2,2);
00084 
00085       for (int y=-centy; y<centy; y++)
00086         for (int x=-centx; x<centx; x++)
00087         {
00088           C(0,0)=C(0,0)+fabs((double)(grad_x.pixel(x+i,y+j)*grad_x.pixel(x+i,y+j)));
00089           C(0,1)=C(0,1)+fabs((double)(grad_x.pixel(x+i,y+j)*grad_y.pixel(x+i,y+j)));
00090           C(1,0)=C(0,1);
00091           C(1,1)=C(1,1)+fabs((double)(grad_y.pixel(x+i,y+j)*grad_y.pixel(x+i,y+j)));
00092         }
00093 
00094       // compute the smalles eigenvalue
00095       smalleig=( C(0,0) + C(1,1) - sqrt( ( C(0,0)-C(1,1) ) * ( C(0,0)-C(1,1) ) + 4*C(0,1)*C(1,0) ))/2.0;
00096       
00097       eigimage.setPixel(i,j,smalleig);
00098       eigval.push_back(smalleig);
00099     }
00100 
00101   //normaliseIt(eigimage, 0.0, 255.0);
00102   //eigimage.display();
00103 
00104   sort(eigval.begin(),eigval.end());
00105 
00106   for (int i=0; i<eigval.size(); i++)
00107      cout << eigval[i] << std::endl;
00108 
00109 
00110   bool notlocalmaximum;
00111   for (int j=centy; j<imagein.getHeight()-centy; j++)
00112     for ( int i=centx; i<imagein.getWidth()-centx; i++)
00113     {
00114       notlocalmaximum=false;
00115       
00116       for (int y=-centy; y<centy; y++)
00117       {
00118         for (int x=-centx; x<centx; x++)
00119         {
00120           if ( x==0 && y==0) continue;
00121           
00122           if ( eigimage.pixel(i,j) >= eigimage.pixel(i+x,j+y) )
00123           {
00124                  eigimage.pixel(i+x,j+y)=0.0;
00125             notlocalmaximum=true;
00126             //break;
00127           }
00128         }
00129         //if (notlocalmaximum==true) break;
00130       }
00131     }
00132   
00133   
00134   double  cutoffval=eigval[eigval.size()-(int)((double)eigval.size()*factor)];
00135 
00136   for (int j=0; j<eigimage.getHeight(); j++)
00137     for ( int i=0; i<eigimage.getWidth(); i++)
00138         imageout.pixel(i,j) = eigimage.pixel(i,j)>=cutoffval ? 255 : 0;
00139   
00140 
00141 
00142 
00143 }
00144 }
00145 #endif

[GNU/Linux] [Qt] [Mesa] [STL] [Lapack] [Boost] [Magick++] [Xalan-C and Xerces-C] [doxygen] [graphviz] [FFTW] [popt] [xine] [Gnuplot] [gnu-arch] [gcc] [gstreamer] [autoconf/automake/make] [freshmeat.net] [opensource.org] [sourceforge.net] [MMVL]
mimas 2.1 - Copyright Mon Oct 30 11:31:17 2006, Bala Amavasai, Stuart Meikle, Arul Selvan, Fabio Caparrelli, Jan Wedekind, Manuel Boissenin, ...