| Bsoft 2.0.5 Bernard's software package

bedge.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: bedge [options] infile.mrc outfile.mrc",
21 "---------------------------------------------",
22 "Smooths the edge of an image to a uniform background.",
23 " ",
24 "Parameters:",
25 "-verbose 7 Verbosity of output.",
26 "-datatype u Force writing of a new data type.",
27 "-truncate -0.5,1.2 Truncate data to minimum and maximum before edge operation.",
28 "-size 4000,4000,10 Size of region inside edge (default 90% of image size).",
29 //"-origin 2500,1500,5 Edge origin (deprecated).",
30 "-start 2500,1500,5 Start of edge (default 5% from image origin).",
31 //"-gausswidth 80 Gaussian width (deprecated, use -width).",
32 "-width 8 Gaussian width (default 0.1, sharp edge, <0 inverts selection).",
33 //"-edgeshape oval Edge shape (deprecated, use -shape).",
34 "-shape oval Edge shape: rectangular (default), oval, cylindrical.",
35 "-fill 150 Fill value for background: average (default), background, or value.",
36 " ",
37 NULL
38 };
39
40 int main(int argc, char* argv[])
41 {
42 // Initialize variables
43 DataType nudatatype(Unknown_Type); // Conversion to new type
44 double cutmin(0), cutmax(0); // Truncation
45 int setedge(0); // Rectangular edge smoothing
46 Bstring shape("rectangular");
47 Vector3<long> size; // Size of smoothing area
48 Vector3<double> start; // Start of smoothing edge
49 int set_start(0); // Flag to set start
50 double width(0.1); // Gaussian width/sigma
51 double fill(127); // Fill value default for byte
52 int fill_type(FILL_AVERAGE); // Fill type for edge smoothing
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 == "truncate" )
61 if ( curropt->values(cutmin, cutmax) < 2 )
62 cerr << "-truncate: Both min and max must be specified!" << endl;
63 if ( curropt->tag == "size" )
64 if ( curropt->values(size[0], size[1], size[2]) < 3 )
65 cerr << "-size: All three dimensions must be specified!" << endl;
66 if ( curropt->tag == "start" || curropt->tag == "origin" ) {
67 if ( curropt->values(start[0], start[1], start[2]) < 3 )
68 cerr << "-start: All three dimensions must be specified!" << endl;
69 set_start = 1;
70 }
71 if ( curropt->tag == "width" || curropt->tag == "gausswidth" ) {
72 width = curropt->value.real();
73 if ( fabs(width) < 0.001 )
74 cerr << "-width: The Gaussian width must be specified." << endl;
75 }
76 if ( curropt->tag == "shape" || curropt->tag == "edgeshape" ) {
77 shape = curropt->value;
78 if ( shape.length() < 1 ) {
79 cerr << "-shape: An edge shape must be specified." << endl;
80 } else {
81 if ( tolower(shape[0]) == 'o' ) setedge = 1;
82 if ( tolower(shape[0]) == 'c' ) setedge = 2;
83 }
84 }
85 if ( curropt->tag == "fill" )
86 fill = curropt->fill(fill_type);
87 }
88 option_kill(option);
89
90 /* Start timer */
91 double ti = timer_start();
92
93 // Read the input file
94 Bimage* p = read_img(argv[optind++], 1, -1);
95 Vector3<double> sz = {double(p->sizeX()), double(p->sizeY()), double(p->sizeZ())};
96
97 if ( cutmin < cutmax )
98 p->truncate_to_min_max(cutmin, cutmax);
99
100 if ( !set_start )
101 start = sz * 0.05;
102
103 if ( size.volume() < 1 ) {
104 sz = sz * 0.95 - start;
105 size = {long(sz[0]), long(sz[1]), long(sz[2])};
106 }
107 size = size.max(1);
108
109 p->edge(setedge, size, start, width, fill_type, fill);
110
111 // Write an output file if a file name is given
112 if ( argc > optind ) {
113 p->label(get_cmd_line(argc, argv));
114 p->change_type(nudatatype);
115 write_img(argv[optind], p, 0);
116 }
117
118 delete p;
119
120 if ( verbose & VERB_TIME )
121 timer_report(ti);
122
123 bexit(0);
124 }
125
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bstring::real
double real()
Definition: Bstring.cpp:545
Boption::fill
double fill(int &fill_type)
Definition: options.h:138
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
utilities.h
Header file for general utilities.
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
main
int main(int argc, char *argv[])
Definition: bedge.cpp:40
Bimage::edge
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
Definition: Bimage_edit.cpp:319
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:173
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bimage::truncate_to_min_max
int truncate_to_min_max(double minim, double maxim)
Truncates image data to a given minimum and maximum.
Definition: Bimage_rescale.cpp:331
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.
Vector3::max
Type max()
Definition: Vector3.h:175
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
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
use
const char * use[]
Definition: bedge.cpp:18
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
Vector3< long >
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
Unknown_Type
Definition: utilities.h:147
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
verbose
int verbose
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