| Bsoft 2.0.5 Bernard's software package

bfilwidth.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
18 // Usage assistance
19 const char* use[] = {
20 " ",
21 "Usage: bfilwidth [options] img.pif out.pif",
22 "------------------------------------------",
23 "Analyzes the periodicity of a filament from width changes.",
24 "The filament must be aligned with the y axis and with positive contrast.",
25 " ",
26 "Actions:",
27 "-invert Invert density in the image before other operations.",
28 "-rescale -0.1,5.2 Rescale data to average and standard deviation before other operations.",
29 "-average 34,1,1 Moving average window size (voxels).",
30 "-period 100,32,1 Periodic frame size (voxels).",
31 "-width 25 Window to fit a moving line for estimating the filament width.",
32 "-density 30,120 Density with filament width and number of histogram bins.",
33 " ",
34 "Parameters:",
35 "-verbose 7 Verbosity of output.",
36 "-datatype u Force writing of a new data type.",
37 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
38 "-origin 0.8,-10,15.7 Set the origin (default from input image).",
39 "-resolution 15.6 Resolution limit for cross-correlation.",
40 "-limits 35,57 Limits on the filament width (default 0 - width of image).",
41 " ",
42 "Input:",
43 "-reference file.map 2D reference for cross-correlation.",
44 " ",
45 "Output:",
46 "-Postscript plot.ps Plot of filament widths.",
47 " ",
48 NULL
49 };
50
51 int main(int argc, char** argv)
52 {
53 // Initialize variables
54 // DataType nudatatype(Unknown_Type); // Conversion to new type
55 int setinvert(0); // Flag to invert density
56 double nuavg(0), nustd(0); // Values for rescaling
57 Vector3<double> sam; // Units for the three axes (A/pixel)
58 Vector3<double> origin; // New image origin
59 int set_origin(0); // Flag to set origin
60 Vector3<long> average_window; // Size of moving average window
61 Vector3<long> period; // Size of periodic frame
62 long width(0); // Moving window for filament width estimation
63 long filwidth(0), bins(100); // Filament width and bins for density calculation
64 double res_lo(10000); // High resolution limits
65 double res_hi(0); // Low resolution limits
66 int lim_lo(0), lim_hi(0); // Limits on the filament width
67 Bstring ref_file; // Reference file name
68 Bstring psfile; // Postscript output file
69
70 int optind;
71 Boption* option = get_option_list(use, argc, argv, optind);
72 Boption* curropt;
73 for ( curropt = option; curropt; curropt = curropt->next ) {
74 // if ( curropt->tag == "datatype" )
75 // nudatatype = curropt->datatype();
76 if ( curropt->tag == "invert" )
77 setinvert = 1;
78 if ( curropt->tag == "rescale" ) {
79 if ( curropt->values(nuavg, nustd) < 2 )
80 cerr << "-rescale: Both average and standard deviation must be specified!" << endl;
81 if ( nustd <= 0 )
82 cerr << "-rescale: A positive standard deviation must be specified!" << endl;
83 }
84 if ( curropt->tag == "average" )
85 average_window = curropt->size();
86 if ( curropt->tag == "period" )
87 period = curropt->size();
88 if ( curropt->tag == "width" )
89 if ( ( width = curropt->value.integer() ) < 1 )
90 cerr << "-width: A window size must be specified!" << endl;
91 if ( curropt->tag == "density" )
92 if ( curropt->values(filwidth, bins) < 1 )
93 cerr << "-density: A filament width must be specified!" << endl;
94 if ( curropt->tag == "sampling" )
95 sam = curropt->sampling();
96 if ( curropt->tag == "origin" ) {
97 if ( curropt->value[0] == 'c' ) {
98 set_origin = 2;
99 } else {
100 origin = curropt->origin();
101 set_origin = 1;
102 }
103 }
104 if ( curropt->tag == "resolution" )
105 if ( ( res_hi = curropt->value.real() ) < 0.001 )
106 cerr << "-resolution: A resolution limit must be specified!" << endl;
107 if ( curropt->tag == "limits" )
108 if ( curropt->values(lim_lo, lim_hi) < 2 )
109 cerr << "-limits: Both low and high limits must be specified!" << endl;
110 if ( curropt->tag == "reference" )
111 ref_file = curropt->filename();
112 if ( curropt->tag == "Postscript" )
113 psfile = curropt->filename();
114 }
115 option_kill(option);
116
117 double ti = timer_start();
118
119 Bimage* p = read_img(argv[optind++], 1, -1);
120 if ( p == NULL ) bexit(-1);
121
122 if ( sam.volume() > 0 ) p->sampling(sam);
123
124 if ( set_origin ) {
125 if ( set_origin == 2 ) p->origin(p->default_origin());
126 else p->origin(origin);
127 }
128
129 if ( setinvert ) p->invert();
130
131 if ( nustd > 0 ) p->rescale_to_avg_std(nuavg, nustd);
132
133 if ( average_window.volume() ) p->filter_average(average_window);
134
135 if ( period.volume() ) {
136 Bimage* pp = p->periodic_averaging(period);
137 delete p;
138 p = pp;
139 }
140
141 Bimage* pref = NULL;
142 Bimage* pmask = NULL;
143 if ( ref_file.length() ) {
144 pref = read_img(ref_file, 1, -1);
145 if ( !pref ) bexit(-1);
146 p->find_shift(pref, pmask, res_hi, res_lo, p->sizeY()/2, 0, 1);
147 if ( verbose )
148 cout << "New origin = " << p->image->origin() << endl;
149 p->shift_wrap(pref->image->origin() - p->image->origin());
150 p->origin(pref->image->origin());
151 delete pref;
152 }
153
154 Bimage* pd = NULL;
155 Bplot* plot = NULL;
156 if ( width ) plot = p->filament_width(width, lim_lo, lim_hi);
157 else if ( filwidth ) {
158 pd = p->filament_density(filwidth);
159 plot = pd->histogram_gauss_plot(bins, 1);
160 if ( verbose )
161 cout << "Gaussain fit: average = " << pd->average() << " standard deviation = " << pd->standard_deviation() << endl;
162 delete pd;
163 }
164
165 if ( psfile.length() && plot )
166 ps_plot(psfile, plot);
167
168 if ( argc > optind ) {
169 p->label(get_cmd_line(argc, argv));
170 write_img(argv[optind], p, 0);
171 }
172
173 delete p;
174 delete plot;
175
176 if ( verbose & VERB_TIME )
177 timer_report(ti);
178
179 bexit(0);
180 }
181
Bstring::real
double real()
Definition: Bstring.cpp:545
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Bimage::invert
void invert()
Inverts the data in the image.
Definition: Bimage.cpp:3108
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Bimage::shift_wrap
int shift_wrap(Vector3< double > vec)
Shifts an image.
Definition: Bimage_transform.cpp:643
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bimage::periodic_averaging
Bimage * periodic_averaging(Vector3< double > period)
Calculates an average within a periodic frame.
Definition: Bimage_filter.cpp:1145
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
main
int main(int argc, char **argv)
Definition: bfilwidth.cpp:51
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
Boption::filename
Bstring filename()
Definition: options.h:85
timer.h
Utilities for timing functions.
Bimage::histogram_gauss_plot
Bplot * histogram_gauss_plot(long bins, long ngauss=1)
Fits a gaussian function to a histogram of an image.
Definition: Bimage_histogram.cpp:695
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
Bimage::filament_width
Bplot * filament_width(long width, long lim_lo, long lim_hi)
Estimates the width of a filament.
Definition: Bimage_helix.cpp:1583
Bimage::filter_average
int filter_average(long kernel_size)
Applies an averaging filter to an image.
Definition: Bimage_filter.cpp:208
verbose
int verbose
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::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
ps_plot
int ps_plot(Bstring filename, Bplot *plot)
Generates postscript graphs.
Definition: ps_plot.cpp:128
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:537
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Bimage::default_origin
Vector3< double > default_origin()
Definition: Bimage.h:585
use
const char * use[]
Definition: bfilwidth.cpp:19
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
Bimage::find_shift
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.
Definition: Bimage_correlate.cpp:932
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
Bstring::integer
long integer()
Definition: Bstring.cpp:539
Bimage::average
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Definition: Bimage.cpp:1349
Bimage::filament_density
Bimage * filament_density(double width)
Estimates the density per pixel length of a filament.
Definition: Bimage_helix.cpp:1688
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
Vector3::volume
double volume()
Definition: Vector3.h:235
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
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::image
Bsub_image * image
Definition: Bimage.h:188
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563
Bplot
Definition: Bplot.h:146