Bsoft  2.1.0
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->scale();
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  write_img(argv[optind], p, 0);
127  }
128 
129  delete p;
130 
131  if ( verbose & VERB_TIME )
132  timer_report(ti);
133 
134  bexit(0);
135 }
Boption
A class for a command line input option.
Definition: options.h:26
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
Bimage::friedel_apply
int friedel_apply()
Applies Friedel symmetry.
Definition: Bimage_fspace.cpp:1806
Boption::scale
Vector3< double > scale()
Definition: options.h:190
Bimage::fspace_positive
int fspace_positive()
Sets the image to positive definite.
Definition: Bimage_fspace.cpp:1703
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Vector3< long >
use
const char * use[]
Definition: bcomplex.cpp:18
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
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
TComplex
@ TComplex
Definition: Bimage.h:60
options.h
Header file for option handlers.
Boption::tag
Bstring tag
Definition: options.h:29
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
Bimage::change_transform_size
Vector3< double > change_transform_size(Vector3< long > nusize)
Resizes a "standard" transform.
Definition: Bimage_fft.cpp:239
Bimage
General image parameter class.
Definition: Bimage.h:177
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:364
timer.h
Utilities for timing functions.
Unknown_Type
@ Unknown_Type
Definition: utilities.h:151
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
Bimage::data_type
DataType data_type()
Definition: Bimage.h:362
utilities.h
Header file for general utilities.
Boption::size
Vector3< long > size()
Definition: options.h:163
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
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::complex_to_phases
void complex_to_phases()
The phases from a complex image is written to a simple image.
Definition: Bimage_complex.cpp:161
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
Vector3::volume
double volume()
Definition: Vector3.h:237
rwimg.h
Header file for 2D and 3D image I/O.
verbose
int verbose
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:111
main
int main(int argc, char **argv)
Definition: bcomplex.cpp:44
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
DataType
DataType
Base data type specifier.
Definition: utilities.h:150
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::logarithm
void logarithm()
Calculates the logarithm of the image data.
Definition: Bimage_rescale.cpp:728
Bimage::friedel_check
double friedel_check()
Checks Friedel symmetry.
Definition: Bimage_fspace.cpp:1744
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
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22