3 |
3 |
Parallel standard version
|
4 |
4 |
|
5 |
5 |
To compile :
|
6 |
|
g++ -o lsm_cells_20160610.exe lsm_cells_20160610.cpp -O2 -L/usr/X11R6/lib -lm -lpthread -lX11 -fopenmp
|
|
6 |
g++ -o lsm_cells lsm_cells.cpp -O2 -L/usr/X11R6/lib -lm -lpthread -lX11 -fopenmp
|
7 |
7 |
Need CImg.h and lsm_lib.h
|
8 |
8 |
|
9 |
9 |
To execute :
|
10 |
|
./lsm_cells.exe img img_wat img_contour erosion
|
|
10 |
./lsm_cells img img_wat img_contour erosion
|
11 |
11 |
|
12 |
12 |
image in .inr or .inr.gz, save in .inr.gz
|
13 |
13 |
img : grayscale image of cells (unsigned char)
|
... | ... | |
152 |
152 |
|
153 |
153 |
//Stop criteria
|
154 |
154 |
int bg_evolution=abs(new_backsegm-backsegm);
|
155 |
|
/*
|
156 |
|
if((it>20)and(bg_evolution<evolution_min))
|
157 |
|
{contour_evolve=false;}
|
158 |
|
*/
|
159 |
155 |
|
160 |
156 |
//New stop criteria
|
161 |
157 |
if((it>10) and (bg_evolution<=evolution_min) and (bg_evolution>=evolution_max))
|
... | ... | |
256 |
252 |
if(argc<5)
|
257 |
253 |
{
|
258 |
254 |
cout<<"!! wrong number of arguments ("<<argc<<")"<<endl;
|
259 |
|
cout<<"how to execute : ./lsm_cells.exe img img_wat img_contour erosion [a b smooth lsm_type]"<<endl;
|
|
255 |
cout<<"Usage : lsm_cells img img_wat img_contour erosion [a b smooth lsm_type]"<<endl;
|
260 |
256 |
cout<<"----------------- "<<endl;
|
261 |
257 |
cout<<"img : grayscale image of cells, (.inr or .inr.gz)"<<endl;
|
262 |
258 |
cout<<"img_wat : image of seeds, (.inr or .inr.gz)"<<endl;
|
... | ... | |
269 |
265 |
cout<<" if negative, the object retracts"<<endl;
|
270 |
266 |
cout<<" if positive, the object inflates"<<endl;
|
271 |
267 |
cout<<"b : curvature term (float) --> 0 or 1 (the default is 0)"<<endl;
|
272 |
|
cout<<"gamma : scale parameter (float>0) --> 0.5 or 1 (the default is 0)"<<endl;
|
|
268 |
cout<<"gamma : scale parameter (float>0) --> 0.5 or 1 (the default is 1)"<<endl;
|
273 |
269 |
cout<<"smooth : gaussian blur to apply to the image (int) --> 0 or 1 (the default is 0)"<<endl;
|
274 |
270 |
cout<<"lsm_type : image, gradient or hessien based evolution --> 'i', 'g' or 'h' (the default is g)"<<endl;
|
275 |
271 |
return 0;
|
... | ... | |
361 |
357 |
|
362 |
358 |
//---------------------------------------------------------------Parameters
|
363 |
359 |
//model parameters
|
364 |
|
//int alfabis=100;
|
365 |
|
//float betabis=0;
|
366 |
360 |
|
367 |
361 |
int c0=-4;
|
368 |
362 |
int erosion=atoi(argv[4]);
|
... | ... | |
419 |
413 |
|
420 |
414 |
//------------------------------------Names and directories
|
421 |
415 |
//new name with arguments
|
422 |
|
//string ar=argv[4];
|
423 |
|
//string insert="_cellLSM-d"+ar;
|
424 |
416 |
filename.insert(filename.size()-4,insert);
|
425 |
417 |
|
426 |
418 |
//create directories and update names
|
... | ... | |
510 |
502 |
CImgList<float> gg=gradient(g);
|
511 |
503 |
CImg<float> h=g;
|
512 |
504 |
img.assign();
|
|
505 |
|
513 |
506 |
|
514 |
|
// save edge indicator
|
515 |
|
string edge_indicator_name = "edge_indicator.inr";
|
516 |
|
g.save_inr(edge_indicator_name.c_str(),tailleVoxel);
|
517 |
|
string zip="gzip -f "+edge_indicator_name;
|
518 |
|
syst=system(zip.c_str());
|
519 |
|
|
520 |
|
//g.crop(0,0,cut,0,g._width,g._height,cut,0);
|
521 |
|
//g.normalize(0,255).save((filename_cut+"_edge_indicator.png").c_str());
|
522 |
|
// warning !!! once normalised, one cannot do computations with it
|
523 |
|
|
524 |
507 |
CImg<float> gout=g;
|
525 |
508 |
gout.crop(0,0,cut,0,g._width,g._height,cut,0);
|
526 |
509 |
gout.normalize(0,255).save((filename_cut+"_edge_indicator.png").c_str());
|
... | ... | |
557 |
540 |
//reconstruct image of eroded cell
|
558 |
541 |
CImg<unsigned short> wat_eroded=reconstruct(background,psi_list,min_list,nbcells,list);
|
559 |
542 |
wat_eroded.save_inr(wat_eroded_name.c_str(),tailleVoxel);
|
560 |
|
zip="gzip -f "+wat_eroded_name;
|
|
543 |
string zip="gzip -f "+wat_eroded_name;
|
561 |
544 |
syst=system(zip.c_str());
|
562 |
545 |
wat_eroded.crop(0,0,cut,0,wat_eroded._width,wat_eroded._height,cut,0);
|
563 |
546 |
wat_eroded.normalize(0,255).save((filename_cut+"_eroded.png").c_str());
|
... | ... | |
600 |
583 |
file<<"edge detection : "<<time2<<endl;
|
601 |
584 |
|
602 |
585 |
|
603 |
|
/*
|
604 |
|
//--------------------------------------------------------Edge evolution
|
605 |
|
//evolve every cell to fill the gaps
|
606 |
|
lam=0;
|
607 |
|
alf=alfabis;
|
608 |
|
beta=betabis;
|
609 |
|
bool contour_evolve=true;
|
610 |
|
float backsegm=free.sum();
|
611 |
|
int it=0;
|
612 |
|
int it_stop=0;
|
613 |
|
|
614 |
|
while((it<timestep_max)and(contour_evolve==true))
|
615 |
|
{
|
616 |
|
//each cell evolve one time step
|
617 |
|
#pragma omp parallel shared(psi_list,min_list,g,gg,h,lam,mu,alf,beta,epsilon,dt,free)
|
618 |
|
{
|
619 |
|
#pragma omp for schedule(dynamic)
|
620 |
|
for(int i=0;i<nbcells;i++)
|
621 |
|
{
|
622 |
|
psi_list[i]=evolution_AK2_contour_interact(psi_list[i],g,gg,h,lam,mu,alf,beta,epsilon,dt,free,min_list[i]);
|
623 |
|
}
|
624 |
|
}
|
625 |
|
|
626 |
|
//reconstruct image of edge detection, overlap=not segmented
|
627 |
|
edge=reconstruct_overlap(background,psi_list,min_list,nbcells,free,list);
|
628 |
|
|
629 |
|
//bg evolution
|
630 |
|
float newsegm=free.sum();
|
631 |
|
float bg_evolution=newsegm-backsegm;
|
632 |
|
backsegm=newsegm;
|
633 |
|
|
634 |
|
//stop criteria
|
635 |
|
//double stop_criteria=size-newsegm;
|
636 |
|
if((it>40)and(abs(bg_evolution)<1))
|
637 |
|
{
|
638 |
|
contour_evolve=false;
|
639 |
|
}
|
640 |
|
|
641 |
|
//save
|
642 |
|
if(((it%100==0)and(it!=0))or(contour_evolve==false)or(it==timestep_max-1))
|
643 |
|
{
|
644 |
|
edge.save_inr(edge_evolve_name.c_str(),tailleVoxel);
|
645 |
|
zip="gzip -f "+edge_evolve_name;
|
646 |
|
syst=system(zip.c_str());
|
647 |
|
CImg<unsigned short> edgeCrop=edge.get_crop(0,0,cut,0,edge._width,edge._height,cut,0);
|
648 |
|
edgeCrop.normalize(0,255).save((filename_cut+"_final.png").c_str());
|
649 |
|
}
|
650 |
|
|
651 |
|
cout<<"it "<<it<<" evo "<<bg_evolution<<endl;
|
652 |
|
it+=1;
|
653 |
|
|
654 |
|
}
|
655 |
|
*/
|
656 |
|
|
657 |
586 |
double end=omp_get_wtime();
|
658 |
587 |
double time=double(end-begin);
|
659 |
588 |
cout<<"total time : "<<time<<" (~"<<time/60<<" mn ~"<<time/60/60<<" h)"<<endl;
|