 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
20 "Usage: bop [options] file1.img file2.img outfile.img",
21 "----------------------------------------------------",
22 "Binary operations for 2D and 3D images.",
23 "Only one operation can be done at a time.",
26 "-slices Interpret multiple 2D images as z-slices of a single 3D image",
27 "-images Interpret slices of a single 3D image as 2D images",
28 "-add 1.4,3.6 Add two images, scaling and shifting the second.",
29 "-multiply -5.1,0.5 Multiply two images, scaling and shifting the second.",
30 "-divide -1.8,-2.4 Divide the first image by the second, scaling and shifting the second.",
31 "-largest 3.1,0.5 Maximum of two images, scaling and shifting the second.",
32 "-smallest 3.1,0.5 Minimum of two images, scaling and shifting the second.",
33 "-truncate -0.3,10 Truncate result to min and max.",
34 "-variance 0.15,-0.5 Scale based on variance ratio, optionally shifting the second.",
35 "-fit 6 Linear fit, excluding a percentage of voxels as outliers, output difference.",
36 "-coefficient Calculates correlation coefficients between two sets of images.",
37 "-correlate corr.img Correlate two images and generate a correlation image.",
38 "-Histomatch 20 Match histogram of image 2 to image 1, output modified image 2.",
39 "-blend 7 Blend from image 1 to image 2, output a new multi-image file.",
42 "-verbose 7 Verbosity of output.",
43 "-datatype u Force writing of a new data type.",
44 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
45 "-radius minr,maxr Correlate or fit only between min. and max. radius (pixel).",
48 "-Mask mask.tif Mask file to use for limiting comparisons to a defined region.",
53 int main(
int argc,
char* argv[])
66 double excl_voxels(0);
70 int sethisto(0), bins(0);
75 double min(0), max(0);
76 double minr(0), maxr(0);
84 for ( curropt = option; curropt; curropt = curropt->
next ) {
85 if ( curropt->
tag ==
"datatype" )
87 if ( curropt->
tag ==
"sampling" )
88 sampling = curropt->
scale();
89 if ( curropt->
tag ==
"slices" )
91 if ( curropt->
tag ==
"images" )
93 if ( curropt->
tag ==
"add" ) {
94 if ( curropt->
values(scale, shift) < 2 )
95 cerr <<
"-add: Both scale and shift must be specified!" << endl;
98 if ( curropt->
tag ==
"multiply" ) {
99 if ( curropt->
values(scale, shift) < 2 )
100 cerr <<
"-multiply: Both scale and shift must be specified!" << endl;
101 else setmultiply = 1;
103 if ( curropt->
tag ==
"divide" ) {
104 if ( curropt->
values(scale, shift) < 2 )
105 cerr <<
"-divide: Both scale and shift must be specified!" << endl;
108 if ( curropt->
tag ==
"largest" ) {
109 if ( curropt->
values(scale, shift) < 2 )
110 cerr <<
"-largest: Both scale and shift must be specified!" << endl;
113 if ( curropt->
tag ==
"smallest" ) {
114 if ( curropt->
values(scale, shift) < 2 )
115 cerr <<
"-smallest: Both scale and shift must be specified!" << endl;
116 else setsmallest = 1;
118 if ( curropt->
tag ==
"truncate" ) {
119 if ( curropt->
values(min, max) < 2 )
120 cerr <<
"-truncate: Both min and max must be specified!" << endl;
123 if ( curropt->
tag ==
"variance" ) {
124 if ( curropt->
values(scale, shift) < 1 )
125 cerr <<
"-variance: A variance ratio be specified!" << endl;
126 else setvar = setadd = 1;
128 if ( curropt->
tag ==
"fit" ) {
129 if ( ( excl_voxels = curropt->
value.
real() ) < 0 )
130 cerr <<
"-fit: A percentage of voxels to exclude must be specified!" << endl;
134 if ( curropt->
tag ==
"coefficient" )
136 if ( curropt->
tag ==
"radius" ) {
137 if ( curropt->
values(minr, maxr) < 2 )
138 cerr <<
"-radius: Both radii must be specified!" << endl;
141 if ( curropt->
tag ==
"Histomatch" ) {
143 cerr <<
"-Histomatch: The number of bins must be specified!" << endl;
147 if ( curropt->
tag ==
"blend" )
149 cerr <<
"-blend: A number of images must be specified!" << endl;
150 if ( curropt->
tag ==
"correlate" )
152 if ( curropt->
tag ==
"Mask" )
161 if ( optind < argc - 1 ) dataflag = 1;
164 cerr <<
"Error: No first input file read!" << endl;
180 cerr <<
"Error: No second input file read!" << endl;
195 cerr <<
"Error: Data missing from image " << p1->
file_name() << endl;
199 cerr <<
"Error: Data missing from image " << p2->
file_name() << endl;
208 if ( blend_number ) {
209 pnu = p1->
blend(p2, blend_number);
217 if ( fabs(scale - 1) > 1e-10 ) p2->
multiply(scale);
219 if ( shift ) p2->
add(shift);
242 if ( !pmask && radiusflag ) {
250 cout <<
"Image\tR-factor" << endl;
251 for ( n=0; n<p1->
images(); n++ )
257 if ( corrfile.
length() ) {
258 cc = p1->
correlate(p2, minr, maxr, pmask, 1);
261 }
else if ( setcc ) {
262 cc = p1->
correlate(p2, minr, maxr, pmask, 0);
269 cerr <<
"Too few bins!" << endl;
276 if ( argc > optind && strspn(argv[optind],
"-") != 1 ) {
288 bexit((
int)(1000*cc));
A class for a command line input option.
Vector3< double > scale()
int bexit(int value)
Exit function for cleanup and debugging.
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.
double standard_deviation()
int images_to_slices()
Changes the 2D images to slices in a 3D image.
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 origin(double x, double y, double z)
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.
void add(long j, double v)
double correlate(Bimage *p)
Calculates correlation coefficient between two images.
int slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
long mask_shell(Vector3< double > origin, double rad_min, double rad_max)
void smallest(Bimage *p)
Selects the smallest of each pixel from two images.
void divide_one(Bimage *p, double scale=1, double shift=0)
Divides the first image by the first sub-image of the second.
void divide(Bimage *p, double scale=1, double shift=0)
Divides the first image by the second.
General image parameter class.
CompoundType compound_type()
Utilities for timing functions.
int truncate_to_min_max(double minim, double maxim)
Truncates image data to a given minimum and maximum.
double timer_start()
Starts timer and prints the time.
Header file for general utilities.
ostream & tab(ostream &out)
double timer_report(double lasttime)
Reports the time elapsed since a given time.
void origin(double ox, double oy, double oz)
int main(int argc, char *argv[])
void change_type(char letter)
Get the data type indicated by a single letter code.
Header file for 2D and 3D image I/O.
double linear_fit(Bimage *p, Bimage *pmask, double max_exclude)
Linear least squares fit of two images.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
unsigned char * data_pointer()
void sampling(long nn, Vector3< double > u)
Bimage * blend(Bimage *p, long number)
Blends the two images, creating a new set of sub-images.
DataType
Base data type specifier.
void largest(Bimage *p)
Selects the largest of each pixel from two images.
int histomatch(Bimage *p, long bins)
Fits two images by matching the histogram of the second to the first.
long statistics()
Calculates the statistics for an image.