| Bsoft 2.0.5 Bernard's software package

radonrecon.cpp
Go to the documentation of this file.
1
13 #include "mg_processing.h"
14 #include "rwmg.h"
15 #include "rwimg.h"
16 #include "img_radon.h"
17 #include "symmetry.h"
18 #include "utilities.h"
19 #include "options.h"
20
21 // Declaration of global variables
22 extern int verbose; // Level of output to the screen
23
24 // Usage assistence
25 const char *use[] = {
26 " ",
27 "Usage: radonrecon [options] input.star [input.star]",
28 "---------------------------------------------------",
29 "Program to reconstruct a quarter (PI*PI) radon transform from projections.",
30 "Projections must be square.",
31 " ",
32 "Parameters:",
33 "-verbose 7 Verbosity of output",
34 "-datatype u Force writing of a new data type (default output floating point)",
35 "-origin 32,32 Projections origin (default center of projections)",
36 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
37 "-kernel 15,4 Kernel size and power (default 11,2)",
38 "-threshold 19.4 Threshold for accepting a particle image (default 0)",
39 "-symmetry D5 Number of symmetry equivalents (default 1)",
40 " ",
41 "Output:",
42 "-output file.star Output parameter file.",
43 "-reconstruction rec.map Reconstruction file name.",
44 "-mask mask.map Binary mask for POCS filter.",
45 " ",
46 NULL
47 };
48
49 int
50 main (int argc, char **argv)
51 {
52 // Initialize variables
53 DataType newdatatype = Unknown_Type; // Conversion to new data type for the reconstruction
54 int rec_size(0); // Reconstruction size - default from particle image size
55 Vector3<double> origin; // Origin of reconstruction
56 Vector3<double> sampling; // Units for the three axes (A/pixel)
57 int n_theta(0); // Number of angular samples per 2*PI
58 int nkernel(11); // Kernel width
59 int kernel_power(2); // Kernel power
60 double threshold(0); // Threshold to accept particle images
61 Bsymmetry* sym = NULL; // Point group
62 Bstring outfile; // File name for parameter output
63 Bstring reconsfile; // File name for reconstruction
64 Bstring maskfile; // File name for mask file output
65
66 int sizeTable = 8;
67
68 int optind;
69 Boption *option = get_option_list (use, argc, argv, optind);
70 Boption *curropt;
71 for (curropt = option; curropt; curropt = curropt->next)
72 {
73 if ( curropt->tag == "datatype" )
74 newdatatype = curropt->datatype();
75 if ( curropt->tag == "origin" )
76 origin = curropt->origin();
77 if ( curropt->tag == "sampling" )
78 sampling = curropt->sampling();
79 if ( curropt->tag == "kernel" )
80 if ( curropt->values(nkernel, kernel_power) < 1)
81 cerr << "-kernel: At least the kernel size must be specified!" << endl;
82 if ( curropt->tag == "threshold" )
83 if ( ( threshold = curropt->value.real() ) < 1e-30)
84 cerr << "-threshold: The threshold must be specified!" << endl;
85 if ( curropt->tag == "symmetry" )
86 sym = curropt->symmetry();
87 if ( curropt->tag == "reconstruction" )
88 reconsfile = curropt->filename();
89 if ( curropt->tag == "output" )
90 outfile = curropt->filename();
91 if ( curropt->tag == "mask" )
92 maskfile = curropt->filename();
93 }
94 option_kill (option);
95
96 // Read all the parameter files
97 Bstring* file_list = NULL;
98 while ( optind < argc ) string_add(&file_list, argv[optind++]);
99 if ( !file_list ) {
100 cerr << "Error: No parameter files specified!" << endl;
101 bexit(-1);
102 }
103
104 Bproject* project = read_project(file_list);
105 string_kill(file_list);
106
107 if ( project == NULL ) {
108 cerr << "Error: No input file read!" << endl;
109 bexit(-1);
110 }
111
112
113 if (sampling[0] > 0)
114 {
115 if (sampling[0] < 0.1)
116 sampling[0] = 1;
117 project_set_pixel_size (project, sampling[0]);
118 }
119
120 Bimage *prec = img_radon_reconstruction (project, sym, maskfile, rec_size, n_theta, sizeTable, threshold, origin, nkernel, kernel_power);
121
122 if (prec && reconsfile.length())
123 {
124 prec->statistics();
125 prec->change_type(newdatatype);
126 prec->label(get_cmd_line(argc, argv));
127 write_img (reconsfile, prec, 0);
128 }
129
130 delete prec;
131
132 if (project && outfile.length())
133 {
134 project_update_comment (project, argc, argv);
135 write_project (outfile, project, 0, 0);
136 }
137
138 kill_symmetry(sym);
139 project_kill (project);
140
141 return 0;
142 }
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:320
rwmg.h
Header file for reading and writing micrograph parameters.
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
symmetry.h
Header file for general symmetry functions.
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
use
const char * use[]
Definition: radonrecon.cpp:25
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
Bstring::length
long length() const
Definition: Bstring.cpp:263
project
Bproject * project
Definition: bshow.cpp:31
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
img_radon.h
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
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
Bimage
General image parameter class.
Definition: Bimage.h:163
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:252
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
main
int main(int argc, char **argv)
Definition: radonrecon.cpp:50
Bsymmetry
Definition: symmetry.h:38
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
project_set_pixel_size
int project_set_pixel_size(Bproject *project, double pixel_size)
Sets the pixel size for all the micrographs.
Definition: mg_processing.cpp:3398
Vector3< double >
Boption::origin
Vector3< double > origin()
Definition: options.h:180
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
mg_processing.h
Header file for micrograph processing.
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
verbose
int verbose
project_update_comment
int project_update_comment(Bproject *project, int n, char **strings)
Puts a set of strings and time in the main comment of a project.
Definition: rwmg.cpp:468
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
img_radon_reconstruction
Bimage * img_radon_reconstruction(Bproject *project, Bsymmetry *sym, Bstring &file_mask, int rec_size, int ntheta, int table_size, double threshold, Vector3< double > origin, int nkernel, int kernel_power)
Reconstructs a Radon transform from a set of projections.
Definition: img_radon.cpp:292
Bproject
Definition: mg_processing.h:333
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:760