 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
21 double cutmin,
double cutmax,
double nuavg,
double nustd);
26 "Usage: bpatch [options] input.images/input.star",
27 "-----------------------------------------------",
28 "Patches a list of tiles together with overlap.",
29 "Requires a text file generated by btile that specifies the size and order of the tiles.",
30 "Any number of input images may be given and may include the wild card \"*\".",
31 "All images must have the same data type.",
34 "-verbose 3 Verbosity of output.",
35 "-datatype u Force writing of a new data type.",
36 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
37 "-origin 0.8,-10,15.7 Set the origin of the output image (default 0,0,0).",
38 "-size 1024,1024,120 Output image size (default from tile file).",
39 "-mode 1 Overlap handling: 0=average(default), 1=weigh, 2=central.",
40 "-rescale 127,27.5 Rescale all input data to average and standard deviation.",
41 "-truncate -5,5.5 Truncate data to minimum and maximum after rescaling.",
44 "-tiles text.tiles Text file with overall size and tile origins.",
47 "-output output.img Output image (default patch.pif).",
48 "-parameters file.star Output micrograph parameter file.",
53 int main(
int argc,
char **argv)
62 double nuavg(0), nustd(0);
63 double cutmin(0), cutmax(0);
71 for ( curropt = option; curropt; curropt = curropt->
next ) {
72 if ( curropt->
tag ==
"datatype" )
74 if ( curropt->
tag ==
"sampling" )
75 sampling = curropt->
scale();
76 if ( curropt->
tag ==
"origin" ) {
77 if ( curropt->
value[0] ==
'c' ) {
80 origin = curropt->
origin();
84 if ( curropt->
tag ==
"size" )
85 size = curropt->
size();
86 if ( curropt->
tag ==
"mode" )
88 if ( curropt->
tag ==
"rescale" )
89 if ( curropt->
values(nuavg, nustd) < 2 )
90 cerr <<
"-rescale: Both average and standard deviation must be specified!" << endl;
91 if ( curropt->
tag ==
"truncate" )
92 if ( curropt->
values(cutmin, cutmax) < 2 )
93 cerr <<
"-truncate: Both min and max must be specified!" << endl;
94 if ( curropt->
tag ==
"output" )
96 if ( curropt->
tag ==
"tiles" )
98 if ( curropt->
tag ==
"parameters" )
112 if ( argc - optind < 1 ) {
113 cerr <<
"Error: No tiles found!" << endl;
118 while ( optind < argc )
string_add(&file_list, argv[optind++]);
119 Bstring paramfile = *file_list;
135 ppatch =
img_patch(file_list, tile_file, nudatatype,
136 cutmin, cutmax, nuavg, nustd);
140 for (
long nn=0; nn<p->
images(); ++nn )
152 if ( set_origin == 2 ) ppatch->
origin(ppatch->
size()/2);
153 else ppatch->
origin(origin);
159 if ( outparam.
length() ) {
180 long i, j, c, x, y, z, xx, yy, zz;
186 cout <<
"Placing tile of size " << p->
size() <<
" at " << start << endl << endl;
188 for ( z=0; z<p->
sizeZ(); z++ ) {
191 if ( z >= overlap[2] && z < p->sizeZ() - overlap[2] ) w[2] = 1;
192 if ( zz <= overlap[2] ) w[2] = 1;
193 if ( zz >= ppatch->
sizeZ() - overlap[2] ) w[2] = 1;
194 for ( y=0; y<p->
sizeY(); y++ ) {
197 if ( y >= overlap[1] && y < p->sizeY() - overlap[1] ) w[1] = 1;
198 if ( yy <= overlap[1] ) w[1] = 1;
199 if ( yy >= ppatch->
sizeY() - overlap[1] ) w[1] = 1;
200 for ( x=0; x<p->
sizeX(); x++ ) {
203 if ( x >= overlap[0] && x < p->sizeX() - overlap[0] ) w[0] = 1;
204 if ( xx <= overlap[0] ) w[0] = 1;
205 if ( xx >= ppatch->
sizeX() - overlap[0] ) w[0] = 1;
209 for ( c=0; c<p->
channels(); c++, i++, j++ ) ppatch->
set(j, (*p)[i]);
234 double cutmin,
double cutmax,
double nuavg,
double nustd)
242 for ( file_ptr = file_list; file_ptr->
next; file_ptr = file_ptr->
next ) n++;
245 ifstream fd(tile_file.
c_str());
247 cerr <<
"Error: A text file specifying the size and tile origins must be given!" << endl;
251 fd >> size[0] >> size[1] >> size[2];
252 fd >> overlap[0] >> overlap[1] >> overlap[2];
256 for ( i=0; i<n; i++ )
257 fd >> tile_origin[i][0] >> tile_origin[i][1] >> tile_origin[i][2];
267 cout <<
"DEBUG img_patch: tilesize=" << tile_size <<
" overlap=" << overlap << endl;
268 cout <<
"DEBUG img_patch: tiles=" << n << endl;
276 if ( size != tile_origin[n-1] + p->
size() ) {
277 cerr <<
"Error: The expected size does not match the size given in file " << tile_file << endl;
278 cerr <<
" Expected size: " << tile_origin[n-1] + p->
size() << endl;
279 cerr <<
" Given size: " << size << endl;
280 cerr <<
" Make sure all the tiles are present." << endl;
293 cout <<
"Patching tiles:" << endl;
294 cout <<
"Size: " << size << endl;
295 cout <<
"Overlap: " << overlap << endl;
296 cout <<
"Number of tiles: " << n << endl << endl;
299 for ( i=0, file_ptr = file_list; i<n && file_ptr; i++, file_ptr = file_ptr->
next ) {
300 if ( ( p =
read_img(*file_ptr, 1, 0) ) ) {
304 if ( cutmin || cutmax )
315 delete[] tile_origin;
A class for a command line input option.
int project_kill(Bproject *project)
Frees a whole project.
Vector3< double > scale()
int string_kill(Bstring *list)
Kills a string linked list.
Header file for file checking functions.
void set(long j, double v)
Sets a single value at the given index.
int bexit(int value)
Exit function for cleanup and debugging.
Vector3< double > default_origin()
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.
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Vector3< double > origin()
long values(T1 &v1, T2 &v2)
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.
void origin(double x, double y, double z)
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Bimage * img_patch(Bstring *file_list, Bstring tile_file, DataType nudatatype, double cutmin, double cutmax, double nuavg, double nustd)
Assembles overlapping tiles into a single image.
General image parameter class.
CompoundType compound_type()
Utilities for timing functions.
int assemble_tiles(Bimage *pt, int flag=0)
Assembles overlapping tiles into this image.
int truncate_to_min_max(double minim, double maxim)
Truncates image data to a given minimum and maximum.
unsigned char * data_alloc_and_clear()
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.
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void origin(double ox, double oy, double oz)
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.
int main(int argc, char **argv)
int option_kill(Boption *option)
Deallocates a linked list of option structures.
void sampling(long nn, Vector3< double > u)
DataType
Base data type specifier.
Breconstruction * reconstruction_add(Breconstruction **rec, Bstring &rec_id)
Adds a reconstruction parameter structure to a linked list.
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
int img_pack_into_image(Bimage *p, Bimage *ppatch, Vector3< int > start, Vector3< int > overlap)
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.