| Bsoft 2.0.5 Bernard's software package

jave.cpp
Go to the documentation of this file.
1
16 #include "rwimg.h"
17 #include "img_combine.h"
18 #include "utilities.h"
19 #include "options.h"
20 #include "timer.h"
21 #include "mg_subtomo.h"
22
23 // Declaration of global variables
24 extern int verbose; // Level of output to the screen
25
26 // Usage assistance
27 const char* use[] = {
28 " ",
29 "Usage: jave [options] input.images",
30 "----------------------------------",
31 "Averages multiple images together.",
32 "The average can be weighed with a weighting function,",
33 "either in real or Fourier space.",
34 " ",
35 "Actions:",
36 "-sum Sum input files (default is to average).",
37 "-rescale -0.1,5.2 Rescale input images to average and standard deviation.",
38 "-divide Values / amplitudes are divided with the weighting function (default).",
39 "-multiply Values / amplitudes are multiplied with the weighting function.",
40 " ",
41 "Parameters:",
42 "-verbose 7 Verbosity of output.",
43 "-datatype u Force writing of a new data type.",
44 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
45 //"-size 50,50,50 Size of the output image (one value sets all).",
46 "-translate Translate images to a common origin.",
47 "-origin 0.8,-10,15.7 Set the origin.",
48 "-wiener 0.1 Wiener factor for dividing (default 0.2).",
49 " ",
50 "Input:",
51 "-weight input.img Real space weighting function.",
52 "-Weight input.img Fourier space weighting function.",
53 " ",
54 "Output:",
55 "-output output.img Output image.",
56 NULL
57 };
58
59 int main(int argc, char **argv)
60 {
61 // Initialize variables
62 DataType nudatatype(Unknown_Type); // Conversion to new type
63 Vector3<double> sampling; // Units for the three axes (A/pixel)
64 Vector3<double> origin; // New image origin
65 int set_origin(0); // Flag to set origin
66 int divide(1), multiply(0);
67 Vector3<long> size(0,0,0); // Boxsize for extracting particles
68 Bstring outfile;
69 Bstring fomfile;
70 double nuavg(0), nustd(0); // Average and standard deviation for rescaling
71 double wiener(0.2);
72 int setweight(0);
73 int flags(1); // Flags to modify summation
74 Vector3<double> shift;
75
76 int optind;
77 Boption* option = get_option_list(use, argc, argv, optind);
78 Boption* curropt;
79
80 for ( curropt = option; curropt; curropt = curropt->next ) {
81 if ( curropt->tag == "datatype")
82 nudatatype = curropt->datatype();
83 if ( curropt->tag == "sampling")
84 sampling = curropt->sampling();
85 if ( curropt->tag == "origin") {
86 if ( curropt->value[0] == 'c' ) {
87 set_origin = 2;
88 } else {
89 origin = curropt->origin();
90 set_origin = 1;
91 }
92 }
93 if ( curropt->tag == "rescale")
94 if ( curropt->values(nuavg, nustd) < 2 )
95 cerr << "-rescale: Both average and standard deviation must be specified" << endl;
96 if ( curropt->tag == "wiener" )
97 if ( ( wiener = curropt->value.real() ) < 1e-10 )
98 cerr << "-wiener: Wiener factor larger than 0 must be specified" << endl;
99 if ( curropt->tag == "Weight") {
100 fomfile = curropt->filename();
101 setweight = 1;
102 }
103 if ( curropt->tag == "weight") {
104 fomfile = curropt->filename();
105 setweight = 2;
106 }
107 if ( curropt->tag == "size") {
108 size = curropt->size();
109 if ( size.volume() < 1 )
110 cerr << "-size: A box size must be specified." << endl;
111 }
112 if ( curropt->tag == "sum") {
113 flags -= 1;
114 }
115 if ( curropt->tag == "divide") {
116 divide = 1;
117 multiply = 0;
118 }
119 if ( curropt->tag == "multiply") {
120 multiply = 1;
121 divide = 0;
122 }
123 if ( curropt->tag == "translate") {
124 flags |= 8;
125 }
126 if ( curropt->tag == "output")
127 outfile = curropt->filename();
128 }
129
130 option_kill(option);
131
132 if ( verbose && argc < 3 ) {
133 cerr << "Error: No input files given!" << endl << endl;
134 bexit(-1);
135 }
136
137 double ti = timer_start();
138
139 if ( optind >= argc ) {
140 cerr << "No input files!" << endl;
141 bexit(-1);
142 }
143
144 // Set up image file names
145 int nfiles(0);
146 Bstring* file_list = NULL;
147 while ( optind < argc ) {
148 string_add(&file_list, argv[optind++]);
149 nfiles++;
150 }
151
152 // calculate average
153 vector<double> weight;
154 Bimage* psum = img_add_weighed(file_list, weight, nuavg, nustd, flags);
155
156 // Masking / amplitude weighting
157 if ( setweight > 0 ) {
158 Bimage* pw = read_img(fomfile, 1, -1);
159
160 // Weigh amplitudes in Fourier space with values read from a file
161 if ( setweight == 1 ) {
162
163 psum->fft();
164
165 if ( divide ) psum->divide(pw, wiener);
166 if ( multiply ) psum->multiply(pw);
167
168 psum->fft_back();
169 }
170 // Weigh values in real space with values read from a file
171 if ( setweight == 2 ) {
172
173 if ( divide ) psum->divide(pw, wiener);
174 if ( multiply ) psum->multiply(pw);
175 }
176
177 delete pw;
178 }
179
180 if ( sampling > 0 ) psum->sampling(sampling);
181
182 if ( set_origin ) psum->origin(origin);
183 if ( set_origin ) {
184 if ( set_origin == 2 ) psum->origin(psum->size()/2);
185 else psum->origin(origin);
186 }
187
188 if ( outfile.length() ) {
189 psum->change_type(nudatatype);
190 psum->label(get_cmd_line(argc, argv));
191 write_img(outfile, psum, 0);
192 }
193
194 delete psum;
195 string_kill(file_list);
196
197 if ( verbose & VERB_TIME )
198 timer_report(ti);
199
200 bexit(0);
201 }
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
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:705
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
use
const char * use[]
Definition: jave.cpp:27
Bimage::fft
int fft()
Definition: Bimage.h:822
Bimage::fft_back
int fft_back()
Definition: Bimage.h:823
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
main
int main(int argc, char **argv)
Definition: jave.cpp:59
Boption::tag
Bstring tag
Definition: options.h:29
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bimage::multiply
void multiply(long j, Complex< double > cv)
Definition: Bimage.h:312
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.
img_add_weighed
Bimage * img_add_weighed(Bstring *file_list, vector< double > weight, double newavg=0, double newstd=0, int flags=0)
Adds multiple images together with given weights.
Definition: img_combine.cpp:288
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
verbose
int verbose
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
img_combine.h
Header file for combining two images in various ways.
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
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Vector3< double >
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
Bimage::divide
void divide(Bimage *p, double scale=1, double shift=0)
Divides the first image by the second.
Definition: Bimage.cpp:3579
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
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
mg_subtomo.h
Header file for functions finding particles (subtomograms) in a tomogram.
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
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760