 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
21 "Usage: bsegment [options] input.img/input.star [output.img]",
22 "-----------------------------------------------------------",
23 "Analyzes images for segmentation.",
26 "-invert Invert density in the image before other operations.",
27 "-rescale -0.1,5.2 Rescale extracted regions to average and standard deviation.",
28 "-blobs 0.45,14,201,1.4 Show blobs above threshold (0.45) and set outside minimum (14) ",
29 " and maximum (201) sizes to value (1.4).",
31 "Mask generating actions:",
32 "-mass 342k Find threshold associated with this molecular weight (Da)",
33 " value can be given in Da, kDa (with k), MDa (with m) or Gda (with g).",
34 " Output binary mask (data type byte, values 0 and 1).",
35 "-threshold 1.54 Report mass calculated from the volume included at this threshold.",
36 " Output binary mask (data type byte, values 0 and 1).",
37 "-multiple 1.2 Generate multiple regions above this threshold.",
38 "-kmeans 12,25,0.8 K-means segmentation: K, iterations and density:distance ratio.",
39 "-innervolume 2.3,15 Calculate internal volume below this threshold, output mask frequency.",
42 "-select 1,5-7 Select levels in a multi-level mask.",
43 "-combine 1,5-7 Combine levels to create a binary mask.",
44 "-voxel 15,50,33 Select a region around this voxel.",
47 "-verbose 7 Verbose output.",
48 "-datatype u Force writing of a new data type.",
49 "-origin 0.8,-10,15.7 Set the origin (default from input image).",
50 "-sign -1 Sign for thresholding (default 0=set by sign of threshold-average;",
51 " 1=positive density; -1=negative density).",
52 "-rho 0.8 Protein density (default 0.81 Da/A3, use with -mass).",
55 "-Mask mask.tif Input mask (must be integer and same size as input image).",
58 "-Region region.tif File name for the excised region.",
63 int main(
int argc,
char* argv[])
68 double nuavg(0), nustd(0);
69 double threshold(-1e36);
77 double blob_threshold(-1e36);
79 double max_size(1000000000);
82 int internal_volume(0);
95 for ( curropt = option; curropt; curropt = curropt->
next ) {
96 if ( curropt->
tag ==
"datatype" )
98 if ( curropt->
tag ==
"invert" )
100 if ( curropt->
tag ==
"rescale" )
101 if ( curropt->
values(nuavg, nustd) < 2 )
102 cerr <<
"-rescale: Both average and standard deviation must be specified!" << endl;
103 if ( curropt->
tag ==
"blobs" ) {
104 if ( ( i = curropt->
values(blob_threshold, min_size, max_size, setvalue ) ) < 1 )
105 cerr <<
"-blobs: A threshold must be specified!" << endl;
107 if ( i < 4 ) setvalue = blob_threshold;
109 if ( curropt->
tag ==
"mass" )
110 mol_weight = curropt->
mass();
111 if ( curropt->
tag ==
"threshold" )
112 if ( ( threshold = curropt->
value.
real() ) < -1e30 )
113 cerr <<
"-threshold: A threshold must be specified!" << endl;
114 if ( curropt->
tag ==
"innervolume" ) {
115 if ( curropt->
values(threshold, mask_out_freq ) < 1 )
116 cerr <<
"-innervolume: A threshold must be specified!" << endl;
120 if ( curropt->
tag ==
"multiple" ) {
121 if ( curropt->
values(threshold, sign) < 1 )
122 cerr <<
"-multiple: A threshold must be specified!" << endl;
126 if ( curropt->
tag ==
"kmeans" )
127 if ( curropt->
values(nregions, max_iter, ratio) < 1 )
128 cerr <<
"-kmeans: A number of regions must be specified!" << endl;
129 if ( curropt->
tag ==
"select" ) {
130 level_select = curropt->
value;
131 if ( level_select.
length() < 1 )
132 cerr <<
"-select: Level numbers must be specified!" << endl;
136 if ( curropt->
tag ==
"combine" ) {
137 level_select = curropt->
value;
138 if ( level_select.
length() < 1 )
139 cerr <<
"-combine: Level numbers must be specified!" << endl;
143 if ( curropt->
tag ==
"voxel" ) {
144 voxel = curropt->
size();
147 if ( curropt->
tag ==
"origin" ) {
148 if ( curropt->
value[0] ==
'c' ) {
151 origin = curropt->
origin();
155 if ( curropt->
tag ==
"sign" )
157 cerr <<
"-sign: A sign value must be specified!" << endl;
158 if ( curropt->
tag ==
"rho" )
159 if ( ( rho = curropt->
value.
real() ) < 0.001 )
160 cerr <<
"-rho: A protein density value must be specified!" << endl;
161 if ( curropt->
tag ==
"Mask" )
163 if ( curropt->
tag ==
"Region" )
171 Bstring filename(argv[optind++]);
179 if ( set_origin == 2 ) p->
origin(p->
size()/2);
183 if ( setinvert ) p->
invert();
185 if ( blob_threshold > -1e29 )
186 p->
blobs(blob_threshold, min_size, max_size, setvalue, sign);
188 if ( mol_weight > 0 )
190 else if ( threshold )
195 if ( mask_file.
length() ) {
197 }
else if ( nregions > 1 ) {
199 }
else if ( region_mask ) {
200 pmask = p->
regions(threshold, sign);
201 }
else if ( mol_weight > 0 ) {
203 }
else if ( internal_volume ) {
220 if ( pmask && region_file.
length() ) {
229 if ( !pmask ) pmask = p;
230 if ( optind < argc ) {
231 filename = argv[optind];
236 if ( pmask && pmask != p )
delete pmask;
Bimage * regions(double threshold, int sign)
Segments an image into contiguous regions.
A class for a command line input option.
Header file for file checking functions.
Bimage * level_mask_extract(Bimage *pmask)
Extracts all the regions associated with a multi-level mask.
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.
double mass_at_threshold(long img_num, double threshold, double rho)
Calculates the mass from the density threshold.
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Vector3< long > size() const
Header file for option handlers.
int main(int argc, char *argv[])
Bimage * kmeans_segment(long nregion=2, long max_iter=10, double ratio=1)
Segments an image based on K-means.
Vector3< double > origin()
Bimage * internal_volume(double threshold)
Calculates the internal volume of a shell.
double mass_threshold(long img_num, double mol_weight, double rho)
Finds the density threshold associated with a particular molecular weight.
long values(T1 &v1, T2 &v2)
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Bimage * mask_by_threshold(double threshold)
Generates a mask based on an image at a given threshold.
General image parameter class.
Utilities for timing functions.
double timer_start()
Starts timer and prints the time.
Header file for general utilities.
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void origin(double ox, double oy, double oz)
void change_type(char letter)
Get the data type indicated by a single letter code.
Header file for 2D and 3D image I/O.
long blobs(double threshold, double min_size, double max_size, double setvalue, int sign)
Identifies contiguous regions above a given threshold (blobs) and eliminate those less than a minimum...
int option_kill(Boption *option)
Deallocates a linked list of option structures.
void invert()
Inverts the data in the image.
DataType
Base data type specifier.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.