Statistiques
| Révision :

root / src / contour_init.cpp @ 6

Historique | Voir | Annoter | Télécharger (2,38 ko)

1 6 akiss
/*
2 6 akiss
Level-set Method to detect tissue contour (exterior shape)
3 6 akiss
- Sequential -
4 6 akiss

5 6 akiss
      Copyright 2016 ENS de Lyon
6 6 akiss

7 6 akiss
       File author(s):
8 6 akiss
           Typhaine Moreau, Annamaria Kiss <annamaria.kiss@ens-lyon.fr.fr>
9 6 akiss
       See accompanying file LICENSE.txt
10 6 akiss

11 6 akiss
To compile
12 6 akiss
 g++ -o contour_init contour_init.cpp -O2 -L/usr/X11R6/lib -lm -lpthread -lX11 -l:libtiff.so.5
13 6 akiss
 Need CImg.h and lsm_lib.h
14 6 akiss

15 6 akiss
To execute
16 6 akiss
 ./contour_init img t_up t_down smooth
17 6 akiss

18 6 akiss
 img : grayscale image of cells, .inr or .inr.gz
19 6 akiss
 t_up,t_down : linear threshold value (inr)
20 6 akiss
 smooth : amount of gaussian blur to apply to the image
21 6 akiss
*/
22 6 akiss
23 6 akiss
#include <iostream>
24 6 akiss
#include <math.h>
25 6 akiss
#include <sstream>
26 6 akiss
#include <vector>
27 6 akiss
#include <fstream>
28 6 akiss
29 6 akiss
#include "lsm_lib.h"
30 6 akiss
31 6 akiss
using namespace cimg_library;
32 6 akiss
using namespace std;
33 6 akiss
34 6 akiss
//------------------------------------------------------------------------------
35 6 akiss
//Main
36 6 akiss
//------------------------------------------------------------------------------
37 6 akiss
int main (int argc, char* argv[])
38 6 akiss
{
39 6 akiss
  clock_t begin=clock();
40 6 akiss
41 6 akiss
  if(argc!=5)
42 6 akiss
    {
43 6 akiss
      cout<<"!! wrong number of arguments"<<endl;
44 6 akiss
      cout<<"Usage : contour_init img t_up t_down smooth"<<endl;
45 6 akiss
      cout<<"Examples for parameter values:"<<endl;
46 6 akiss
      cout<<"------------------------------"<<endl;
47 6 akiss
      cout<<"img : grayscale image of cells, (.inr or .inr.gz)"<<endl;
48 6 akiss
      cout<<"Upper threshold : t_up = 20"<<endl;
49 6 akiss
      cout<<"Down threshold : t_down = 5"<<endl;
50 6 akiss
      cout<<"Gaussian filter : smooth = 1 (0, if image already filtered)"<<endl;
51 6 akiss
      return 0;
52 6 akiss
    }
53 6 akiss
54 6 akiss
  //ckeck filename and read image
55 6 akiss
  string filename=argv[1];
56 6 akiss
  float tailleVoxel[3] = {0};// resolution initialisation
57 6 akiss
  CImg<float> img=imread(filename, tailleVoxel);
58 6 akiss
59 6 akiss
  //--------------------------------------------Parameters
60 6 akiss
  //linear threshold and smoothing
61 6 akiss
  int t_up=atoi(argv[2]);
62 6 akiss
  int t_down=atoi(argv[3]);
63 6 akiss
  float smooth=atof(argv[4]);
64 6 akiss
65 6 akiss
  //-------------------------------------------Names and directories
66 6 akiss
  //new name with arguments
67 6 akiss
  string ar2=argv[2];
68 6 akiss
  string ar3=argv[3];
69 6 akiss
  string ar4=argv[4];
70 6 akiss
  string insert="_initial"+ar2+"-"+ar3+"s"+ar4;
71 6 akiss
  filename.insert(filename.size()-4,insert);
72 6 akiss
73 6 akiss
  //-----------------------------------------Image Pre-processing
74 6 akiss
  //smooth image
75 6 akiss
  img.blur(smooth);
76 6 akiss
77 6 akiss
  //-------------------------------------------Initialization
78 6 akiss
  //initialize level-set
79 6 akiss
  CImg<unsigned char> segmented=threshold_linear_alongZ(img,t_up,t_down);
80 6 akiss
  int s=imsave(filename, tailleVoxel, segmented);
81 6 akiss
  return 0;
82 6 akiss
}