Révision 28

lsm3D_compile.sh (revision 28)
1 1
#! /bin/bash
2 2

  
3 3
bin_directory='../bin'
4
compiling_options=' -O2 -L/usr/X11R6/lib -lm -lpthread -lX11 '
4
compiling_options=' -O2 -lm -lpthread -lX11 '
5 5

  
6 6
cd src
7 7
echo '------------------------------------'
src/lsm_cells.cpp (revision 28)
161 161
      int bg_evolution=abs(new_backsegm-backsegm);
162 162
	
163 163
      // * if the evolution is less then evolution_min 3 consecutive times
164
      //if((it>10) and (bg_evolution<=evolution_min) and (bg_evolution>=evolution_max))
165 164
      if((it>10) and (bg_evolution<=evolution_min) )
166 165
	{
167 166
	  it_stop+=1;
168 167
	  if(it_stop>3)
169
	    {contour_evolve=false;
170
		cout<<"stopit "<<endl;}
168
	    {contour_evolve=false;}
171 169
	}
172 170
      else
173 171
	{
......
177 175

  
178 176
      it+=1;
179 177
      backsegm=new_backsegm;
180
      //cout<<"backsegm= "<<backsegm<<endl;     
181 178
    }
182

  
183
//  cimg_forXYZ(psi,x,y,z)
184
//    {
185
//      if(psi(x,y,z)>=0){psi(x,y,z)=4;}
186
//      else{psi(x,y,z)=-4;}
187
//    }
188

  
189 179
  return psi;
190 180
}
191 181

  
......
283 273
  //Original image
284 274
  CImg<char> description;
285 275
  float tailleVoxel[3] = {0}; // resolution initialisation
286
  //float tailleVoxel[3] = {0.195177,0.195177,0.195177};
287 276
  
288 277
  bool gzipped=false;
289 278
  
......
430 419
  string outputdir=filename;
431 420
  outputdir.erase(filename.size()-4);
432 421
  string mkdir="mkdir -p "+outputdir;
433
  int syst=system(mkdir.c_str()); 
434
  mkdir="mkdir -p "+outputdir+"/evolution";
435
  syst=system(mkdir.c_str());
422
  if(system(mkdir.c_str())); 
436 423

  
437
  string filename_cut=outputdir+"/evolution/"+filename;
438
  filename_cut.erase(filename_cut.size()-4);
424
  string filename_txt=outputdir+"/"+filename;
425
  filename_txt.erase(filename_txt.size()-4);
439 426
  filename=outputdir+"/"+filename;
440 427
  string wat_eroded_name=filename;
441 428
  wat_eroded_name.insert(filename.size()-4,"_eroded");
......
446 433

  
447 434
  //txt files 
448 435
  ofstream file;
449
  string txt_name=filename_cut+".txt";
436
  string txt_name=filename_txt+".txt";
450 437
  file.open(txt_name.c_str());
451 438
  file<<argv[0]<<endl;
452 439
  time_t t;
......
474 461
  file<<"timestep_max : "<<timestep_max <<endl;
475 462

  
476 463
  //-----------------------------------------Image Pre-processing
477
  //define cut
478
  int cut=img._depth/2;
479
  cut = 82;
480
  cout <<"cut z= "<<cut<<endl;
481
  file <<"\ncut z= "<<cut<<endl;
482
  CImg<float> imgCut=img.get_crop(0,0,cut,0,img._width,img._height,cut,0);
483
  imgCut.save((filename_cut+".png").c_str());
484 464

  
485 465
  //smooth image
486 466
  file<<"smooth : "<<smooth<<endl;
......
510 490
  CImgList<float> gg=gradient(g);
511 491
  CImg<float> h=g;
512 492
  img.assign();
513

  
514 493
  
515
  CImg<float> gout=g;
516
  gout.crop(0,0,cut,0,g._width,g._height,cut,0);
517
  gout.normalize(0,255).save((filename_cut+"_edge_indicator.png").c_str());
518
  gout.assign();
