Révision 28 src/lsm_cells.cpp
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; |
Formats disponibles : Unified diff