| Bsoft 2.0.5 Bernard's software package

bcomplex.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "utilities.h"
11 #include "options.h"
12 #include "timer.h"
13
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16
17 // Usage assistance
18 const char* use[] = {
19 " ",
20 "Usage: bcomplex [options] input.img output.img",
21 "----------------------------------------------",
22 "Converts complex image forms.",
23 " ",
24 "Actions:",
25 "-size 120,102,200 Resize the image as a Fourier transform.",
26 "-logarithm Calculate the logarithm of the image.",
27 "-amplitudes Convert a complex image to amplitudes.",
28 "-intensities Convert a complex image to intensities.",
29 "-real Convert a complex image to real values.",
30 "-imaginary Convert a complex image to imaginary values.",
31 "-phases Convert a complex image to phases.",
32 "-signed Convert a complex image to amplitudes, with sign based on phase.",
33 "-positive Convert a complex image to be postive definite.",
34 "-friedel Check and apply Friedel symmetry.",
35 " ",
36 "Parameters:",
37 "-verbose 7 Verbosity of output.",
38 "-datatype u Force writing of a new data type.",
39 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
40 " ",
41 NULL
42 };
43
44 int main(int argc, char **argv)
45 {
46 DataType nudatatype(Unknown_Type); // Conversion to new type
47 Vector3<long> nusize; // New size if > 0
48 Vector3<double> sam; // Units for the three axes (A/pixel)
49 int setlogarithm(0); // Flag for logarithmic power spectrum
50 int conv_comp(0); // Flag for complex to real conversions
51 int positive(0); // Flag to convert to positive definite
52 int friedel(0); // Flag for applying Fiedel symmetry
53
54 int optind;
55 Boption* option = get_option_list(use, argc, argv, optind);
56 Boption* curropt;
57 for ( curropt = option; curropt; curropt = curropt->next ) {
58 if ( curropt->tag == "datatype" )
59 nudatatype = curropt->datatype();
60 if ( curropt->tag == "sampling" )
61 sam = curropt->sampling();
62 if ( curropt->tag == "size" )
63 nusize = curropt->size();
64 if ( curropt->tag == "logarithm" )
65 setlogarithm = 1;
66 if ( curropt->tag == "amplitudes" )
67 conv_comp = 1;
68 if ( curropt->tag == "intensities" )
69 conv_comp = 2;
70 if ( curropt->tag == "real" )
71 conv_comp = 3;
72 if ( curropt->tag == "imaginary" )
73 conv_comp = 4;
74 if ( curropt->tag == "phases" )
75 conv_comp = 5;
76 if ( curropt->tag == "signed" )
77 conv_comp = 6;
78 if ( curropt->tag == "positive" )
79 positive = 1;
80 if ( curropt->tag == "friedel" )
81 friedel = 1;
82 }
83 option_kill(option);
84
85 double ti = timer_start();
86
87 int dataflag(0);
88 if ( optind < argc - 1 ) dataflag = 1;
89 Bimage* p = read_img(argv[optind++], dataflag, -1);
90 if ( p == NULL ) bexit(-1);
91
92 if ( nudatatype == Unknown_Type )
93 nudatatype = p->data_type();
94 else if ( nudatatype > p->data_type() )
95 p->change_type(nudatatype);
96
97 if ( sam.volume() > 0 ) p->sampling(sam);
98
99 if ( nusize.volume() > 0 ) p->change_transform_size(nusize);
100
101 if ( friedel ) {
102 p->friedel_check();
103 p->friedel_apply();
104 }
105
106 if ( positive )
107 p->fspace_positive();
108
109 if ( conv_comp && p->compound_type() == TComplex ) {
110 switch ( conv_comp ) {
111 case 1: p->complex_to_amplitudes(); break;
112 case 2: p->complex_to_intensities(); break;
113 case 3: p->complex_to_real(); break;
114 case 4: p->complex_to_imaginary(); break;
115 case 5: p->complex_to_phases(); break;
116 case 6: p->complex_to_signed_amplitudes(); break;
117 }
118 p->statistics();
119 }
120
121 if ( setlogarithm ) p->logarithm();
122
123 // Write an output file if a file name is given
124 if ( optind < argc ) {
125 p->change_type(nudatatype);
126 p->label(get_cmd_line(argc, argv));
127 write_img(argv[optind], p, 0);
128 }
129
130 delete p;
131
132 if ( verbose & VERB_TIME )
133 timer_report(ti);
134
135 bexit(0);
136 }
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::tag
Bstring tag
Definition: options.h:29
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:351
use
const char * use[]
Definition: bcomplex.cpp:18
Bimage::logarithm
void logarithm()
Calculates the logarithm of the image data.
Definition: Bimage_rescale.cpp:728
TComplex
Definition: Bimage.h:59
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
timer.h
Utilities for timing functions.
Bimage::complex_to_amplitudes
void complex_to_amplitudes()
The amplitudes from a complex image is written to a simple image.
Definition: Bimage_complex.cpp:114
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
Bimage::complex_to_signed_amplitudes
void complex_to_signed_amplitudes()
The signed amplitudes from a complex image is written to a simple image.
Definition: Bimage_complex.cpp:136
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
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bimage::complex_to_intensities
void complex_to_intensities()
The intensities from a complex image is written to a simple image.
Definition: Bimage_complex.cpp:92
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bimage::complex_to_real
void complex_to_real()
The real part of a complex image is written to a simple image.
Definition: Bimage_complex.cpp:50
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bimage::complex_to_imaginary
void complex_to_imaginary()
The imaginary part of a complex image is written to a simple image.
Definition: Bimage_complex.cpp:71
main
int main(int argc, char **argv)
Definition: bcomplex.cpp:44
verbose
int verbose
Vector3< long >
Bimage::friedel_apply
int friedel_apply()
Applies Friedel symmetry.
Definition: Bimage_fspace.cpp:1711
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
Bimage::fspace_positive
int fspace_positive()
Sets the image to positive definite.
Definition: Bimage_fspace.cpp:1608
Bimage::friedel_check
double friedel_check()
Checks Friedel symmetry.
Definition: Bimage_fspace.cpp:1649
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bimage::complex_to_phases
void complex_to_phases()
The phases from a complex image is written to a simple image.
Definition: Bimage_complex.cpp:161
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::change_transform_size
Vector3< double > change_transform_size(Vector3< long > nusize)
Resizes a "standard" transform.
Definition: Bimage_fft.cpp:239
Vector3::volume
double volume()
Definition: Vector3.h:235
Bimage::data_type
DataType data_type()
Definition: Bimage.h:349
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