Révision 4
src/tiff2inr.cpp (revision 4) | ||
---|---|---|
1 |
/* |
|
2 |
Convert tif file into inr |
|
3 |
|
|
4 |
To compile : |
|
5 |
g++ -o tiff2inr tiff2inr.cpp -O2 -L/usr/X11R6/lib -lm -lpthread -lX11 -fopenmp -l:libtiff.so.5 |
|
6 |
Needs CImg.h |
|
7 |
|
|
8 |
To execute : |
|
9 |
./tiff2inr img.tif compress |
|
10 |
|
|
11 |
img : image in .tif |
|
12 |
compress : if 0 then output image is not compressed (img.inr), else the output is img.inr.gz |
|
13 |
|
|
14 |
*/ |
|
15 |
#include <iostream> |
|
16 |
#include <math.h> |
|
17 |
#include <sstream> |
|
18 |
#include <fstream> |
|
19 |
|
|
20 |
#define cimg_use_tiff |
|
21 |
#include "CImg.h" |
|
22 |
|
|
23 |
using namespace cimg_library; |
|
24 |
using namespace std; |
|
25 |
|
|
26 |
//----------------------------------------------------------------------------- |
|
27 |
//Main |
|
28 |
//----------------------------------------------------------------------------- |
|
29 |
int main (int argc, char* argv[]) |
|
30 |
{ |
|
31 |
|
|
32 |
if( argc>3 || argc<2 ) |
|
33 |
{ |
|
34 |
cout<<"tiff2inr : !! wrong number of arguments !!"<<endl; |
|
35 |
cout<<"Usage : tiff2inr img.tif compress"<<endl; |
|
36 |
return 0; |
|
37 |
} |
|
38 |
|
|
39 |
// ------------------- |
|
40 |
// Sparsing arguments |
|
41 |
// ------------------- |
|
42 |
string name=argv[1]; |
|
43 |
|
|
44 |
bool compress=true; |
|
45 |
if (argc==3) |
|
46 |
{ |
|
47 |
if (string(argv[2])=="0")compress=false; |
|
48 |
cout<<"Output file will not be compressed. "<<endl; |
|
49 |
} |
|
50 |
|
|
51 |
CImg<> img; |
|
52 |
CImg<char> description; |
|
53 |
float tailleVoxel[3] = {0}; |
|
54 |
|
|
55 |
if(name.compare(name.size()-4,4,".tif")==0) |
|
56 |
{ |
|
57 |
cout<<"The input file is a .tif file. OK"<<endl; |
|
58 |
} |
|
59 |
else |
|
60 |
{ |
|
61 |
cout<<"This is a tif file converter. Please give a .tif file as input."<<endl; |
|
62 |
return 0; |
|
63 |
} |
|
64 |
|
|
65 |
// ----------------------- |
|
66 |
// Reading the .tif image file |
|
67 |
// ----------------------- |
|
68 |
cout<<"File to read : "<<name<<endl; |
|
69 |
if(name.compare(name.size()-4,4,".tif")==0) |
|
70 |
{ |
|
71 |
cout<<"The input file is a .tif file."<<endl; |
|
72 |
} |
|
73 |
else |
|
74 |
{ |
|
75 |
cout<<"This is a tif file converter. Please give a .tif file as input."<<endl; |
|
76 |
return 0; |
|
77 |
} |
|
78 |
|
|
79 |
img.load_tiff(name.c_str(),0,~0U,1,tailleVoxel,&description); |
|
80 |
cout<<"Image depth : "<<img.depth()<<endl; |
|
81 |
cout<<"Voxel size : ("<<tailleVoxel[0]<<","<<tailleVoxel[1]<<","<<tailleVoxel[2]<<")"<<endl; |
|
82 |
|
|
83 |
|
|
84 |
// ----------------------- |
|
85 |
// Writing the .inr or .inr.gz file |
|
86 |
// ----------------------- |
|
87 |
|
|
88 |
name.erase(name.size()-4); |
|
89 |
string newname=name+string(".inr"); |
|
90 |
CImg<unsigned char> imgbis=img; |
|
91 |
img.assign(); |
|
92 |
imgbis.save_inr(newname.c_str(),tailleVoxel); |
|
93 |
imgbis.assign(); |
|
94 |
|
|
95 |
if (compress) |
|
96 |
{ |
|
97 |
string zip="gzip -f "+newname; |
|
98 |
if(system(zip.c_str())); |
|
99 |
} |
|
100 |
|
|
101 |
return 0; |
|
102 |
} |
Formats disponibles : Unified diff