519
  
520 494
  //initialize psi for every cell
521 495
  int maxcells=wat.max()+1; //indice maximum  
522 496
  vector<int> list=index(wat,maxcells);
......
540 514
      min_list[i][0]=xmin;
541 515
      min_list[i][1]=ymin;
542 516
      min_list[i][2]=zmin;
543
      cout <<"cell "<<ind<<endl;
517
      cout <<"cell "<<ind<<" initialised."<<endl;
544 518
    }
545 519
  }
546 520
  wat.assign();
547 521

  
548
  //reconstruct image of eroded cell
522
  //reconstruct image of eroded cells
549 523
  CImg<unsigned short> wat_eroded=reconstruct(background,psi_list,min_list,nbcells,list);
524
  cout <<"saving file "<<wat_eroded_name<<"..."<<endl;
550 525
  wat_eroded.save_inr(wat_eroded_name.c_str(),tailleVoxel);
551 526
  string zip="gzip -f "+wat_eroded_name;
552
  syst=system(zip.c_str());
553
  wat_eroded.crop(0,0,cut,0,wat_eroded._width,wat_eroded._height,cut,0);
554
  wat_eroded.normalize(0,255).save((filename_cut+"_eroded.png").c_str());
555
  wat_eroded.assign();
527
  if(system(zip.c_str()));
528
  cout <<"Eroded watershed segmentation saved in file:"<<wat_eroded_name<<endl;
556 529

  
557 530
  //Segmented inital = background segmentation
558 531
  CImg<unsigned char> segmented=background;
559 532

  
560 533
  double end1=omp_get_wtime();
561 534
  double time1=double(end1-begin);
562
  cout<<"initialization with erosion : "<<time1<<endl;
563
  file<<"\ninitialization with erosion : "<<time1<<endl;
564 535
  cout<<"Evolving cells..... "<<endl;
536
  
565 537
  //---------------------------------------------------------Edge detection
566 538
  //evolve each cell one by one, attract to maximal gradient
567 539
#pragma omp parallel shared(psi_list,min_list,g,gg,h,lam,mu,alf,beta,epsilon,dt,list)
......
570 542
  for(int i=0;i<nbcells;i++) 
571 543
    {
572 544
      psi_list[i]=lsm_segment2(psi_list[i],g,gg,h,lam,mu,alf,beta,epsilon,dt,min_list[i]);
573
      cout <<"cell evolution "<<list[i]<<endl;
545
      cout <<"cell "<<list[i]<<" evolved."<<endl;
574 546
    }
575 547
  }
576 548

  
......
579 551
  CImg<unsigned short> edge=reconstruct_overlap(background,psi_list,min_list,nbcells,free,list);
580 552
  edge.save_inr(edge_detection_name.c_str(),tailleVoxel);
581 553
  zip="gzip -f "+edge_detection_name;
582
  syst=system(zip.c_str());
583
  edge.crop(0,0,cut,0,edge._width,edge._height,cut,0);
584
  edge.normalize(0,255).save((filename_cut+"_evoEdge.png").c_str());
585
  
554
  if(system(zip.c_str()));
586 555

  
587

  
556
// time measurements
588 557
  double end2=omp_get_wtime();
589 558
  double time2=double(end2-begin);
590
  cout<<"edge detection : "<<time2<<endl;
591
  file<<"edge detection : "<<time2<<endl;
592

  
593

  
559
  
594 560
  double end=omp_get_wtime();
595 561
  double time=double(end-begin);
596
  cout<<"total time : "<<time<<" (~"<<time/60<<" mn  ~"<<time/60/60<<" h)"<<endl;
597
  cout<<"initialization with erosion : "<<time1<<endl;
598
  cout<<"edge detection : "<<time2<<endl;
599
  file<<"total time : "<<time<<" (~"<<time/60<<" mn  ~"<<time/60/60<<" h)"<<endl;
600
  file<<"initialization with erosion : "<<time1<<endl;
601
  file<<"edge detection : "<<time2<<endl;
