| Bsoft 2.0.5 Bernard's software package

bmissing.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "rwmg.h"
11 #include "mg_tomo_rec.h"
12 #include "file_util.h"
13 #include "options.h"
14 #include "utilities.h"
15 #include "timer.h"
16
17 // Declaration of global variables
18 extern int verbose; // Level of output to the screen
19
20 // Usage assistance
21 const char* use[] = {
22 " ",
23 "Usage: bmissing [options] input.img/mg.star output.img",
24 "------------------------------------------------------",
25 "Generates binary masks corresponding to reciprocal space regions.",
26 "The selected regions have value 1 and the omitted regions 0.",
27 "The default is a blank mask created of the same size as the input image.",
28 " ",
29 "Actions for mask creation:",
30 "-create 20,60,30 Create a new mask of this size in place of input image",
31 " or using the micrograph orientations in the parameter file.",
32 "-find wedge Find the missing regions and create a new mask.",
33 " ",
34 "Actions for mask modification:",
35 "-wedge 45,-70,65 Missing wedge mask: tilt axis angle, first and last tilt angles.",
36 "-pyramid 40,-60,60,130,-55,60 Missing pyramid mask: 2 sets of tilt axis angle, first and last tilt angles.",
37 "-cone 65 Missing cone mask: one tilt angle.",
38 "-invert Invert mask just before writing the image.",
39 "-dilate 2 Dilate mask a number of times.",
40 " ",
41 "Parameters:",
42 "-verbose 1 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 "-origin 110,50,44 Origin for the mask (default 0,0,0).",
46 //"-fill 28.3 Fill value (default average).",
47 "-wrap Flag to wrap around image boundaries (default not).",
48 "-resolution 20 Resolution limit (angstrom, default Nyquist).",
49 " ",
50 "Parameters for micrograph orientations:",
51 "-scale 1.2 Scale or magnification of mask compared to original images (default 1).",
52 " ",
53 "Examples:",
54 "1. Creating a new mask:",
55 " bmissing -v 7 -create 100,100,50 -wedge 45,-60,65 -origin 50,50,25 mask.mrc",
56 " ",
57 "2. Generating a mask from an image:",
58 " bmissing -v 7 -pyramid 30,-30,70,120,-60,50 -wrap input.map mask.mrc",
59 " ",
60 "3. Generating a mask from micrograph orientations:",
61 " bmissing -v 7 -create 100,100,50 -wrap mg.star mask.pif",
62 " ",
63 NULL
64 };
65
66 int main(int argc, char **argv)
67 {
68 // Initialize variables
69 DataType nudatatype(Unknown_Type); // Conversion to new type
70 Vector3<double> sam; // Units for the three axes (A/pixel)
71 int invert(0); // Inversion flag
72 // int operation(1); // Default operation is and
73 Vector3<long> nusize; // Size of new mask
74 Bstring find; // Type of missing regions to find in input image
75 double tilt_axis(0); // Tilt axis angle
76 double tilt_neg(0); // First or negative tilt angle
77 double tilt_pos(0); // Last or positive tilt angle
78 double tilt_axis2(0); // Tilt axis angle
79 double tilt_neg2(0); // First or negative tilt angle
80 double tilt_pos2(0); // Last or positive tilt angle
81 double tilt_cone(0); // Cone tilt angle
82 int dilate(0); // Number of times to dilate
83 int set_origin(0); // Flag to set origin
84 Vector3<double> ori; // Mask origin
85 // int wrap(0); // Flag to wrap
86 double scale(1); // Scale or magnification of mask compared to original images
87 double resolution(0); // Must be set > 0 to limit resolution
88 // int fill_type = FILL_USER; // Use 1
89 // double fill = 1; // Default fill is 1
90
91 int i, optind;
92 Boption* option = get_option_list(use, argc, argv, optind);
93 Boption* curropt;
94 for ( curropt = option; curropt; curropt = curropt->next ) {
95 if ( curropt->tag == "create" )
96 nusize = curropt->size();
97 if ( curropt->tag == "find" )
98 find = curropt->value;
99 if ( curropt->tag == "datatype" )
100 nudatatype = curropt->datatype();
101 if ( curropt->tag == "sampling" )
102 sam = curropt->sampling();
103 if ( curropt->tag == "wedge" ) {
104 if ( ( i = curropt->values(tilt_axis, tilt_neg, tilt_pos) ) < 2 )
105 cerr << "-wedge: At least the tilt axis and one angle must be specified" << endl;
106 else {
107 tilt_axis *= M_PI/180.0;
108 tilt_neg *= M_PI/180.0;
109 tilt_pos *= M_PI/180.0;
110 if ( i < 3 ) tilt_pos = tilt_neg;
111 }
112 }
113 if ( curropt->tag == "pyramid" ) {
114 vector<double> d = curropt->value.split_into_doubles(",");
115 if ( d.size() < 4 )
116 cerr << "-pyramid: At least the four angles must be specified" << endl;
117 else {
118 tilt_axis = d[0] * M_PI/180.0;
119 tilt_neg = d[1] * M_PI/180.0;
120 tilt_pos = d[2] * M_PI/180.0;
121 tilt_axis2 = d[3] * M_PI/180.0;
122 if ( d.size() < 5 ) tilt_neg2 = tilt_neg;
123 else tilt_neg2 = d[4] * M_PI/180.0;
124 if ( d.size() < 6 ) tilt_pos2 = tilt_pos;
125 else tilt_pos2 = d[5] * M_PI/180.0;
126 }
127 }
128 if ( curropt->tag == "cone" ) {
129 if ( ( tilt_cone = curropt->value.real() ) < 1 )
130 cerr << "-cone: A tilt angle must be specified" << endl;
131 else
132 tilt_cone *= M_PI/180.0;
133 }
134 if ( curropt->tag == "dilate" )
135 if ( ( dilate = curropt->value.integer() ) < 1 )
136 cerr << "-dilate: A number of times to dilate must be specified!" << endl;
137 if ( curropt->tag == "origin" ) {
138 if ( curropt->value[0] == 'c' ) {
139 set_origin = 2;
140 } else {
141 ori = curropt->origin();
142 set_origin = 1;
143 }
144 }
145 // if ( curropt->tag == "fill" )
146 // fill = curropt->fill(fill_type);
147 // if ( curropt->tag == "wrap" ) wrap = 1;
148 if ( curropt->tag == "invert" ) invert = 1;
149 /* if ( curropt->tag == "operation" ) {
150 if ( curropt->value.contains("xor") ) operation = 3;
151 else if ( curropt->value.contains("or") ) operation = 2;
152 else if ( curropt->value.contains("and") ) operation = 1;
153 else operation = 0;
154 }*/
155 if ( curropt->tag == "resolution" )
156 if ( ( resolution = curropt->value.real() ) < 0.001 )
157 cerr << "-resolution: A resolution limit must be specified!" << endl;
158 if ( curropt->tag == "scale" )
159 if ( ( scale = curropt->value.real() ) < 0.0001 )
160 cerr << "-scale: A scale must be specified!" << endl;
161 }
162 option_kill(option);
163
164 double ti = timer_start();
165
166 Bimage* p = NULL;
167 Bproject* project = NULL;
168 Bstring filename(argv[optind++]);
169
170 if ( nusize.volume() > 0 ) { // Create the mask in place of an input image
171 if ( access(filename.c_str(), F_OK) ) {
172 if ( verbose & VERB_PROCESS )
173 cout << "Creating a mask of size: " << nusize << endl;
174 if ( nudatatype == Unknown_Type ) nudatatype = UCharacter;
175 p = new Bimage(nudatatype, TSimple, nusize, 1);
176 // operation = 0; // Default operation is replace
177 // fill = 1;
178 } else if ( file_type(filename) == Micrograph ) {
179 if ( nusize.volume() < 1 ) {
180 cerr << "Error: A mask size must be specified!" << endl;
181 bexit(-1);
182 }
183 project = read_project(filename);
184 p = project_missing_mask(project, nusize, ori, resolution, scale);
185 project_kill(project);
186 filename = argv[optind];
187 } else {
188 cerr << "Error: " << filename << " already exists!" << endl;
189 }
190 } else {
191 p = read_img(filename, 1, -1);
192 if ( p == NULL ) bexit(-1);
193 // if ( fill_type == FILL_AVERAGE ) fill = p->avg;
194 // if ( fill_type == FILL_BACKGROUND ) fill = p->image[0].background();
195 filename = argv[optind];
196 }
197
198 if ( p == NULL ) bexit(-1);
199
200 if ( set_origin ) {
201 if ( set_origin == 2 ) p->origin(p->default_origin());
202 else p->origin(ori);
203 ori = p->image->origin();
204 }
205
206 if ( sam.volume() > 0 ) p->sampling(sam);
207
208 if ( !project ) {
209 if ( find.length() )
210 p->mask_missing_find(ori, resolution, find);
211 else if ( tilt_pos2 )
212 p->mask_missing_pyramid(ori, tilt_axis, tilt_axis2,
213 tilt_neg, tilt_pos, tilt_neg2, tilt_pos2, resolution);
214 else if ( tilt_pos )
215 p->mask_missing_wedge(ori, tilt_axis, tilt_neg, tilt_pos, resolution);
216 else if ( tilt_cone )
217 p->mask_missing_cone(ori, tilt_cone, resolution);
218 }
219
220 if ( invert ) p->mask_invert();
221
222 if ( dilate > 0 )
223 p->mask_dilate(dilate);
224
225 p->mask_stats();
226
227 if ( filename.length() ) {
228 p->change_type(nudatatype);
229 p->label(get_cmd_line(argc, argv));
230 write_img(filename, p, 0);
231 }
232
233 delete p;
234
235 if ( verbose & VERB_TIME )
236 timer_report(ti);
237
238 bexit(0);
239 }
240
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
rwmg.h
Header file for reading and writing micrograph parameters.
Bstring::real
double real()
Definition: Bstring.cpp:545
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Bimage::mask_stats
long mask_stats()
Calculates statistics for a mask.
Definition: Bimage_mask.cpp:165
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
Bimage::mask_invert
long mask_invert()
Inverts a mask.
Definition: Bimage_mask.cpp:221
main
int main(int argc, char **argv)
Definition: bmissing.cpp:66
file_type
FileType file_type(const char *filename)
Checks the file type using the extension and contents.
Definition: file_util.cpp:178
read_project
Bproject * read_project(const char *filename, int flags=0)
Reading micrograph parameters from files.
Definition: rwmg.cpp:140
use
const char * use[]
Definition: bmissing.cpp:21
Bstring::length
long length() const
Definition: Bstring.cpp:263
project
Bproject * project
Definition: bshow.cpp:31
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
verbose
int verbose
Bimage::mask_missing_cone
long mask_missing_cone(Vector3< double > origin, double mis_ang, double resolution)
Generates a mask with a missing cone.
Definition: Bimage_mask.cpp:1068
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
TSimple
Definition: Bimage.h:58
timer.h
Utilities for timing functions.
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
Micrograph
Definition: file_util.h:23
M_PI
#define M_PI
Definition: utilities.h:59
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
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
file_util.h
Header file for file checking functions.
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:665
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
project_missing_mask
Bimage * project_missing_mask(Bproject *project, Vector3< long > size, Vector3< double > origin, double hi_res, double scale)
Creates a reciprocal space mask from the tilt series orientations.
Definition: mg_tomo_rec.cpp:1594
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
UCharacter
Definition: utilities.h:149
Bstring
Definition: Bstring.h:29
project_kill
int project_kill(Bproject *project)
Frees a whole project.
Definition: mg_processing.cpp:1224
Bimage::default_origin
Vector3< double > default_origin()
Definition: Bimage.h:585
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
mg_tomo_rec.h
Functions to do a tomographic reconstruction.
Bimage::mask_dilate
long mask_dilate(long times=1)
Dilates a binary mask.
Definition: Bimage_mask.cpp:424
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
Bimage::mask_missing_pyramid
long mask_missing_pyramid(Vector3< double > origin, double tilt_axis1, double tilt_axis2, double tilt_neg1, double tilt_pos1, double tilt_neg2, double tilt_pos2, double resolution)
Generates a mask with a missing pyramid.
Definition: Bimage_mask.cpp:981
Vector3::volume
double volume()
Definition: Vector3.h:235
Bimage::mask_missing_find
long mask_missing_find(Vector3< double > ori, double resolution, Bstring &mis_type)
Generates a missing mask from an example image.
Definition: Bimage_mask.cpp:1140
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
Bproject
Definition: mg_processing.h:333
Bimage::mask_missing_wedge
long mask_missing_wedge(Vector3< double > origin, double tilt_axis, double tilt_neg, double tilt_pos, double resolution)
Generates a mask with a missing wedge.
Definition: Bimage_mask.cpp:899
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563