 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
29 "Usage: bproject [options] input.img output.img",
30 "----------------------------------------------",
31 "Projects a 3D map and calculating comparison statistics of the projections.",
32 "If the input is a 2D image, it is assumed to be projections.",
35 "-axis y,2 Project down a major axis (x, y, z).",
36 " and a flag for minimum (1) or maximum (2).",
37 "-kernel 6,2 Reciprocal space projection: kernel size and power.",
38 "-average 7,5,3 Averaging/smoothing filter before projection: kernel size.",
39 "-rescale -0.1,5.2 Rescale data to average and standard deviation (after -truncate).",
40 "-View 0.3,-0.5,0.8,33 View to generate symmetry-related projections.",
41 "-Tilt -65,72,2.5,55 Tilt series of projections with angle min, max, step and axis angle.",
42 "-side 15 Generate side view projections within the given angle from the equator.",
43 "-compare 0.02,15 Compare projections, with the given SNR imposed and shift limit (default off).",
44 "-random 24 Generate a number of random projections.",
45 "-asu Change to views to fit into the asymmetric unit.",
46 "-edgewidth 80 Gaussian width of edge to background (default 0).",
49 "-verbose 7 Verbosity of output.",
50 "-datatype u Force writing of a new data type.",
51 "-origin 10,-10,20 Origin for rotation (voxels, default 0,0,0).",
52 "-sampling 2,3.5,1 Sampling (angstrom/voxel, a single value sets all three).",
53 "-resolution 15.6,200 High and low resolution limits (default 0,1e30).",
54 "-fill 127 Fill value for resizing: average (default), background, or value.",
55 "-symmetry D6 Symmetry: Point group identifier.",
56 "-angles 8,6 Step sizes for theta and phi in the asymmetric unit, one value sets both.",
57 "-noinplanerotation No in-plane rotations applied to projections (default applied).",
58 "-nonormalization No normalization applied to projections (default applied).",
59 "-unitcell 10,23,77,90,90,90 Unit cell parameters.",
62 "-Plotviews plot.ps Output postscript file with a plot of projection vectors.",
63 "-json views.json Output JSON file with views.",
64 "-Matrix cc.dat Projection comparison matrix.",
65 "-Map cc.map Projection comparison matrix in an image.",
70 int main(
int argc,
char **argv)
79 double nuavg(0), nustd(0);
83 double hires(0), lores(1e30);
87 double ang_min(0), ang_max(0), ang_step(0), ang_axis(0);
93 double compare_snr(0);
94 double shift_limit(-1);
112 for ( curropt = option; curropt; curropt = curropt->
next ) {
113 if ( curropt->
tag ==
"axis" ) {
114 if ( ( axis = curropt->
value[0] ) <
'a' )
115 cerr <<
"-axis: An axis for projection must be specified!" << endl;
121 if ( curropt->
tag ==
"kernel" )
122 if ( curropt->
values(kernel_width, kernel_power) < 1 )
123 cerr <<
"-kernel: At least the kernel size must be specified!" << endl;
124 if ( curropt->
tag ==
"average" ) {
125 if ( ( i = curropt->
values(average_kernel[0],
126 average_kernel[1], average_kernel[2]) ) < 1 )
127 cerr <<
"-average: The kernel edge size must be specified!" << endl;
129 if ( i < 2 ) average_kernel[2] = average_kernel[1] = average_kernel[0];
131 if ( curropt->
tag ==
"rescale" )
132 if ( curropt->
values(nuavg, nustd) < 2 )
133 cerr <<
"-rescale: Both average and standard deviation must be specified!" << endl;
134 if ( curropt->
tag ==
"datatype" )
136 if ( curropt->
tag ==
"origin" ) {
137 if ( curropt->
value[0] ==
'c' ) {
140 origin = curropt->
origin();
144 if ( curropt->
tag ==
"sampling" )
145 sam = curropt->
scale();
146 if ( curropt->
tag ==
"resolution" )
147 if ( curropt->
values(hires, lores) < 1 )
148 cerr <<
"-resolution: A resolution limit must be specified!" << endl;
149 if ( curropt->
tag ==
"fill" ) {
150 if ( ! ( fill = curropt->
value.
real() ) )
151 cerr <<
"-fill: A fill value must be specified!" << endl;
155 if ( curropt->
tag ==
"compare" )
156 if ( curropt->
values(compare_snr, shift_limit, lowpass) < 1 )
157 cerr <<
"-compare: A SNR value must be specified!" << endl;
158 if ( curropt->
tag ==
"asu" )
160 if ( curropt->
tag ==
"edgewidth" )
161 if ( ( edge_width = curropt->
value.
real() ) < 0.001 )
162 cerr <<
"-edgewidth: An edge width must be specified!" << endl;
163 if ( curropt->
tag ==
"random" )
165 cerr <<
"-random: A number of views must be specified!" << endl;
166 if ( curropt->
tag ==
"symmetry" )
168 if ( curropt->
tag ==
"angles" ) {
169 if ( ( i = curropt->
values(theta_step, phi_step) ) < 1 )
170 cerr <<
"-angles: An angle step size must be specified!" << endl;
172 theta_step *=
M_PI/180.0;
173 if ( i < 2 ) phi_step = theta_step;
174 else phi_step *=
M_PI/180.0;
177 if ( curropt->
tag ==
"unitcell" )
179 if ( curropt->
tag ==
"noinplanerotation" )
181 if ( curropt->
tag ==
"nonormalization" )
183 if ( curropt->
tag ==
"View" ) {
184 theview = curropt->
view();
185 symviews = ps_flag = 1;
187 if ( curropt->
tag ==
"Tilt" ) {
188 if ( curropt->
values(ang_min, ang_max, ang_step, ang_axis) < 3 )
189 cerr <<
"-Tilt: Three angles must be specified!" << endl;
191 ang_min *=
M_PI/180.0;
192 ang_max *=
M_PI/180.0;
193 ang_step *=
M_PI/180.0;
194 ang_axis *=
M_PI/180.0;
197 if ( curropt->
tag ==
"side" ) {
198 if ( ( side_ang = curropt->
value.
real() ) < 0.001 )
199 cerr <<
"-side: One angle must be specified!" << endl;
201 side_ang *=
M_PI/180.0;
203 if ( curropt->
tag ==
"Plotviews" )
205 if ( curropt->
tag ==
"json" )
207 if ( curropt->
tag ==
"Matrix" )
209 if ( curropt->
tag ==
"Map" )
217 fftwf_init_threads();
229 }
else if ( side_ang > -1 ) {
230 views =
side_views(sym, side_ang, theta_step, phi_step);
231 }
else if ( ang_step ) {
232 views =
tilt_views(ang_min, ang_max, ang_step, ang_axis);
233 }
else if ( symviews ) {
235 }
else if ( theta_step && phi_step ) {
242 cout <<
"Generating " << nviews <<
" projections" <<endl << endl;
245 ps_views(ps_file, symmetry_string, views, ps_flag);
247 string fn(js_file.
c_str());
252 }
else if ( axis ==
'z' ) {
253 views =
new View(0,0,1,0);
254 }
else if ( axis ==
'y' ) {
255 views =
new View(0,1,0,0);
256 }
else if ( axis ==
'x' ) {
257 views =
new View(1,0,0,0);
262 if ( optind >= argc ) {
268 if ( kernel_width > 1 )
273 if ( optind < argc - 1 ) dataflag = 1;
274 if ( compare_snr ) dataflag = 1;
277 if ( p == NULL )
bexit(-1);
287 if ( set_origin == 2 ) p->
origin(p->
size()/2);
300 proj = p->
project(axis, flags);
301 }
else if ( p->
sizeZ() > 1 && views ) {
305 proj = p->
project(views, !(view_flag&4));
311 (
int)(proj->
sizeY() - 2*edge_width), (
int)(proj->
sizeZ() - 2*edge_width));
312 origin[0] = origin[1] = origin[2] = edge_width;
313 if ( edge_width ) proj->
edge(1, size, origin, edge_width, fill_type, fill);
319 if ( compare_snr > 0 ) {
325 if ( map_file.
length() ) {
333 if ( optind < argc ) {
338 if ( p != proj )
delete p;
343 fftwf_cleanup_threads();
356 double hires,
double lores,
double radius,
double sigma,
365 for ( j=0; j<p->
images(); j++ ) {
381 if ( lores <= 0 ) lores = 1e30;
382 if ( hires < p->sampling(0)[0] ) hires = p->
sampling(0)[0];
383 if ( hires > lores ) swap(hires, lores);
384 if ( shift_limit < 0 ) shift_limit = 1e30;
403 dispatch_apply(n, dispatch_get_global_queue(0, 0), ^(
size_t i){
407 #pragma omp parallel for
408 for (
long i=0; i<n; i++ )
435 long i, j, m, n(p->
images()), nw(0), im;
436 double ccmax(0), ccmax1, ccavg(0), ccstd(0);
439 cout <<
"Image1\tImage2\tCC" << endl;
440 for ( j=0; j<n; ++j ) {
443 for ( i=0; i<n; ++i ) {
444 if ( ccmax1 < cc[i][j] ) {
448 if ( i == j ) ccmax += cc[i][j];
451 ccstd += cc[i][j]*cc[i][j];
454 cout << setprecision(5) << i <<
tab << j <<
tab << cc[i][j] << endl;
458 cout << j <<
tab << im <<
tab << ccmax1 << endl;
464 ccstd = ccstd/m - ccavg * ccavg;
465 if ( ccstd > 0 ) ccstd = sqrt(ccstd);
469 cout <<
"Correlating all projections:" << endl;
470 cout <<
"Imposed SNR: " << SNR << endl;
471 cout <<
"Resolution limits: " << hires <<
" " << lores << endl;
472 cout <<
"Shift limit: " << shift_limit << endl;
473 cout <<
"CC maximum: " << ccmax << endl;
474 cout <<
"CC average: " << ccavg << endl;
475 cout <<
"CC standard deviation: " << ccstd << endl;
476 cout <<
"Fraction incorrect: " << nw*1.0/n << endl;
477 cout <<
"Relative maximum sigma units: " << (ccmax - ccavg)/ccstd << endl;
496 unsigned long i, j, k, m, n(p->
images());
498 double ccmax, ccavg, ccstd, cct;
503 cout <<
"ResLim\tk\tCCmax\tCCavg\tCCstd\tCCth" << endl;
504 for ( hires = p->
sampling(0)[0]; hires < lores; hires *= 2 ) {
508 ccmax = ccavg = ccstd = 0;
509 for ( m=i=0; i<n; i++ ) {
510 for ( j=0; j<n; j++, m++ ) {
511 if ( i == j ) ccmax += cc[i][j];
514 ccstd += cc[i][j]*cc[i][j];
517 cout << setprecision(5) << i <<
tab << j <<
tab << cc[i][j] << endl;
524 ccstd = ccstd/m - ccavg * ccavg;
525 if ( ccstd > 0 ) ccstd = sqrt(ccstd);
528 k = (
unsigned long) (p->
real_size()[0]/hires);
531 if ( cct > 1 ) cct = 1;
532 cct = sqrt(SNR/(SNR + cct));
537 cout << hires <<
tab << k <<
tab << ccmax <<
tab << ccavg <<
tab << ccstd <<
tab << cct << endl;
549 for ( v = views; v; v = v->
next ) {
A class for a command line input option.
fft_plan fft_setup(fft_direction dir, int opt=0)
Sets up a plan for fast Fourier transforms.
Vector3< double > real_size()
Utility functions for matrices.
Vector3< double > scale()
View * symmetry_get_all_views(Bsymmetry *sym, View asu_view)
Get all symmetry-related views of one given view.
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.
size_t system_processors()
Returns the number of processors.
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Header file for general symmetry functions.
View * random_views(int nviews)
Calculates a set of random views.
void unit_cell(UnitCell uc)
int bexit(int value)
Exit function for cleanup and debugging.
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
double background(long nn)
Vector3< long > size() const
Header file for option handlers.
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
View * asymmetric_unit_views(Bsymmetry *sym, double theta_step, double phi_step, int flag)
Initializes a well-distributed set of views in an asymmetric unit.
int find_shift(Bimage *pref, Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Calculates a cross-correlation map to find the shift for the pair of images.
Vector3< double > origin()
long count_list(char *list)
Counts the number of items in a linked list.
double standard_deviation()
int change_views_to_asymmetric_unit(Bsymmetry *sym, View *view)
Change the views to those in the asymmetric unit.
Matrix img_compare_projections(Bimage *p, double SNR, double hires, double lores, double shift_limit)
Compares a set of projections from a 3D density map.
long values(T1 &v1, T2 &v2)
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Bimage * project(char axis, int flags=1)
Projects a 3D image to a 2D image down one of the three major axes.
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
int img_compare_projections_lowpass(Bimage *p, double SNR, double shift_limit)
Compares a set of projections from a 3D density map.
int noise_gaussian(double ravg=0, double rstd=1)
Generates an image with a gaussian random distribution of densities.
General image parameter class.
Utilities for timing functions.
Bstring symmetry_string()
int ps_views(Bstring &filename, Bstring &symmetry_string, View *view, int flags)
Generates postscript plot of views on the unit sphere.
void push_back(const JSvalue &val)
View * side_views(Bsymmetry *sym, double side_ang, double theta_step, double phi_step)
Initializes a set of views around the z-axis for helical projection.
double timer_start()
Starts timer and prints the time.
Header file for general utilities.
ostream & tab(ostream &out)
Bsymmetry * init_point_group_symmetry(Bstring symmetry_string)
Sets up a symmetry structure from a string identifier.
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void origin(double ox, double oy, double oz)
Matrix * img_compare_projections_driver(Bimage *p, double SNR, double hires, double lores, double shift_limit)
void change_type(char letter)
Get the data type indicated by a single letter code.
Header file for 2D and 3D image I/O.
View * tilt_views(double ang_min, double ang_max, double ang_step, double axis)
Initializes a set of views tilted around the y axis.
int filter_average(long kernel_size)
Applies an averaging filter to an image.
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
Header file for generalized linked list functions.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
void write(Bstring &filename)
int main(int argc, char **argv)
double fishers_z_transform(double value)
Calculates Fisher's z-transform.
void sampling(long nn, Vector3< double > u)
DataType
Base data type specifier.
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
void write(string filename)
double img_compare_one_projection(Bimage *p, Bimage *pref, long i, double hires, double lores, double radius, double sigma, Matrix *cc, fft_plan planf, fft_plan planb)
Header file for postscript tools dealing with views.
JSvalue js_views(View *views)
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.