| Bsoft 2.0.5 Bernard's software package

bftr.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "utilities.h"
11 #include "options.h"
12 #include "timer.h"
13
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16
17 /* Usage assistance */
18 const char* use[] = {
19 " ",
20 "Usage: bftr [options] file.spi file.mrc",
21 "---------------------------------------",
22 "Resizing an image using Fourier transformation.",
23 " ",
24 "Actions:",
25 "-scale 1.56 Isotropic scale (required to resize the data).",
26 "-translate 0.3,-4.1,3.3 Translation.",
27 "-bandpass 25.3,200 Bandpass filter: resolution limits (angstrom).",
28 "-filterextremes Remove extreme regions (such as micrograph labels)",
29 " ",
30 "Parameters:",
31 "-verbose 7 Verbosity of output",
32 "-datatype u Force writing of a new data type",
33 "-origin 0,-10,30 Set origin, used with -size option (default 0,0,0)",
34 "-size 22,33,14 New size (voxels, default from data)",
35 "-sampling 2,3.5,1 Sampling before rescaling (angstrom/voxel, a single value sets all three)",
36 " ",
37 "Input:",
38 "-reference ref.map Reference for resizing.",
39 " ",
40 NULL
41 };
42
43 int main(int argc, char **argv)
44 {
45 // Initialize variables
46 DataType nudatatype(Unknown_Type); // Conversion to new type
47 Vector3<long> size; // New size
48 Vector3<double> shift; // Translation
49 double scale(0); // Scale, 0=no scaling
50 Vector3<double> origin; // Origin
51 int set_origin(0); // Flag for setting the origin
52 Vector3<double> sam; // Sampling before rescaling
53 double res_hi(0); // High resolution limit
54 double res_lo(1e37); // Low resolution limit
55 int filter_extremes(0); // Filter extreme regions
56 Bstring reffile; // Reference template file name
57
58 int optind;
59 Boption* option = get_option_list(use, argc, argv, optind);
60 Boption* curropt;
61 for ( curropt = option; curropt; curropt = curropt->next ) {
62 if ( curropt->tag == "datatype" )
63 nudatatype = curropt->datatype();
64 if ( curropt->tag == "origin" ) {
65 if ( curropt->value[0] == 'c' ) {
66 set_origin = 2;
67 } else {
68 origin = curropt->origin();
69 set_origin = 1;
70 }
71 }
72 if ( curropt->tag == "scale" )
73 if ( ( scale = curropt->value.real() ) < 0.001 )
74 cerr << "-scale: A scale must be specified!" << endl;
75 if ( curropt->tag == "translate" )
76 shift = curropt->vector3();
77 if ( curropt->tag == "bandpass" ) {
78 if ( curropt->values(res_hi, res_lo) < 1 )
79 cerr << "-bandpass: The resolution limits must be specified!" << endl;
80 else
81 if ( res_hi > res_lo ) swap(res_hi, res_lo);
82 }
83 if ( curropt->tag == "size" )
84 size = curropt->size();
85 if ( curropt->tag == "sampling" )
86 sam = curropt->sampling();
87 if ( curropt->tag == "filterextremes" )
88 filter_extremes = 1;
89 if ( curropt->tag == "reference" )
90 reffile = curropt->filename();
91 }
92 option_kill(option);
93
94 double ti = timer_start();
95
96 Bimage* p = NULL;
97 Bimage* pref = NULL;
98 Bimage* pt = NULL;
99
100 if ( ( p = read_img(argv[optind++], 1, -1) ) == NULL ) {
101 cerr << "File not read!" << endl;
102 exit(-1);
103 }
104
105 if ( reffile.length() ) {
106 if ( ( pref = read_img(reffile, 1, -1) ) == NULL ) {
107 cerr << "File " << reffile << " not read!" << endl;
108 exit(-1);
109 }
110 }
111
112 if ( nudatatype == Unknown_Type )
113 nudatatype = p->data_type();
114
115 if ( sam.volume() > 0 ) p->sampling(sam);
116
117 if ( set_origin ) {
118 if ( set_origin == 2 ) p->origin(p->size()/2);
119 else p->origin(origin);
120 }
121
122 Vector3<long> translate;
123 if ( optind < argc ) {
124 if ( filter_extremes )
125 p->filter_extremes();
126 if ( shift.length() )
127 p->fspace_translate(shift);
128 if ( scale ) {
129 p->fspace_resize(scale, res_hi, res_lo);
130 } else if ( reffile.length() ) {
131 pt = p->fspace_resize(pref);
132 delete p;
133 p = pt;
134 }
135 if ( size.volume() > 0 )
136 p->resize(size, translate, FILL_BACKGROUND, 0);
137 p->change_type(nudatatype);
138 p->label(get_cmd_line(argc, argv));
139 write_img(argv[optind], p, 0);
140 }
141
142 delete p;
143 delete pref;
144
145 if ( verbose & VERB_TIME )
146 timer_report(ti);
147
148 bexit(0);
149 }
150
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bstring::real
double real()
Definition: Bstring.cpp:545
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:174
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Vector3::length
double length()
Definition: Vector3.h:222
Bimage::fspace_translate
int fspace_translate(Vector3< double > shift)
Translates an image in frequency space to avoid interpolation.
Definition: Bimage_fspace.cpp:150
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bimage::fspace_resize
int fspace_resize(double scale, double res_hi, double res_lo)
Resizes an image in frequency space to avoid interpolation.
Definition: Bimage_fspace.cpp:205
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
Bimage::resize
int resize(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
Definition: Bimage_resize.cpp:28
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
use
const char * use[]
Definition: bftr.cpp:18
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
verbose
int verbose
Boption::datatype
DataType datatype()
Definition: options.h:93
Bimage::filter_extremes
int filter_extremes()
Filters the extremes out of a micrograph image.
Definition: Bimage_segment.cpp:634
Boption::next
Boption * next
Definition: options.h:28
main
int main(int argc, char **argv)
Definition: bftr.cpp:43
Bstring
Definition: Bstring.h:29
Boption::vector3
Vector3< double > vector3()
Definition: options.h:148
Vector3< long >
Boption::origin
Vector3< double > origin()
Definition: options.h:180
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
Vector3::volume
double volume()
Definition: Vector3.h:235
Bimage::data_type
DataType data_type()
Definition: Bimage.h:349
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:273
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563