root / src / contour_init.cpp @ 9
Historique | Voir | Annoter | Télécharger (2,38 ko)
1 |
/*
|
---|---|
2 |
Level-set Method to detect tissue contour (exterior shape)
|
3 |
- Sequential -
|
4 |
|
5 |
Copyright 2016 ENS de Lyon
|
6 |
|
7 |
File author(s):
|
8 |
Typhaine Moreau, Annamaria Kiss <annamaria.kiss@ens-lyon.fr.fr>
|
9 |
See accompanying file LICENSE.txt
|
10 |
|
11 |
To compile
|
12 |
g++ -o contour_init contour_init.cpp -O2 -L/usr/X11R6/lib -lm -lpthread -lX11 -l:libtiff.so.5
|
13 |
Need CImg.h and lsm_lib.h
|
14 |
|
15 |
To execute
|
16 |
./contour_init img t_up t_down smooth
|
17 |
|
18 |
img : grayscale image of cells, .inr or .inr.gz
|
19 |
t_up,t_down : linear threshold value (inr)
|
20 |
smooth : amount of gaussian blur to apply to the image
|
21 |
*/
|
22 |
|
23 |
#include <iostream> |
24 |
#include <math.h> |
25 |
#include <sstream> |
26 |
#include <vector> |
27 |
#include <fstream> |
28 |
|
29 |
#include "lsm_lib.h" |
30 |
|
31 |
using namespace cimg_library; |
32 |
using namespace std; |
33 |
|
34 |
//------------------------------------------------------------------------------
|
35 |
//Main
|
36 |
//------------------------------------------------------------------------------
|
37 |
int main (int argc, char* argv[]) |
38 |
{ |
39 |
clock_t begin=clock(); |
40 |
|
41 |
if(argc!=5) |
42 |
{ |
43 |
cout<<"!! wrong number of arguments"<<endl;
|
44 |
cout<<"Usage : contour_init img t_up t_down smooth"<<endl;
|
45 |
cout<<"Examples for parameter values:"<<endl;
|
46 |
cout<<"------------------------------"<<endl;
|
47 |
cout<<"img : grayscale image of cells, (.inr or .inr.gz)"<<endl;
|
48 |
cout<<"Upper threshold : t_up = 20"<<endl;
|
49 |
cout<<"Down threshold : t_down = 5"<<endl;
|
50 |
cout<<"Gaussian filter : smooth = 1 (0, if image already filtered)"<<endl;
|
51 |
return 0; |
52 |
} |
53 |
|
54 |
//ckeck filename and read image
|
55 |
string filename=argv[1]; |
56 |
float tailleVoxel[3] = {0};// resolution initialisation |
57 |
CImg<float> img=imread(filename, tailleVoxel);
|
58 |
|
59 |
//--------------------------------------------Parameters
|
60 |
//linear threshold and smoothing
|
61 |
int t_up=atoi(argv[2]); |
62 |
int t_down=atoi(argv[3]); |
63 |
float smooth=atof(argv[4]); |
64 |
|
65 |
//-------------------------------------------Names and directories
|
66 |
//new name with arguments
|
67 |
string ar2=argv[2]; |
68 |
string ar3=argv[3]; |
69 |
string ar4=argv[4]; |
70 |
string insert="_initial"+ar2+"-"+ar3+"s"+ar4; |
71 |
filename.insert(filename.size()-4,insert);
|
72 |
|
73 |
//-----------------------------------------Image Pre-processing
|
74 |
//smooth image
|
75 |
img.blur(smooth); |
76 |
|
77 |
//-------------------------------------------Initialization
|
78 |
//initialize level-set
|
79 |
CImg<unsigned char> segmented=threshold_linear_alongZ(img,t_up,t_down); |
80 |
int s=imsave(filename, tailleVoxel, segmented);
|
81 |
return 0; |
82 |
} |