 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
26 "Usage: btile [options] input.img/input.star output.img",
27 "------------------------------------------------------",
28 "Splits an image into overlapping tiles.",
29 "During tiling, the original size and tile origins are written into a text",
30 " file with the base of the output file name and the extension \".tiles\".",
31 "The program bpatch can reassemble the tiles using this text file.",
34 "-split Split into multiple images.",
37 "-verbose 7 Verbosity of output.",
38 "-datatype u Force writing of a new data type.",
39 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
40 "-size 120,150,70 Size of tiles (default 512,512,512).",
41 "-overlap 13,15,8 Overlap of tiles (default 0,0,0).",
42 "-first 5 Number given to the first file (default 0).",
43 "-digits 3 Number of digits inserted before the last period in the output file name (default 3).",
45 "Parameters for reconstructions:",
46 "-recid rec_1 Reconstruction ID to use.",
49 "-output output.star Output parameter file.",
54 int main(
int argc,
char **argv)
70 for ( curropt = option; curropt; curropt = curropt->
next ) {
71 if ( curropt->
tag ==
"split" )
split = 1;
72 if ( curropt->
tag ==
"datatype" )
74 if ( curropt->
tag ==
"sampling" )
75 sampling = curropt->
scale();
76 if ( curropt->
tag ==
"size" )
77 size = curropt->
size();
78 if ( curropt->
tag ==
"overlap" )
79 overlap = curropt->
size();
80 if ( curropt->
tag ==
"first" ) {
82 cerr <<
"-first: A number must be specified!" << endl;
83 if ( first_number < 0 ) first_number = 0;
85 if ( curropt->
tag ==
"digits" )
87 cerr <<
"-digits: A number of digits must be specified!" << endl;
88 if ( curropt->
tag ==
"recid" ) {
89 recid = curropt->
value;
91 cerr <<
"-recid: A reconstruction ID must be specified!" << endl;
93 if ( curropt->
tag ==
"output" )
100 Bstring filename = argv[optind++];
109 cerr <<
"Error: Reconstruction " << recid <<
" not found!" << endl;
112 filename = rec->
frec;
113 if ( sampling[0] > 0 ) rec->
voxel_size = sampling;
117 if ( p == NULL )
bexit(-1);
119 if ( optind >= argc )
bexit(0);
124 if ( argc > optind ) {
176 if ( digits < 2 ) digits = 2;
178 snprintf(format, 16,
"%%0%dd.", digits);
180 if ( size[0] < 1 ) size[0] = 512;
181 if ( size[1] < 1 ) size[1] = 512;
182 if ( size[2] < 1 ) size[2] = 512;
183 if ( size[0] > p->
sizeX() ) size[0] = p->
sizeX();
184 if ( size[1] > p->
sizeY() ) size[1] = p->
sizeY();
185 if ( size[2] > p->
sizeZ() ) size[2] = p->
sizeZ();
186 if ( overlap[0] < 0 ) overlap[0] = 0;
187 if ( overlap[1] < 0 ) overlap[1] = 0;
188 if ( overlap[2] < 0 ) overlap[2] = 0;
189 if ( overlap[0] > p->
sizeX() ) overlap[0] = p->
sizeX()/2;
190 if ( overlap[1] > p->
sizeY() ) overlap[1] = p->
sizeY()/2;
191 if ( overlap[2] > p->
sizeZ() ) overlap[2] = p->
sizeZ()/2;
193 int n, i = first_number;
197 filename = outputfile.
pre_rev(
'.') +
".tiles";
198 n = (p->
sizeX()/step[0] + 1)*(p->
sizeY()/step[1] + 1)*(p->
sizeZ()/step[2] + 1);
201 cout <<
"Splitting image " << p->
file_name() <<
" into tiles:" << endl;
202 cout <<
"Tile size: " << size << endl;
203 cout <<
"Overlap: " << overlap << endl;
204 cout <<
"Number of tiles: " << n << endl << endl;
207 ofstream fd(filename.
c_str());
208 if ( fd.fail() )
return 0;
211 fd << overlap[0] <<
" " << overlap[1] <<
" " << overlap[2] << endl;
213 for ( n=0, start[2]=0; start[2]<p->
sizeZ(); start[2]+=step[2] ) {
214 xsize[2] = p->
sizeZ() - (long)start[2];
215 if ( xsize[2] > size[2] ) xsize[2] = size[2];
216 for ( start[1]=0; start[1]<p->
sizeY(); start[1]+=step[1] ) {
217 xsize[1] = p->
sizeY() - (long)start[1];
218 if ( xsize[1] > size[1] ) xsize[1] = size[1];
219 for ( start[0]=0; start[0]<p->
sizeX(); start[0]+=step[0], i++ ) {
220 xsize[0] = p->
sizeX() - (long)start[0];
221 if ( xsize[0] > size[0] ) xsize[0] = size[0];
222 pone = p->
extract(0, start, xsize);
227 cout <<
"File " << i <<
": " << filename << endl;
230 fd << start[0] <<
" " << start[1] <<
" " << start[2] << endl;
239 cout <<
"Number of tiles: " << n << endl << endl;
A class for a command line input option.
int project_kill(Bproject *project)
Frees a whole project.
Vector3< double > scale()
Header file for file checking functions.
Vector3< double > voxel_size
int bexit(int value)
Exit function for cleanup and debugging.
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Vector3< long > size() const
Header file for option handlers.
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Header file for reading and writing micrograph parameters.
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
General image parameter class.
Utilities for timing functions.
Bimage * extract_tiles(long nn, vector< Vector3< long >> &coords, Vector3< long > tile_size)
Extracts a set of tiles at specified positions from an image into a new image.
double timer_start()
Starts timer and prints the time.
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Header file for general utilities.
vector< string > split(const string &s)
Splits a string on whitespace.
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void change_type(char letter)
Get the data type indicated by a single letter code.
Header file for 2D and 3D image I/O.
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Header file for micrograph processing.
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
void sampling(long nn, Vector3< double > u)
DataType
Base data type specifier.
int img_tile_with_overlap(Bimage *p, Bstring outputfile, Vector3< int > size, Vector3< int > overlap, int digits, int first_number, DataType nudatatype)
Writes overlapping tiles into new images.
int main(int argc, char **argv)
FileType file_type(const char *filename)
Checks the file type using the extension and contents.