Bsoft  2.1.0
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->scale();
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;
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  write_img (reconsfile, prec, 0);
127  }
128 
129  delete prec;
130 
131  if (project && outfile.length())
132  write_project (outfile, project, 0, 0);
133 
134  kill_symmetry(sym);
136 
137  return 0;
138 }
Boption
A class for a command line input option.
Definition: options.h:26
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:429
Boption::scale
Vector3< double > scale()
Definition: options.h:190
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:768
use
const char * use[]
Definition: radonrecon.cpp:25
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
Bstring
Definition: Bstring.h:29
Boption::datatype
DataType datatype()
Definition: options.h:93
symmetry.h
Header file for general symmetry functions.
Boption::next
Boption * next
Definition: options.h:28
Vector3< double >
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:280
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
Bstring::real
double real()
Definition: Bstring.cpp:553
options.h
Header file for option handlers.
Boption::origin
Vector3< double > origin()
Definition: options.h:180
Bsymmetry
Definition: symmetry.h:38
Boption::symmetry
Bsymmetry * symmetry()
Definition: options.h:240
img_radon.h
project
Bproject * project
Definition: bshow.cpp:33
Boption::tag
Bstring tag
Definition: options.h:29
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
rwmg.h
Header file for reading and writing micrograph parameters.
project_set_mg_pixel_size
int project_set_mg_pixel_size(Bproject *project, Vector3< double > pixel_size)
Sets the pixel size for all the micrographs.
Definition: mg_processing.cpp:1997
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
main
int main(int argc, char **argv)
Definition: radonrecon.cpp:50
Boption::value
Bstring value
Definition: options.h:30
Bimage
General image parameter class.
Definition: Bimage.h:177
Bproject
Definition: mg_processing.h:336
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:141
utilities.h
Header file for general utilities.
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
rwimg.h
Header file for 2D and 3D image I/O.
write_project
int write_project(const char *filename, Bproject *project)
Writing micrograph parameters to a file.
Definition: rwmg.cpp:321
mg_processing.h
Header file for micrograph processing.
verbose
int verbose
kill_symmetry
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Definition: symmetry.cpp:207
Boption::filename
Bstring filename()
Definition: options.h:85
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
DataType
DataType
Base data type specifier.
Definition: utilities.h:150
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:713
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22