| Bsoft 2.0.5 Bernard's software package

bmultimask.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "options.h"
11 #include "utilities.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: bmultimask [options] input.img output.img",
22 "------------------------------------------------",
23 "Manipulates composite/level masks.",
24 " ",
25 "Actions:",
26 "-color Generate a RGBA image.",
27 "-select 1,5-7 Select levels in a multi-level mask.",
28 "-voxel 23,241,193 Select the level including this voxel.",
29 "-level 134 Convert a mask to multiple levels, with the given voxels per level.",
30 "-bands 250,-1,150,1,30,0 Banded mask for reciprocal space (pairs of numbers: angstrom,value).",
31 " Band with 0: Not used.",
32 " Band with 1: Use for orientation determination.",
33 " Band with -1: Use for cross-validation.",
34 "-collapse Convert a multi-level mask to a binary mask.",
35 "-interfaces 3 Calculates interfaces for the indicated region (-1 gives whole matrix).",
36 "-merge 25,4 Calculates a region interface matrix and deletes/merges",
37 " regions smaller than the given size and interface size.",
38 " ",
39 "Parameters:",
40 "-verbose 1 Verbosity of output.",
41 "-datatype u Force writing of a new data type.",
42 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
43 "-origin 110,50,44 Origin for the mask (default from input image).",
44 " ",
45 "Input:",
46 "-Mask file.img Template mask to select levels.",
47 " ",
48 NULL
49 };
50
51 int main(int argc, char **argv)
52 {
53 // Initialize variables
54 int color(0); // Flag to generate RGBA mask
55 Bstring level_select; // Selection of levels
56 Vector3<long> voxel(-1,0,0); // Voxel to select a level
57 int level(0); // Number of voxels per level
58 vector<double> band; // Reciprocal space bands
59 int collapse(0); // Collapse a multi-level mask to a binary mask
60 int reg_if(-1000000); // Calculate region interfaces
61 int min_size(0); // Minimum size and flag to calculate interface matrix
62 int min_if(1); // Minimum interface size to accept
63 DataType nudatatype(Unknown_Type); // Conversion to new type
64 Vector3<double> sampling; // Units for the three axes (A/pixel)
65 Vector3<double> origin; // Mask origin
66 int set_origin(0); // Flag to set origin
67 Bstring mask_file; // Secondary mask file
68
69 int optind;
70 Boption* option = get_option_list(use, argc, argv, optind);
71 Boption* curropt;
72 for ( curropt = option; curropt; curropt = curropt->next ) {
73 if ( curropt->tag == "color" )
74 color = 1;
75 if ( curropt->tag == "select" ) {
76 level_select = curropt->value;
77 if ( level_select.length() < 1 )
78 cerr << "-select: Level numbers must be specified!" << endl;
79 }
80 if ( curropt->tag == "voxel" ) {
81 voxel = curropt->size();
82 if ( voxel.volume() < 0 )
83 cerr << "-voxel: A voxel must be specified!" << endl;
84 }
85 if ( curropt->tag == "level" )
86 if ( ( level = curropt->value.integer() ) < 1 )
87 cerr << "-level: The voxels per level must be specified!" << endl;
88 if ( curropt->tag == "bands" ) {
89 band = curropt->value.split_into_doubles(",");
90 if ( band.size() < 2 )
91 cerr << "-bands: At least two pairs of numbers must be specified!" << endl;
92 band[band.size()] = 0;
93 }
94 if ( curropt->tag == "collapse" )
95 collapse = 1;
96 if ( curropt->tag == "interfaces" )
97 if ( ( reg_if = curropt->value.integer() ) < -1000000 )
98 cerr << "-interfaces: A region number must be specified!" << endl;
99 if ( curropt->tag == "merge" )
100 if ( curropt->values(min_size, min_if) < 1 )
101 cerr << "-merge: A minimum size must be specified!" << endl;
102 if ( curropt->tag == "datatype" )
103 nudatatype = curropt->datatype();
104 if ( curropt->tag == "sampling" )
105 sampling = curropt->sampling();
106 if ( curropt->tag == "origin" ) {
107 if ( curropt->value[0] == 'c' ) {
108 set_origin = 2;
109 } else {
110 origin = curropt->origin();
111 set_origin = 1;
112 }
113 }
114 if ( curropt->tag == "Mask" )
115 mask_file = curropt->filename();
116 }
117 option_kill(option);
118
119 double ti = timer_start();
120
121 Bimage* p = read_img(argv[optind++], 1, -1);
122
123 if ( p == NULL ) bexit(-1);
124
125 if ( set_origin ) {
126 if ( set_origin == 2 ) p->origin(p->size()/2);
127 else p->origin(origin);
128 }
129
130 if ( sampling.volume() > 0 ) p->sampling(sampling);
131
132 if ( level_select.length() ) p->levelmask_select(level_select);
133
134 if ( voxel[0] >= 0 ) p->levelmask_select(0, voxel);
135
136 if ( band[0] )
137 p->mask_fspace_banded(band);
138
139 if ( level ) p->mask_split(level);
140
141 if ( reg_if > -1000000 ) p->mask_region_interfaces(reg_if);
142
143 if ( min_size > 0 ) p->mask_merge_delete(min_size, min_if);
144
145 Bimage* pmask = NULL;
146 if ( mask_file.length() ) {
147 pmask = read_img(mask_file, 1, -1);
148 if ( sampling.volume() > 0 ) pmask->sampling(sampling);
149 p->levelmask_select(pmask);
150 delete pmask;
151 }
152
153 if ( collapse ) p->levelmask_collapse();
154
155 p->levelmask_clean();
156
157 if ( color ) p->levelmask_colorize();
158
159 p->mask_stats();
160
161 if ( optind < argc ) {
162 p->change_type(nudatatype);
163 p->label(get_cmd_line(argc, argv));
164 write_img(argv[optind], p, 0);
165 }
166
167 delete p;
168
169 if ( verbose & VERB_TIME )
170 timer_report(ti);
171
172 bexit(0);
173 }
174
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Bimage::mask_region_interfaces
long mask_region_interfaces(int reg_num)
Reports the whole interface matrix or interfaces for one region only.
Definition: Bimage_mask.cpp:2175
DataType
DataType
Base data type specifier.
Definition: utilities.h:146
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Bimage::mask_stats
long mask_stats()
Calculates statistics for a mask.
Definition: Bimage_mask.cpp:165
utilities.h
Header file for general utilities.
Boption::sampling
Vector3< double > sampling()
Definition: options.h:202
Boption::value
Bstring value
Definition: options.h:30
Boption::tag
Bstring tag
Definition: options.h:29
main
int main(int argc, char **argv)
Definition: bmultimask.cpp:51
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bimage::mask_fspace_banded
int mask_fspace_banded(vector< double > &band)
Generate reciprocal space mask based on a specification of bands.
Definition: Bimage_mask.cpp:814
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
Boption::filename
Bstring filename()
Definition: options.h:85
verbose
int verbose
timer.h
Utilities for timing functions.
Bimage::levelmask_collapse
long levelmask_collapse()
Collapse a multi-level mask to a binary mask.
Definition: Bimage_mask.cpp:1503
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
Bimage::mask_merge_delete
long mask_merge_delete(long min_size, long min_if)
Calculates the interfaces between regions and deletes/merges small ones.
Definition: Bimage_mask.cpp:2226
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::levelmask_select
long levelmask_select(Bstring &select_list)
Retains the selected levels in a multi-level mask.
Definition: Bimage_mask.cpp:1650
Bimage::levelmask_colorize
long levelmask_colorize()
Colorizes a multi-level mask with random color assignments.
Definition: Bimage_mask.cpp:1887
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
level
size_t level(0)
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:665
Bimage::mask_split
long mask_split(long voxels_per_level)
Converts a mask to a multilevel mask with a given number of voxels per level.
Definition: Bimage_mask.cpp:1453
use
const char * use[]
Definition: bmultimask.cpp:19
Boption::datatype
DataType datatype()
Definition: options.h:93
Boption::next
Boption * next
Definition: options.h:28
Bstring
Definition: Bstring.h:29
Vector3< long >
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
Bstring::integer
long integer()
Definition: Bstring.cpp:539
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::levelmask_clean
long levelmask_clean()
Removes empty levels from a multi-level mask.
Definition: Bimage_mask.cpp:1849
Vector3::volume
double volume()
Definition: Vector3.h:235
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