| Bsoft 2.0.5 Bernard's software package

bphase.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: bphase [options] file1.img file2.img outfile.img",
21 "-------------------------------------------------------",
22 "Calculates the phase difference between two images.",
23 " ",
24 "Actions:",
25 "-cosine Calculate the cosine of the phase angle difference.",
26 "-amplitude Weight the phase difference with the amplitude product.",
27 "-center Center phase difference map and output it.",
28 "-flip Flip phases based on phase difference map and modify second image.",
29 " ",
30 "Parameters:",
31 "-verbose 7 Verbosity of output.",
32 "-datatype short Force writing of a new data type (default float).",
33 "-origin 0.8,-10,15.7 Set the origin of both images (default from input images).",
34 "-resolution 4.5,130 Resolution (default 0 - 10000 angstrom).",
35 " ",
36 NULL
37 };
38
39 int main(int argc, char* argv[])
40 {
41 // Initialize all settings
42 int pd_type(0); // Phase difference result type
43 int center(0); // Flag to center phase difference map
44 int flip(0); // Flag to flip phases of second image based on phase difference map
45 DataType nudatatype(Unknown_Type); // Conversion to new type
46 Vector3<double> origin; // New image origin
47 int set_origin(0); // Flag to set origin
48 double hires(0), lores(1e4); // Limiting resolution range (hires must be > 0 to be set)
49
50 int optind;
51 Boption* option = get_option_list(use, argc, argv, optind);
52 Boption* curropt;
53 for ( curropt = option; curropt; curropt = curropt->next ) {
54 if ( curropt->tag == "cosine" ) pd_type |= 1;
55 if ( curropt->tag == "amplitude" ) pd_type |= 2;
56 if ( curropt->tag == "center" ) center = 1;
57 if ( curropt->tag == "flip" ) flip = 1;
58 if ( curropt->tag == "datatype" )
59 nudatatype = curropt->datatype();
60 if ( curropt->tag == "origin" ) {
61 if ( curropt->value[0] == 'c' ) {
62 set_origin = 2;
63 } else {
64 origin = curropt->origin();
65 set_origin = 1;
66 }
67 }
68 if ( curropt->tag == "resolution" )
69 if ( curropt->values(hires, lores) < 1 )
70 cerr << "-resolution: A high resolution limit must be specified" << endl;
71 }
72 option_kill(option);
73
74 double ti = timer_start();
75
76 int dataflag = 0;
77 if ( optind < argc - 1 ) dataflag = 1;
78 Bimage* p1 = read_img(argv[optind++], dataflag, -1);
79 if ( p1 == NULL ) {
80 cerr << "Error: No first input file read!" << endl;
81 bexit(-1);
82 }
83 if ( !p1->data_pointer() ) {
84 cerr << "Error: Data missing from image " << p1->file_name() << endl;
85 bexit(-1);
86 }
87
88 Bimage* p2 = read_img(argv[optind++], dataflag, -1);
89 if ( p2 == NULL ) {
90 cerr << "Error: No second input file read!" << endl;
91 bexit(-1);
92 }
93 if ( !p2->data_pointer() ) {
94 cerr << "Error: Data missing from image " << p2->file_name() << endl;
95 bexit(-1);
96 }
97
98 if ( !p1->check_if_same_size(p2) ) bexit(-1);
99
100 if ( set_origin ) {
101 if ( set_origin == 2 ) {
102 p1->origin(p1->size()/2);
103 p2->origin(p2->size()/2);
104 } else {
105 p1->origin(origin);
106 p2->origin(origin);
107 }
108 }
109
110 Bimage* pd = NULL;
111 Bimage* pout = NULL;
112
113 pd = p1->phase_difference(p2, pd_type, hires, lores);
114 pout = pd;
115
116 if ( flip ) {
117 p2->phase_flip(pd);
118 pout = p2;
119 } else {
120 if ( center ) pout->center_wrap();
121 }
122
123 if ( optind < argc ) {
124 pout->label(get_cmd_line(argc, argv));
125 pout->change_type(nudatatype);
126 write_img(argv[optind], pout, 0);
127 }
128
129 delete p1;
130 delete p2;
131 delete pd;
132
133 if ( verbose & VERB_TIME )
134 timer_report(ti);
135
136 bexit(0);
137 }
138
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
verbose
int verbose
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
utilities.h
Header file for general utilities.
Bimage::phase_flip
int phase_flip(Bimage *pd)
Flips the phases of an image based on a phase difference map.
Definition: Bimage_fspace.cpp:1978
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
main
int main(int argc, char *argv[])
Definition: bphase.cpp:39
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:230
Bimage::center_wrap
int center_wrap()
Centers an image with wrapping.
Definition: Bimage_transform.cpp:713
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
General image parameter class.
Definition: Bimage.h:163
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
use
const char * use[]
Definition: bphase.cpp:18
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::size
Vector3< long > size() const
Definition: Bimage.h:373
Boption::datatype
DataType datatype()
Definition: options.h:93
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:261
Boption::next
Boption * next
Definition: options.h:28
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
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bimage::check_if_same_size
bool check_if_same_size(Bimage *p)
Check if two images are the same size.
Definition: Bimage.cpp:536
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::phase_difference
Bimage * phase_difference(Bimage *p, int type=0, double res_hi=0, double res_lo=0)
Calculates the cosine of the phase difference between two images.
Definition: Bimage_fspace.cpp:1793
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
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563