 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
21 "Usage: bmask [options] input.img output.img",
22 "-------------------------------------------",
23 "Generates and uses binary masks of the size given or of the input image.",
24 "The selected regions have value 1 and the omitted regions 0.",
25 "The default is a blank mask created of the same size as the input image.",
27 "Actions for mask creation:",
28 "-create 20,60,30 Create a new mask of this size in place of input image",
29 "-threshold -0.55,1.2 One or more thresholds to generate a mask.",
30 "-variance 5,1 Generate mask based on local variance in a kernel of a given size,",
31 " and flag to generate a background with value -1.",
33 "Actions for mask modification:",
34 "-invert Invert mask.",
36 "-dilate 2 Dilate mask a number of times.",
37 "-erode 3 Erode mask a number of times.",
38 "-open 4 Open (erode-dilate) mask a number of times.",
39 "-close 2 Close (dilate-erode) mask a number of times.",
40 "-hole 3,56,23 Fill a hole indicated by the voxel.",
41 "-plane 0.3,0.5,-0.1,0,3,25 Mask on one side of a plane with the given normal and origin.",
42 "-rectangle 40,20,45 Rectangular mask with given length, width and rotation angle.",
43 "-radius 10,45 Generate a mask inside these radii.",
44 "-asu D3 Generate an asymmetric unit mask.",
45 "-color size Generate a RGBA image (random/size).",
46 "-size Convert level mask to region size map.",
48 "Actions for multi-level masks:",
49 "-collapse Convert a multi-level mask to a binary mask.",
50 "-select 1,5-7 Select levels in a multi-level mask.",
51 "-voxel 23,241,193 Select the level including this voxel.",
52 "-level 134 Convert a mask to multiple levels, with the given voxels per level.",
53 "-bands 250,-1,150,1,30,0 Banded mask for reciprocal space (pairs of numbers: angstrom,value).",
54 " Band with 0: Not used.",
55 " Band with 1: Use for orientation determination.",
56 " Band with -1: Use for cross-validation.",
58 "Actions for mask application:",
59 "-apply Apply the mask to the input image (default output mask).",
60 "-rescaleapply 0.5,2.3 Rescale region inside mask and apply the mask to the input image.",
63 "-verbose 1 Verbosity of output.",
64 "-datatype u Force writing of a new data type.",
65 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
66 "-origin 110,50,44 Origin for the mask (default from input image).",
67 "-fill 28.3 Fill value (default average).",
68 "-wrap Flag to wrap around image boundaries (default not).",
71 "-Mask file.img Input mask to apply or get difference with main input image.",
74 "1. Creating a new mask:",
75 " bmask -v 7 -create 100,100,50 -radius 10,20 -origin 50,50,25 mask.mrc",
77 "2. Generating a mask from an image:",
78 " bmask -v 7 -threshold 1.5 test.map mask.mrc",
80 "3. Applying a mask to an image:",
81 " bmask -v 7 -Mask mask.mrc test.map new.map",
83 "4. Generating and applying a mask to an image:",
84 " bmask -v 7 -apply -radius 50,80 -origin 100,100,100 test.map new.map",
89 int main(
int argc,
char **argv)
97 vector<double> threshold;
100 double rect_length(0);
101 double rect_width(0);
102 double rect_angle(0);
112 double nuavg(0), nustd(0);
132 for ( curropt = option; curropt; curropt = curropt->
next ) {
133 if ( curropt->
tag ==
"create" )
134 nusize = curropt->
size();
135 if ( curropt->
tag ==
"datatype" )
137 if ( curropt->
tag ==
"sampling" )
138 sam = curropt->
scale();
139 if ( curropt->
tag ==
"threshold" ) {
141 if ( threshold.size() < 1 )
142 cerr <<
"-threshold: At least one threshold must be specified!" << endl;
144 if ( curropt->
tag ==
"variance" )
145 if ( curropt->
values(var_kernel, bgk_flag) < 1 )
146 cerr <<
"-variance: The kernel edge size must be specified!" << endl;
147 if ( curropt->
tag ==
"plane" )
148 if ( curropt->
box(plane_normal, plane_origin) < 3 )
149 cerr <<
"-plane: The plane normal must be specified" << endl;
150 if ( curropt->
tag ==
"rectangle" ) {
151 if ( curropt->
values(rect_length, rect_width, rect_angle) < 2 )
152 cerr <<
"-rectangle: Both length and width must be specified" << endl;
153 rect_angle *=
M_PI/180.0;
155 if ( curropt->
tag ==
"radius" )
156 if ( curropt->
values(rad_min, rad_max) < 2 )
157 cerr <<
"-radius: Both radii must be specified" << endl;
158 if ( curropt->
tag ==
"asu" )
160 if ( curropt->
tag ==
"origin" ) {
161 if ( curropt->
value[0] ==
'c' ) {
164 origin = curropt->
origin();
168 if ( curropt->
tag ==
"fill" )
169 fill = curropt->
fill(fill_type);
170 if ( curropt->
tag ==
"wrap" )
172 if ( curropt->
tag ==
"apply" )
174 if ( curropt->
tag ==
"rescaleapply" )
175 if ( curropt->
values(nuavg, nustd) < 2 )
176 cerr <<
"-rescaleapply: Both average and standard deviation must be specified!" << endl;
177 if ( curropt->
tag ==
"invert" )
185 if ( curropt->
tag ==
"dilate" )
187 cerr <<
"-dilate: A number of times to dilate must be specified!" << endl;
188 if ( curropt->
tag ==
"erode" )
190 cerr <<
"-erode: A number of times to erode must be specified!" << endl;
191 if ( curropt->
tag ==
"open" )
193 cerr <<
"-open: A number of times to open must be specified!" << endl;
194 if ( curropt->
tag ==
"close" )
196 cerr <<
"-close: A number of times to close must be specified!" << endl;
197 if ( curropt->
tag ==
"hole" )
198 if ( curropt->
values(fill_voxel[0], fill_voxel[1], fill_voxel[2]) < 3 )
199 cerr <<
"-hole: A voxel must be specified!" << endl;
200 if ( curropt->
tag ==
"color" )
201 color = curropt->
value;
202 if ( curropt->
tag ==
"size" )
204 if ( curropt->
tag ==
"collapse" )
206 if ( curropt->
tag ==
"select" ) {
207 level_select = curropt->
value;
208 if ( level_select.
length() < 1 )
209 cerr <<
"-select: Level numbers must be specified!" << endl;
211 if ( curropt->
tag ==
"voxel" )
212 if ( curropt->
values(voxel[0], voxel[1], voxel[2]) < 3 )
213 cerr <<
"-voxel: A voxel must be specified!" << endl;
214 if ( curropt->
tag ==
"level" )
216 cerr <<
"-level: The voxels per level must be specified!" << endl;
217 if ( curropt->
tag ==
"bands" ) {
219 if ( band.size() < 2 )
220 cerr <<
"-bands: At least two pairs of numbers must be specified!" << endl;
221 band[band.size()] = 0;
223 if ( curropt->
tag ==
"Mask" )
232 if ( nusize.
volume() > 0 ) {
234 cout <<
"Creating a mask of size: " << nusize << endl;
244 p =
read_img(argv[optind++], 1, -1);
245 if ( p == NULL )
bexit(-1);
256 if ( mask_file.
length() ) {
258 if ( pmask == NULL )
bexit(-1);
260 }
else if ( threshold.size() > 0 ) {
262 }
else if ( var_kernel > 2 ) {
277 if ( plane_normal.
length() > 0 )
278 pmask->
mask_plane(plane_origin, plane_normal);
280 if ( rect_length*rect_width > 0 )
286 if ( band.size() && band[0] )
309 if ( fill_voxel.
length() )
318 }
else if ( apply_flag ) {
319 p->
mask(pmask, fill);
337 if ( optind < argc ) {
342 if ( p != pmask )
delete pmask;
A class for a command line input option.
long mask_fill(Vector3< long > voxel)
Fills an empty part of a mask indicated by the given voxel.
long mask_erode(long times=1)
Erodes a binary mask.
Vector3< double > scale()
long mask_dilate(long times=1)
Dilates a binary mask.
Bimage * levelmask_color_by_size()
Color a multi-level mask based on the volumes of regions.
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Header file for general symmetry functions.
long levelmask_select(Bstring &select_list, int flag=0)
Retains the selected levels in a multi-level mask.
int bexit(int value)
Exit function for cleanup and debugging.
Vector3< double > default_origin()
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
double background(long nn)
Header file for option handlers.
Vector3< double > origin()
Bimage * mask_by_thresholds(vector< double > threshold)
Generates a mask based on an image at a given threshold.
long values(T1 &v1, T2 &v2)
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
void multiply(long j, Complex< double > cv)
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
long mask_stats()
Calculates statistics for a mask.
long mask_shell(Vector3< double > origin, double rad_min, double rad_max)
int levelmask_region_size()
Convert a mask to reflect region sizes.
General image parameter class.
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Utilities for timing functions.
long box(Vector3< T1 > &st, Vector3< T2 > &sz)
long mask(Bimage *pmask, double fill)
Masks an image.
vector< double > split_into_doubles(const Bstring &delim)
Bimage * levelmask_asymmetric_units(Bsymmetry *sym, int index)
Calculates a multi-level mask to indicate asymmetric units.
double timer_start()
Starts timer and prints the time.
Header file for general utilities.
double fill(int &fill_type)
long levelmask_collapse()
Collapse a multi-level mask to a binary mask.
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void origin(double ox, double oy, double oz)
long mask_invert()
Inverts a mask.
void change_type(char letter)
Get the data type indicated by a single letter code.
Header file for 2D and 3D image I/O.
Bimage * variance_mask(long kernel_size, double lowvar=1e-6, int bkg_flag=0)
Calculates a mask based on local variance.
long mask_split(long voxels_per_level)
Converts a mask to a multilevel mask with a given number of voxels per level.
int kill_symmetry(Bsymmetry *sym)
Deallocates a symmetry structure.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
long mask_plane(Vector3< double > origin, Vector3< double > normal)
Generates a mask on one side of a plane.
void sampling(long nn, Vector3< double > u)
int main(int argc, char **argv)
DataType
Base data type specifier.
void simple_to_rgba()
A simple image is converted to a color image.
long mask_open(int times=1)
Opens a binary mask.
long mask_rectangle(double length, double width, double rect_angle, int wrap)
Generates a mask along an axis within a 2D image.
long mask_close(int times=1)
Closes a binary mask.
int mask_fspace_banded(vector< double > &band)
Generate reciprocal space mask based on a specification of bands.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.