 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
19 "Usage: bint [options] input.img output.img",
20 "------------------------------------------",
21 "Applies geometric transformations requiring interpolation to 2D and 3D images.",
22 "The transformation is set up so that only a single interpolation is done",
23 "to preserve information as far as possible.",
26 "-size 10,50,8 New size (pixels).",
27 "-translate 0,-10,30 Translation after rotating (default 0,0,0).",
28 "-rotate -2.5,5.5,9,45 Rotate around a vector by an angle (default 0,0,0,0).",
29 "-toview 0.3,0.5,0.8,33 Rotate to view: vector {xyz} and angle (default 0,0,1,0).",
30 "-fromview 0.3,0.5,0.8,33 Rotate from view: vector {xyz} and angle (default 0,0,1,0).",
31 "-toeuler 16,120,85 Euler angle rotation: Phi, theta, psi (around axes z, y, z).",
32 "-fromeuler 16,120,85 Euler angle rotation: Psi, theta, phi (around axes z, y, z).",
33 "-scale 1.5,1.5,1.5 Relative scale (changes the units).",
34 "-enlarge 2,3,1 Enlarge the image by the given integer scale.",
35 "-integer 2,32 Special integer interpolation by given kernel size (changes units).",
36 " If old origin falls on a voxel, new origin also falls on a voxel.",
37 " Second value forces odd/even dimensions (default all odd).",
38 "-bin 3,2,1 Binning by given kernel size - one value = isotropic binning.",
39 " (i.e., 2 = binning with a 2x2 kernel, changes the units).",
40 "-median 3 Median binning (changes the units).",
41 "-invert Invert density in the image.",
42 "-slices Interpret multiple 2D images as z-slices of a single 3D image",
43 "-images Interpret slices of a single 3D image as 2D images",
44 "-rescale -0.1,5.2 Rescale output data to average and standard deviation.",
45 "-project Project a 3D image along the z-axis after transformation.",
46 "-Skew + + skews and - removes skewing (default off).",
49 "-verbose 7 Verbosity of output.",
50 "-datatype u Force writing of a new data type.",
51 "-sampling 1.2,0.7,2.0 Sampling before transformations (angstrom/pixel).",
52 "-newsampling 1.2,0.7,2.0 Sampling set after transformations (angstrom/pixel).",
53 "-origin 10,-10,20 Origin for rotation (default 0,0,0).",
54 "-neworigin 10,-10,20 Origin set after transformations.",
55 "-fill 127 Fill value for resizing (default background).",
56 "-unitcell 10,23,77,90,90,90 Unit cell parameters.",
61 int main(
int argc,
char **argv)
73 double nuavg(0), nustd(0);
78 int median_binning(0);
79 int integer_factor(0);
101 for ( curropt = option; curropt; curropt = curropt->
next ) {
102 if ( curropt->
tag ==
"datatype" )
104 if ( curropt->
tag ==
"invert" )
106 if ( curropt->
tag ==
"slices" )
108 if ( curropt->
tag ==
"images" )
110 if ( curropt->
tag ==
"rescale" ) {
111 if ( curropt->
values(nuavg, nustd) < 2 )
112 cerr <<
"-rescale: Both average and standard deviation must be specified!" << endl;
115 if ( nustd <= 0 ) setrescale = 0;
117 if ( curropt->
tag ==
"sampling" )
118 sampling = curropt->
scale();
119 if ( curropt->
tag ==
"newsampling" )
120 newsampling = curropt->
scale();
121 if ( curropt->
tag ==
"size" ) {
122 newsize = curropt->
size();
125 if ( curropt->
tag ==
"origin" ) {
126 if ( curropt->
value[0] ==
'c' ) {
129 origin = curropt->
origin();
133 if ( curropt->
tag ==
"neworigin" ) {
134 if ( curropt->
value[0] ==
'c' ) {
137 nuorigin = curropt->
origin();
141 if ( curropt->
tag ==
"translate" ) {
142 translate = curropt->
vector3();
146 cerr <<
"-translate: At least one translation value must be specified!" << endl;
148 if ( curropt->
tag ==
"rotate" ) {
149 if ( curropt->
values(axis[0], axis[1], axis[2], angle) < 4 )
150 cerr <<
"-rotate: All three vector elements and an angle must be specified!" << endl;
157 if ( curropt->
tag ==
"toview" ) {
158 view = curropt->
view();
163 if ( curropt->
tag ==
"fromview" ) {
164 view = curropt->
view();
168 if ( curropt->
tag ==
"toeuler" ) {
169 euler = curropt->
euler();
175 if ( curropt->
tag ==
"fromeuler" ) {
176 euler = curropt->
euler();
181 if ( curropt->
tag ==
"scale" ) {
182 scale = curropt->
scale();
186 cerr <<
"-scale: At least one value must be specified!" << endl;
188 if ( curropt->
tag ==
"enlarge" ) {
189 enlarge = curropt->
scale();
190 if ( enlarge.
volume() < 1 )
191 cerr <<
"-enlarge: All three values must be specified!" << endl;
193 if ( curropt->
tag ==
"integer" )
194 if ( curropt->
values(integer_factor, intbin_flag) < 1 )
195 cerr <<
"-integer: An integer must be specified!" << endl;
196 if ( curropt->
tag ==
"bin" ) {
197 if ( ( i = curropt->
values(bin[0], bin[1], bin[2]) ) < 1 )
198 cerr <<
"-bin: At least one bin size must be specified!" << endl;
200 if ( i < 2 ) bin[2] = bin[1] = bin[0];
202 if ( curropt->
tag ==
"median" )
203 if ( ( median_binning = curropt->
value.
integer() ) < 1 )
204 cerr <<
"-median: A binning size must be specified!" << endl;
205 if ( curropt->
tag ==
"project" )
207 if ( curropt->
tag ==
"Skew" ) {
214 cerr <<
"-Skew: A skewing direction (+/-) must be specified!" << endl;
218 if ( curropt->
tag ==
"fill" )
219 fill = curropt->
fill(fill_type);
220 if ( curropt->
tag ==
"unitcell" ) {
231 if ( optind < argc - 1 ) dataflag = 1;
234 cerr <<
"Error: No input file read!" << endl;
252 if ( fabs(scale.
volume()) < 0.001 ) {
253 cerr <<
"Error: Scales too small!" << endl;
257 if ( setinvert ) p->
invert();
267 if ( set_origin == 2 ) p->
origin(p->
size()/2);
273 else if ( median_binning )
275 else if ( integer_factor )
284 if ( settransform ) {
288 }
else if ( rotate ) {
289 if ( view[2] < 1 || view.
angle() != 0 ) {
294 }
else if ( angle != 0 ) {
295 if ( p->
sizeZ() < 2 ) {
296 axis[0] = axis[1] = 0;
304 cout <<
"View: " << view << endl;
307 if ( fabs(scale[0] - 1) < 1e-10 ) setresize += 1;
308 if ( fabs(scale[1] - 1) < 1e-10 ) setresize += 1;
309 if ( fabs(scale[2] - 1) < 1e-10 ) setresize += 1;
310 shift[0] = (long)floor(translate[0]+0.5);
311 shift[1] = (long)floor(translate[1]+0.5);
312 shift[2] = (long)floor(translate[2]+0.5);
313 if ( fabs(translate[0] - shift[0]) < 1e-10 ) setresize += 1;
314 if ( fabs(translate[1] - shift[1]) < 1e-10 ) setresize += 1;
315 if ( fabs(translate[2] - shift[2]) < 1e-10 ) setresize += 1;
317 if ( set_skew || rotate || setresize < 6 ) {
318 if ( newsize.
volume() < 1 ) newsize = p->
size();
323 p->
resize(newsize, shift, fill_type, fill);
327 cout <<
"DEBUG bint: Transformations done" << endl;
332 if ( setproject ) p->
project(
'z', 1);
336 if ( set_nuorigin ) {
337 if ( set_nuorigin == 2 ) p->
origin(p->
size()/2);
341 if ( optind < argc ) {
A class for a command line input option.
Vector3< double > scale()
Matrix3 transpose() const
int main(int argc, char **argv)
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.
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
Vector3< double > origin()
int enlarge(Vector3< long > scale)
Enlarges an image by an inetger scale.
int integer_interpolation(int integer_factor)
int images_to_slices()
Changes the 2D images to slices in a 3D image.
long values(T1 &v1, T2 &v2)
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
void origin(double x, double y, double z)
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 slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
General image parameter class.
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Utilities for timing functions.
double timer_start()
Starts timer and prints the time.
Vector3< double > vector3()
double fill(int &fill_type)
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void origin(double ox, double oy, double oz)
void change_type(char letter)
Get the data type indicated by a single letter code.
Header file for 2D and 3D image I/O.
Matrix3 skew_rotation(int invert)
int option_kill(Boption *option)
Deallocates a linked list of option structures.
void invert()
Inverts the data in the image.
void sampling(long nn, Vector3< double > u)
DataType
Base data type specifier.
bool contains(const Bstring &s)
int median_bin(int binning)
Bins by an integer size, selecting the kernel median.
int resize(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.