Index: lsm3D_compile.sh
===================================================================
--- lsm3D_compile.sh	(revision 24)
+++ lsm3D_compile.sh	(revision 25)
@@ -5,8 +5,8 @@
 
 cd src
 echo '------------------------------------'
-echo 'compiling lsm_detect_contour...'
-g++ -o $bin_directory/lsm_detect_contour lsm_detect_contour.cpp $compiling_options
+echo 'compiling lsm_contour...'
+g++ -o $bin_directory/lsm_contour lsm_contour.cpp $compiling_options
 
 echo 'compiling lsm_cells...'
 g++ -o $bin_directory/lsm_cells lsm_cells.cpp $compiling_options -lX11 -fopenmp
Index: src/lsm_detect_contour.cpp
===================================================================
--- src/lsm_detect_contour.cpp	(revision 24)
+++ src/lsm_detect_contour.cpp	(revision 25)
@@ -1,276 +0,0 @@
-/*
-Level-set Method to detect contour (exterior shape)
-Sequential
-Stop criteria parameters in command lines
-
-To compile
- g++ -o lsm_detect_contour lsm_detect_contour_full.cpp -O2 -L/usr/X11R6/lib -lm -lpthread -lX11 -l:libtiff.so.5
- Need CImg.h and lsm_lib.h
- 
-To execute
- ./lsm_detect_contour_ful.exe img t_up t_down a b smooth perUp perDown
-
- img : grayscale image of cells, .inr or .inr.gz
- t_up,t_down : linear threshold value (inr)
- a : area term (float) --> 0.5, 1
- b : curvature term (float)
- smooth : amount of gaussian blur to apply to the image
- perUp, perDown : the algorithm stops when 10 succesive iteration are between perUp and perDown (in % of background growth)
-*/
-
-#include <iostream>
-#include <math.h>
-#include <sstream>
-#include <vector>
-#include <fstream>
-
-#include "lsm_lib.h"
-
-using namespace cimg_library;
-using namespace std;
-
-//------------------------------------------------------------------------------
-//Main
-//------------------------------------------------------------------------------
-int main (int argc, char* argv[])
-{
-  clock_t begin=clock();
-
-  if(argc!=9)
-    {
-      cout<<"!! wrong number of arguments"<<endl;
-      cout<<"Usage : lsm_detect_contour img t_up t_down a b smooth perUp perDown"<<endl;
-      cout<<"Examples for parameter values:"<<endl;
-      cout<<"------------------------------"<<endl;
-      cout<<"img : grayscale image of cells, (.inr or .inr.gz)"<<endl;
-      cout<<"Upper threshold : t_up = 20"<<endl;
-      cout<<"Down threshold : t_down = 5"<<endl;
-      cout<<"Area term : a = 0 (0.5, 1)"<<endl;
-      cout<<"Curvature term : b = 0 (1)"<<endl;
-      cout<<"Gaussian filter : smooth = 1 (0, if image already filtered)"<<endl;
-      cout<<"Stop criteria : the contour evolution is in [perDown,perUp] for 10 consecutive iterations"<<endl;
-      cout<<"     perUp = 0.002, perDown = -0.002"<<endl;
-      return 0;
-    }
-
-  //ckeck filename and read image
-  string filename=argv[1];
-  CImg<unsigned char> img_prev;
-  if(filename.compare(filename.size()-4,4,".inr")==0)
-    {
-      img_prev.load(filename.c_str());
-    }
-  else if(filename.compare(filename.size()-7,7,".inr.gz")==0)
-    {
-      img_prev.load_gzip_external(filename.c_str());
-      filename.erase(filename.size()-3);
-    }
-  else
-    {cout<<"!! wrong file extension : "<<filename<<endl;
-      return 0;}
-  CImg<float> img=img_prev;
-  img_prev.assign();
-  cout<<"original image : "<<filename<<endl;
-
-  //--------------------------------------------Parameters
-  //model parameters
-  int lam=10;
-  int alf=atoi(argv[4]);
-  int beta=atoi(argv[5]);
-
-  //numerical parameters
-  float epsilon=1.5;
-  int dt=100;
-  float mu=0.1/dt;
-  int timestep_max=2000;
-
-  //linear threshold
-  int t_up=atoi(argv[2]);
-  int t_down=atoi(argv[3]);
-
-  float smooth=atof(argv[6]);
-
-  float perUp=atof(argv[7]);
-  float perDown=atof(argv[8]);
-
-  float tailleVoxel[3] = {0.195177,0.195177,0.195177};
-  
-  //other paremeters
-  int systout;
-
-  //-------------------------------------------Names and directories
-  //new name with arguments
-  string ar2=argv[2];
-  string ar3=argv[3];
-  string ar4=argv[4];
-  string ar5=argv[5];
-  string ar6=argv[6];
-  string insert="_LSMcont"+ar2+"-"+ar3+"a"+ar4+"b"+ar5+"s"+ar6;
-  filename.insert(filename.size()-4,insert);
-
-  //create directories and update names
-  size_t test=filename.rfind("/");
-  if(test!=filename.npos)
-    {filename.erase(0,test+1);}
-  string outputdir=filename;
-  outputdir.erase(filename.size()-4);
-  string mkdir="mkdir -p "+outputdir;
-  systout=system(mkdir.c_str()); 
-  mkdir="mkdir -p "+outputdir+"/evolution";
-  systout=system(mkdir.c_str());
-
-  string filename_cut=outputdir+"/evolution/"+filename;
-  filename_cut.erase(filename_cut.size()-4);
-  filename=outputdir+"/"+filename;
-  string result_name=filename;
-
-  //txt files 
-  ofstream file;
-  string txt_name=filename_cut+".txt";
-  file.open(txt_name.c_str());
-  file<<argv[0]<<endl;
-  time_t t;
-  struct tm * timeinfo;
-  time(&t);
-  timeinfo=localtime(&t);
-  file<<asctime(timeinfo);
-  file<<"image : "<<argv[1]<<endl;
-  file<<"_________________________________"<<endl;
-  file<<"Parameters"<<endl;
-  file<<"lambda : "<<lam<<endl;
-  file<<"alpha : "<<alf<<endl;
-  file<<"epsilon : "<<epsilon<<endl;
-  file<<"dt : "<<dt<<endl;
-  file<<"mu : "<<mu<<endl;
-  file<<"timestep_max : "<<timestep_max<<endl;
-  file<<"\nthreshold up : "<<t_up<<endl;
-  file<<"threshold down : "<<t_down<<endl;
-  file<<"beta : "<<beta<<endl;
-  file<<"perUp : "<<perUp<<endl;
-  file<<"perDown : "<<perDown<<endl;
-
-  ofstream bg_file;
-  string bg_name=filename_cut+"_BGgrowth.txt";
-  bg_file.open(bg_name.c_str());
-  bg_file<<"it\tbg_growth"<<endl;
-
-  //-----------------------------------------Image Pre-processing
-  //add slices
-  img=add_side_slices(img,3);
-
-  //define and save cut
-  int cut=img._depth/2;
-  cout <<"cut z= "<<cut<<endl;
-  file <<"\ncut z= "<<cut<<endl;
-  CImg<float> imgCut=img.get_crop(0,0,cut,0,img._width,img._height,cut,0);
-  imgCut.save((filename_cut+".png").c_str());
-
-  //smooth image
-  file<<"smooth : "<<smooth<<endl;
-  img.blur(smooth);
-
-  //-------------------------------------------Initialization
-  //compute fixed terms
-  CImg<float> g=edge_indicator(gradient(img));
-  CImgList<float> gg=gradient(g);
- 
-  //initialize level-set
-  int c0=-4;
-  CImg<unsigned char> segmented=threshold_linear_alongZ(img,t_up,t_down);
-  string segmentedName=filename+".gz";
-  segmentedName.insert(filename.size()-4,"_initial");
-  segmented.save_gzip_external(segmentedName.c_str());
-
-  CImg<float> psi=lsm_contour_init(segmented,c0);
-
-  int it=0;
-  int it_stop=0;
-  bool contour_evolves=true;
-  int nb_pix=img.width()*img.height()*img.depth();
-  double prev_backsegm=segmented.sum();
-
-  //-------------------------------------------Time iterations
-  while( (it<timestep_max) and (contour_evolves==true) )
-    {
-      //LSM
-      psi=evolution_AK2_contour(psi,g,gg,g,lam,mu,alf,beta,epsilon,dt);
-
-      //Update segmentation
-      double backsegm=0;
-      cimg_forXYZ(segmented,x,y,z)
-	{
-	  if(psi(x,y,z)>0)
-	    {
-	      segmented(x,y,z)=1;
-	      backsegm+=1;
-	    }
-	  else
-	    {segmented(x,y,z)=0;}
-	}	
-
-      //Background evolution
-      double bg_evolution=backsegm-prev_backsegm;
-      double bg100=(bg_evolution*1.0/nb_pix)*100;
-      prev_backsegm=backsegm;
-
-      cout<<"----------------------------------- it : "<<it<<endl;
-      cout<<"bg growth : "<<bg_evolution<<endl;
-      cout<<"% of bg growth : "<<bg100<<endl;
-      bg_file<<it<<"\t"<<bg_evolution<<endl;
-   
-
-      //Stop criteria 
-      if((it>10) and (bg100<perUp) and (bg100>perDown))
-	{
-	  it_stop+=1;
-	  if(it_stop>9)
-	    {contour_evolves=false;}
-	}
-      else
-	{
-	  it_stop=0;
-	}
-
-      //Graphics to follow evolution
-      if((it%50==0)or(contour_evolves==false)or(it==timestep_max-1))
-	{
-	  ostringstream oss;
-	  oss << it;
-	  string iterstring="";
-	  if(it<10) {iterstring="00"+oss.str();}
-	  else if (it<100) {iterstring="0"+oss.str();}
-	  else {iterstring=oss.str();}
-	  cout<<"-----------------------------------"<<endl;
-	  cout<<" *** time step for graphics : "<<iterstring<<endl;
-	  //Save cut
-	  CImg<float>segCut=segmented.get_crop(0,0,cut,0,img._width,img._height,cut,0);
-	  string temp_name=filename_cut+"it"+iterstring+".png";
-	  segCut.normalize(0,255).save(temp_name.c_str());
-	}
-      if((((it%50)==0)and(it!=0))or(contour_evolves==false)or(it==timestep_max-1))
-	{
-	  //Save result
-	  CImg<unsigned char>segSave=remove_side_slices(segmented,3);
-	  segSave.save_inr(result_name.c_str(),tailleVoxel);
-	  segSave.assign();
-	  string zip="gzip -f "+result_name;
-	  systout=system(zip.c_str());
-	}
-      it+=1;
-    }
-
-  clock_t end=clock();
-  double time=double(end-begin)/CLOCKS_PER_SEC;
-  cout <<"elapsed time : "<<time<<" sec ( ~ "<<time/60<<" mn ~ "<<time/60/60<<" h)"<<endl;
-  file <<"last iteration : "<<it-1<<endl;
-  file <<"elapsed time : "<<time<<" sec ( ~ "<<time/60<<" mn ~ "<<time/60/60<<" h)"<<endl;
-
-  file<<"width "<<img.width()<<endl;
-  file<<"height "<<img.height()<<endl;
-  file<<"depth "<<img.depth()<<endl;
-
-  file<<"number of pixel "<<img._width*img._height*img._depth<<endl;
-
-  file.close();
-  return 0;
-}
Index: src/lsm_contour.cpp
===================================================================
--- src/lsm_contour.cpp	(revision 0)
+++ src/lsm_contour.cpp	(revision 25)
@@ -0,0 +1,276 @@
+/*
+Level-set Method to detect contour (exterior shape)
+Sequential
+Stop criteria parameters in command lines
+
+To compile
+ g++ -o lsm_contour lsm_contour.cpp -O2 -L/usr/X11R6/lib -lm -lpthread -lX11 -l:libtiff.so.5
+ Need CImg.h and lsm_lib.h
+ 
+To execute
+ ./lsm_contour img t_up t_down a b smooth perUp perDown
+
+ img : grayscale image of cells, .inr or .inr.gz
+ t_up,t_down : linear threshold value (inr)
+ a : area term (float) --> 0.5, 1
+ b : curvature term (float)
+ smooth : amount of gaussian blur to apply to the image
+ perUp, perDown : the algorithm stops when 10 succesive iteration are between perUp and perDown (in % of background growth)
+*/
+
+#include <iostream>
+#include <math.h>
+#include <sstream>
+#include <vector>
+#include <fstream>
+
+#include "lsm_lib.h"
+
+using namespace cimg_library;
+using namespace std;
+
+//------------------------------------------------------------------------------
+//Main
+//------------------------------------------------------------------------------
+int main (int argc, char* argv[])
+{
+  clock_t begin=clock();
+
+  if(argc!=9)
+    {
+      cout<<"!! wrong number of arguments"<<endl;
+      cout<<"Usage : lsm_contour img t_up t_down a b smooth perUp perDown"<<endl;
+      cout<<"Examples for parameter values:"<<endl;
+      cout<<"------------------------------"<<endl;
+      cout<<"img : grayscale image of cells, (.inr or .inr.gz)"<<endl;
+      cout<<"Upper threshold : t_up = 20"<<endl;
+      cout<<"Down threshold : t_down = 5"<<endl;
+      cout<<"Area term : a = 0 (0.5, 1)"<<endl;
+      cout<<"Curvature term : b = 0 (1)"<<endl;
+      cout<<"Gaussian filter : smooth = 1 (0, if image already filtered)"<<endl;
+      cout<<"Stop criteria : the contour evolution is in [perDown,perUp] for 10 consecutive iterations"<<endl;
+      cout<<"     perUp = 0.002, perDown = -0.002"<<endl;
+      return 0;
+    }
+
+  //ckeck filename and read image
+  string filename=argv[1];
+  CImg<unsigned char> img_prev;
+  if(filename.compare(filename.size()-4,4,".inr")==0)
+    {
+      img_prev.load(filename.c_str());
+    }
+  else if(filename.compare(filename.size()-7,7,".inr.gz")==0)
+    {
+      img_prev.load_gzip_external(filename.c_str());
+      filename.erase(filename.size()-3);
+    }
+  else
+    {cout<<"!! wrong file extension : "<<filename<<endl;
+      return 0;}
+  CImg<float> img=img_prev;
+  img_prev.assign();
+  cout<<"original image : "<<filename<<endl;
+
+  //--------------------------------------------Parameters
+  //model parameters
+  int lam=10;
+  int alf=atoi(argv[4]);
+  int beta=atoi(argv[5]);
+
+  //numerical parameters
+  float epsilon=1.5;
+  int dt=100;
+  float mu=0.1/dt;
+  int timestep_max=2000;
+
+  //linear threshold
+  int t_up=atoi(argv[2]);
+  int t_down=atoi(argv[3]);
+
+  float smooth=atof(argv[6]);
+
+  float perUp=atof(argv[7]);
+  float perDown=atof(argv[8]);
+
+  float tailleVoxel[3] = {0.195177,0.195177,0.195177};
+  
+  //other paremeters
+  int systout;
+
+  //-------------------------------------------Names and directories
+  //new name with arguments
+  string ar2=argv[2];
+  string ar3=argv[3];
+  string ar4=argv[4];
+  string ar5=argv[5];
+  string ar6=argv[6];
+  string insert="_LSMcont"+ar2+"-"+ar3+"a"+ar4+"b"+ar5+"s"+ar6;
+  filename.insert(filename.size()-4,insert);
+
+  //create directories and update names
+  size_t test=filename.rfind("/");
+  if(test!=filename.npos)
+    {filename.erase(0,test+1);}
+  string outputdir=filename;
+  outputdir.erase(filename.size()-4);
+  string mkdir="mkdir -p "+outputdir;
+  systout=system(mkdir.c_str()); 
+  mkdir="mkdir -p "+outputdir+"/evolution";
+  systout=system(mkdir.c_str());
+
+  string filename_cut=outputdir+"/evolution/"+filename;
+  filename_cut.erase(filename_cut.size()-4);
+  filename=outputdir+"/"+filename;
+  string result_name=filename;
+
+  //txt files 
+  ofstream file;
+  string txt_name=filename_cut+".txt";
+  file.open(txt_name.c_str());
+  file<<argv[0]<<endl;
+  time_t t;
+  struct tm * timeinfo;
+  time(&t);
+  timeinfo=localtime(&t);
+  file<<asctime(timeinfo);
+  file<<"image : "<<argv[1]<<endl;
+  file<<"_________________________________"<<endl;
+  file<<"Parameters"<<endl;
+  file<<"lambda : "<<lam<<endl;
+  file<<"alpha : "<<alf<<endl;
+  file<<"epsilon : "<<epsilon<<endl;
+  file<<"dt : "<<dt<<endl;
+  file<<"mu : "<<mu<<endl;
+  file<<"timestep_max : "<<timestep_max<<endl;
+  file<<"\nthreshold up : "<<t_up<<endl;
+  file<<"threshold down : "<<t_down<<endl;
+  file<<"beta : "<<beta<<endl;
+  file<<"perUp : "<<perUp<<endl;
+  file<<"perDown : "<<perDown<<endl;
+
+  ofstream bg_file;
+  string bg_name=filename_cut+"_BGgrowth.txt";
+  bg_file.open(bg_name.c_str());
+  bg_file<<"it\tbg_growth"<<endl;
+
+  //-----------------------------------------Image Pre-processing
+  //add slices
+  img=add_side_slices(img,3);
+
+  //define and save cut
+  int cut=img._depth/2;
+  cout <<"cut z= "<<cut<<endl;
+  file <<"\ncut z= "<<cut<<endl;
+  CImg<float> imgCut=img.get_crop(0,0,cut,0,img._width,img._height,cut,0);
+  imgCut.save((filename_cut+".png").c_str());
+
+  //smooth image
+  file<<"smooth : "<<smooth<<endl;
+  img.blur(smooth);
+
+  //-------------------------------------------Initialization
+  //compute fixed terms
+  CImg<float> g=edge_indicator(gradient(img));
+  CImgList<float> gg=gradient(g);
+ 
+  //initialize level-set
+  int c0=-4;
+  CImg<unsigned char> segmented=threshold_linear_alongZ(img,t_up,t_down);
+  string segmentedName=filename+".gz";
+  segmentedName.insert(filename.size()-4,"_initial");
+  segmented.save_gzip_external(segmentedName.c_str());
+
+  CImg<float> psi=lsm_contour_init(segmented,c0);
+
+  int it=0;
+  int it_stop=0;
+  bool contour_evolves=true;
+  int nb_pix=img.width()*img.height()*img.depth();
+  double prev_backsegm=segmented.sum();
+
+  //-------------------------------------------Time iterations
+  while( (it<timestep_max) and (contour_evolves==true) )
+    {
+      //LSM
+      psi=evolution_AK2_contour(psi,g,gg,g,lam,mu,alf,beta,epsilon,dt);
+
+      //Update segmentation
+      double backsegm=0;
+      cimg_forXYZ(segmented,x,y,z)
+	{
+	  if(psi(x,y,z)>0)
+	    {
+	      segmented(x,y,z)=1;
+	      backsegm+=1;
+	    }
+	  else
+	    {segmented(x,y,z)=0;}
+	}	
+
+      //Background evolution
+      double bg_evolution=backsegm-prev_backsegm;
+      double bg100=(bg_evolution*1.0/nb_pix)*100;
+      prev_backsegm=backsegm;
+
+      cout<<"----------------------------------- it : "<<it<<endl;
+      cout<<"bg growth : "<<bg_evolution<<endl;
+      cout<<"% of bg growth : "<<bg100<<endl;
+      bg_file<<it<<"\t"<<bg_evolution<<endl;
+   
+
+      //Stop criteria 
+      if((it>10) and (bg100<perUp) and (bg100>perDown))
+	{
+	  it_stop+=1;
+	  if(it_stop>9)
+	    {contour_evolves=false;}
+	}
+      else
+	{
+	  it_stop=0;
+	}
+
+      //Graphics to follow evolution
+      if((it%50==0)or(contour_evolves==false)or(it==timestep_max-1))
+	{
+	  ostringstream oss;
+	  oss << it;
+	  string iterstring="";
+	  if(it<10) {iterstring="00"+oss.str();}
+	  else if (it<100) {iterstring="0"+oss.str();}
+	  else {iterstring=oss.str();}
+	  cout<<"-----------------------------------"<<endl;
+	  cout<<" *** time step for graphics : "<<iterstring<<endl;
+	  //Save cut
+	  CImg<float>segCut=segmented.get_crop(0,0,cut,0,img._width,img._height,cut,0);
+	  string temp_name=filename_cut+"it"+iterstring+".png";
+	  segCut.normalize(0,255).save(temp_name.c_str());
+	}
+      if((((it%50)==0)and(it!=0))or(contour_evolves==false)or(it==timestep_max-1))
+	{
+	  //Save result
+	  CImg<unsigned char>segSave=remove_side_slices(segmented,3);
+	  segSave.save_inr(result_name.c_str(),tailleVoxel);
+	  segSave.assign();
+	  string zip="gzip -f "+result_name;
+	  systout=system(zip.c_str());
+	}
+      it+=1;
+    }
+
+  clock_t end=clock();
+  double time=double(end-begin)/CLOCKS_PER_SEC;
+  cout <<"elapsed time : "<<time<<" sec ( ~ "<<time/60<<" mn ~ "<<time/60/60<<" h)"<<endl;
+  file <<"last iteration : "<<it-1<<endl;
+  file <<"elapsed time : "<<time<<" sec ( ~ "<<time/60<<" mn ~ "<<time/60/60<<" h)"<<endl;
+
+  file<<"width "<<img.width()<<endl;
+  file<<"height "<<img.height()<<endl;
+  file<<"depth "<<img.depth()<<endl;
+
+  file<<"number of pixel "<<img._width*img._height*img._depth<<endl;
+
+  file.close();
+  return 0;
+}