562
  cout<<"total time : "<<time<<"s"<<" (~"<<time/60<<" mn  ~"<<time/60/60<<" h)"<<endl;
563
  cout<<"-initialization with erosion : "<<time1<<"s"<<endl;
564
  cout<<"-edge detection : "<<time2<<"s"<<endl;
565
  file<<"total time : "<<time<<"s"<<" (~"<<time/60<<" mn  ~"<<time/60/60<<" h)"<<endl;
566
  file<<"-initialization with erosion : "<<time1<<"s"<<endl;
567
  file<<"-edge detection : "<<time2<<"s"<<endl;
602 568
  file.close();
603 569

  
604 570
  return 0;
src/lsm_contour.cpp (revision 28)
116 116
  outputdir.erase(filename.size()-4);
117 117
  string mkdir="mkdir -p "+outputdir;
118 118
  systout=system(mkdir.c_str()); 
119
  mkdir="mkdir -p "+outputdir+"/evolution";
120
  systout=system(mkdir.c_str());
121 119

  
122
  string filename_cut=outputdir+"/evolution/"+filename;
123
  filename_cut.erase(filename_cut.size()-4);
120
  string filename_txt=outputdir+"/"+filename;
121
  filename_txt.erase(filename_txt.size()-4);
124 122
  filename=outputdir+"/"+filename;
125 123
  string result_name=filename;
126 124

  
127 125
  //txt files 
128 126
  ofstream file;
129
  string txt_name=filename_cut+".txt";
127
  string txt_name=filename_txt+".txt";
130 128
  file.open(txt_name.c_str());
131 129
  file<<argv[0]<<endl;
132 130
  time_t t;
......
150 148
  file<<"perDown : "<<perDown<<endl;
151 149

  
152 150
  ofstream bg_file;
153
  string bg_name=filename_cut+"_BGgrowth.txt";
151
  string bg_name=filename_txt+"_BGgrowth.txt";
154 152
  bg_file.open(bg_name.c_str());
155 153
  bg_file<<"it\tbg_growth"<<endl;
156 154

  
......
158 156
  //add slices
159 157
  img=add_side_slices(img,3);
160 158

  
161
  //define and save cut
162
  int cut=img._depth/2;
163
  cout <<"cut z= "<<cut<<endl;
164
  file <<"\ncut z= "<<cut<<endl;
165
  CImg<float> imgCut=img.get_crop(0,0,cut,0,img._width,img._height,cut,0);
166
  imgCut.save((filename_cut+".png").c_str());
167

  
168 159
  //smooth image
169 160
  file<<"smooth : "<<smooth<<endl;
170 161
  img.blur(smooth);
......
231 222
	  it_stop=0;
232 223
	}
233 224

  
234
      //Graphics to follow evolution
235
      if((it%50==0)or(contour_evolves==false)or(it==timestep_max-1))
236
	{
237
	  ostringstream oss;
238
	  oss << it;
239
	  string iterstring="";
240
	  if(it<10) {iterstring="00"+oss.str();}
241
	  else if (it<100) {iterstring="0"+oss.str();}
242
	  else {iterstring=oss.str();}
243
	  cout<<"-----------------------------------"<<endl;
244
	  cout<<" *** time step for graphics : "<<iterstring<<endl;
245
	  //Save cut
246
	  CImg<float>segCut=segmented.get_crop(0,0,cut,0,img._width,img._height,cut,0);
247
	  string temp_name=filename_cut+"it"+iterstring+".png";
248
	  segCut.normalize(0,255).save(temp_name.c_str());
249
	}
225
    //Save result
250 226
      if((((it%50)==0)and(it!=0))or(contour_evolves==false)or(it==timestep_max-1))
251
	{
252
	  //Save result
227
	{	  
253 228
	  CImg<unsigned char>segSave=remove_side_slices(segmented,3);
254 229
	  segSave.save_inr(result_name.c_str(),tailleVoxel);
255 230
	  segSave.assign();

Formats disponibles : Unified diff