Jerome Piovano

Research in Medical Imaging and Computer Vision

2D_Gaussian.C

Gaussian Region Segmentation of a 2D Image

00001 #include <Segmentation.h>
00002 #include <SegmentationModule/RegularizationModule.h>
00003 #include <SegmentationModule/GaussianRegionModule.h>
00004 #include <SegmentationModule/BalloonModule.h>
00005 
00008 int main(int argc, char* argv[])
00009 {       
00010         using namespace Images;
00011         using namespace levelset;
00012         using namespace segmentation;
00013 
00014 #if 1 // 2D
00015 
00016         // image to segment 
00017 
00018         BaseImage<2, float> image;
00019         std::ifstream f("image/head3.inr");
00020         f >> format("inrimage") >> image;
00021         Globals::normalize(image, 0.0f, 250.0f);
00022 
00023 /*
00024         // binary circle
00025         const Dimension nx = 300; 
00026         const Dimension ny = 300;
00027         const Dimension dims[] = {nx, ny};
00028         Shape<2> shape(dims);
00029         BaseImage<2,float> image(shape);    // image of size nx*ny
00030 
00031         image = 0.0;
00032 
00033         int radius = 100;
00034         int cx = 150;
00035         int cy = 150;
00036 
00037         for (BaseImage<2, float>::iterator<domain> ind=image.begin() ; ind!=image.end() ; ++ind){
00038                 if(sqrt( (double) Maths::sqr(ind(1) - cx) +  Maths::sqr( ind(2) - cy)) < radius)
00039                         image(ind) = 0;
00040                 else image(ind) =  255 ;
00041         }
00042 */
00043 
00044         // initialization of the segmentations objects
00045         FastMarchingInitializer<2,float> init;                               // Fast Marching Initializer
00046         LevelSet<2,float>                phi(image.shape(), (double) 20.0);  // Level Set of band thickness = 2
00047         Segmentation<2,float>            segm(&phi, &init, &image);          // Segmentation
00048 
00049         // initalization of the level set
00050         BaseImage<2,float> im_init;
00051         std::ifstream f1("multi_variance/head3/var/phi_000498.inr");
00052         f1 >> format("inrimage") >> im_init;
00053         phi.init_image(im_init, init, true);
00054         // phi.init_small_spheres(10, 25, init);    // parameters : radius, windows
00055 
00056         // initialization of the modules
00057         RegularizationModule<2,float>        regul(1.f);           // parameters : weight
00058         GaussianRegionModule<2,float,float>  gauss(&image, 1.f);   // parameters : image, weight
00059 
00060         //note : the variance is useful for the normalization of the gaussian module (speed bounded between -1 and 1)
00061         //       if no variance, one has to reduce the weight of the gaussian module.
00062         gauss.use_variance(true);
00063         gauss.set_data_term(image);
00064 
00065         segm.add_module(regul);
00066         segm.add_module(gauss); 
00067  
00068         // launch the segmentation
00069         Segmentation<2,float>::RGBPixel neg(215,152,0); 
00070         Segmentation<2,float>::RGBPixel pos(255,252,0); 
00071 
00072         timeval _time;
00073         Globals::initChrono(_time);
00074 
00075         std::ostringstream name;
00076         name.str("");  
00077         name << "mkdir CVPR/";
00078         system (name.str().c_str()); 
00079         name.str("");  
00080         name << "mkdir CVPR/gaussian_cortex";
00081         system (name.str().c_str());
00082         name.str("");  
00083         name << "CVPR/gaussian_cortex/multivar";
00084 
00085         segm.segment(1000, name.str().c_str(), neg, pos);
00086 
00087         Globals::printChrono("\n        => Gaussian : ", _time);
00088         Globals::initChrono(_time); 
00089 
00090         std::cout << "OK" << std::endl;
00091 
00092         return 0;
00093 
00094 #endif
00095 
00096 #if 0 //3D
00097 
00098         // image to segment
00099         BaseImage<3, unsigned char> image;
00100         std::ifstream f("image/brain.inr");
00101         f >> format("inrimage") >> image;
00102 
00103         std::cout << image.shape() << std::endl;
00104 
00105         // initialization of the segmentations objects
00106         FastMarchingInitializer<3,float> init;                               // Fast Marching Initializer
00107         LevelSet<3,float>                phi(image.shape(), (double) 2.0);   // Level Set 
00108         Segmentation<3,unsigned char>    segm(&phi, &init, &image);          // Segmentation object
00109 
00110         phi.init_small_spheres(10, 25, init);    // parameters : radius, windows
00111 
00112         RegularizationModule<3,float>                regul(0.75f);                     // parameters : weight
00113         GaussianRegionModule<3,float,unsigned char>  gaussian( &image, 0.75f, true);   // parameters : image, weight, smooth
00114 
00115         segm.add_module(regul);
00116         segm.add_module(gaussian);
00117  
00118         // launch the segmentation
00119         Segmentation<3,float>::RGBPixel neg(215,152,0);
00120         Segmentation<3,float>::RGBPixel pos(255,252,0);
00121 
00122         timeval _time;
00123         Globals::initChrono(_time); 
00124 
00125          segm.segment(1000, "result_3D/brain_gaussian/gaussian_", neg, pos); 
00126 
00127         Globals::printChrono("\n        => Gaussian : ", _time); 
00128         Globals::initChrono(_time); 
00129 
00130         std::cout << "OK" << std::endl;
00131 
00132         return 0;
00133 #endif
00134 
00135 }

For further information, please contact Jerome Piovano - Last update 2008-02-08