 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
20 "Usage: beditimg [options] [input.img] output.img",
21 "------------------------------------------------",
22 "Creates a new image or modifies an input image by inserting or deleting regions.",
25 "-create 20,60,30 Create a new image of this size (pixels/voxels).",
26 " Note: No input image is read and the first file name is taken as the output image.",
27 "-rescale -0.1,5.2 Rescale data to average and standard deviation.",
28 "-box 0,3,44,50,30,44 Start (lower-left-back voxel) and size of box (voxels).",
29 "-sphere 22,5,39,120 Center and radius from center of sphere (voxels).",
30 "-shell 32,45,23,20,120 Center and inner and outer radii of shell (voxels).",
31 "-cylinder 41,76,9,12,23 Center, radius and height of cylinder (voxels).",
32 "-gaussian 45,55,12,14.5 Center and sigma of gaussian sphere (voxels).",
33 "-quadratic 1,2,1,2,1,2,1 Create a quadratic image (7 parameters).",
34 "-gradient quad Correct for the gradient in an image: linear or quadratic.",
35 "-tetrahedron 9,-3,4,... Extract a tetrahedron defined by four sets of 3-valued vectors.",
38 "-verbose 7 Verbosity of output.",
39 "-datatype u Force writing of a new data type.",
40 "-origin 60.4,-32.2,44 Origin of image (voxels).",
41 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
42 "-images 12 Number of images (default: 1).",
43 "-fill 0.02 Fill value: average (default), background, or value.",
44 "-background -1.2 Fill a newly created image with a background value.",
45 "-edgewidth 10 Gaussian width of edge of region to delete (voxels, <0 inverts selection).",
46 "-wrap Turn wrapping on (default off).",
48 "Parameters for placing an image (use with -place):",
49 "-location 33,12,56 Location to place an input image.",
50 "-rotate 0,0.4,0.7,52 Rotation applied before placing an input image.",
53 "-place img.pif An image to place within a larger image.",
58 int main(
int argc,
char* argv[])
67 double nuavg(0), nustd(0);
74 double sphereradius(0);
76 double shellminrad(0);
77 double shellmaxrad(0);
82 double quad[7] = {0,0,0,0,0,0,0};
84 int correct_gradient(0);
96 for ( curropt = option; curropt; curropt = curropt->
next ) {
99 if ( curropt->
tag ==
"create" )
100 nusize = curropt->
size();
101 if ( curropt->
tag ==
"datatype" )
103 if ( curropt->
tag ==
"sampling" )
104 sam = curropt->
scale();
105 if ( curropt->
tag ==
"images" )
107 cerr <<
"-images: The number of images must be specified!" << endl;
108 if ( curropt->
tag ==
"rescale" )
109 if ( curropt->
values(nuavg, nustd) < 2 )
110 cerr <<
"-rescale: Both average and standard deviation must be specified!" << endl;
111 if ( curropt->
tag ==
"fill" )
112 fill = curropt->
fill(fill_type);
113 if ( curropt->
tag ==
"background" )
114 if ( ( background = curropt->
value.
real() ) == 0 )
115 cerr <<
"-background: A background value must be specified!" << endl;
116 if ( curropt->
tag ==
"box" )
117 if ( curropt->
box(boxstart, boxsize) < 6 )
118 cerr <<
"-box: A position and size must be specified!" << endl;
119 if ( curropt->
tag ==
"edgewidth" ) {
121 if ( fabs(width) < 0.001 )
122 cerr <<
"-edgewidth: An edge width must be specified!" << endl;
124 if ( curropt->
tag ==
"sphere" )
125 if ( curropt->
values(spherecenter[0],
126 spherecenter[1], spherecenter[2], sphereradius) < 4 )
127 cerr <<
"-sphere: A position and radius must be specified!" << endl;
128 if ( curropt->
tag ==
"shell" ) {
130 cerr <<
"-shell: A position and two radii must be specified!" << endl;
132 for ( i=0; i<3; i++ ) shellcenter[i] = d[i];
137 if ( curropt->
tag ==
"cylinder" ) {
139 cerr <<
"-cylinder: A position, radius and height must be specified!" << endl;
141 for ( i=0; i<3; i++ ) cylcenter[i] = d[i];
146 if ( curropt->
tag ==
"gaussian" ) {
148 cerr <<
"-gaussian: 4 parameters must be specified!" << endl;
150 for ( i=0; i<3; i++ ) spherecenter[i] = d[i];
154 if ( curropt->
tag ==
"quadratic" ) {
156 cerr <<
"-quadratic: 7 parameters must be specified!" << endl;
158 for (
size_t i=0; i<d.size(); i++ ) quad[i] = d[i];
160 if ( curropt->
tag ==
"gradient" ) {
161 if ( curropt->
value[0] ==
'q' ) correct_gradient = 2;
162 else correct_gradient = 1;
164 if ( curropt->
tag ==
"tetrahedron" ) {
166 cerr <<
"-tetrahedron: Twelve values must be specified!" << endl;
168 for ( i=0; i<4; i++ )
169 for ( j=0; j<3; j++ )
174 if ( curropt->
tag ==
"origin" ) {
175 if ( curropt->
value[0] ==
'c' ) {
178 origin = curropt->
origin();
182 if ( curropt->
tag ==
"wrap" )
184 if ( curropt->
tag ==
"location" )
185 if ( curropt->
values(loc[0], loc[1], loc[2]) < 3 )
186 cerr <<
"-location: All three location coordinates must be specified!" << endl;
187 if ( curropt->
tag ==
"rotate" ) {
188 if ( curropt->
values(axis[0], axis[1], axis[2], angle) < 4 )
189 cerr <<
"-rotate: All three vector elements and an angle must be specified!" << endl;
193 if ( curropt->
tag ==
"place" )
201 if ( nusize[0] > 0 && nusize[1] > 0 && nusize[2] > 0 ) {
204 if ( background ) p->
fill(background);
206 p =
read_img(argv[optind++], 1, -1);
208 cerr <<
"Error: No input file read or output size specified!" << endl;
218 if ( set_origin == 2 ) p->
origin(p->
size()/2);
224 if ( boxsize.
volume() > 0 )
225 p->
shape(0, boxsize, boxstart, width, fill_type, fill);
228 p->
sphere(spherecenter, sphereradius, width, fill_type, fill);
233 if ( shellmaxrad > 0 ) {
235 p->
shell_wrap(0, shellcenter, shellminrad, shellmaxrad, width, fill_type, fill);
237 p->
shell(0, shellcenter, shellminrad, shellmaxrad, width, fill_type, fill);
240 if ( cylradius && cylheight )
241 p->
cylinder(cylcenter, cylradius, cylheight, width, fill_type, fill);
248 if ( angle ) pp->
rotate(axis, angle);
249 p->
place(0, pp, loc, 1e30, 1, 0, 0);
266 for (
long n=1; n<nimg; ++n ) pm->
replace(n, p);
272 if ( optind < argc ) {
A class for a command line input option.
Vector3< double > scale()
Bimage * extract_tetrahedron(Vector3< double > *tet, int fill_type=0, double fill=0)
Extracts a tetrahedral part of the image.
int main(int argc, char *argv[])
int shell(Vector3< double > center, double minrad, double maxrad, double width, int fill_type=0, double fill=0)
Fills a shell within an image with a uniform value.
Bimage * copy()
Copies the header information and data of an image into a new image structure.
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.
double background(long nn)
Vector3< long > size() const
Header file for option handlers.
Vector3< double > origin()
int shell_wrap(long nn, Vector3< double > center, double minrad, double maxrad, double width, int fill_type=0, double fill=0)
Fills a shell within an image with a uniform value with wrapping.
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.
int quadric_correct(vector< double > param)
Corrects for a quadric surface.
int gradient_correction()
Calculates and corrects for a linear gradient across an image.
int rotate()
Rotates an image using parameters defined in the image in place.
int cylinder(Vector3< double > center, double radius, double height, double width, int fill_type=0, double fill=0)
Fills a cylinder within an image with a uniform value.
General image parameter class.
int shape(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Creates a shape in an image and fills it with a constant value.
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)
vector< double > split_into_doubles(const Bstring &delim)
int replace(Bimage *img)
Replaces the data with that from the given image.
int place(long nn, Bimage *p, Vector3< double > loc, double radius=0, double scale=1, double shift=0, int operation=0)
Places a small image into a large image.
vector< double > quadric_fit()
Fits the whole image to a quadric surface.
double timer_start()
Starts timer and prints the time.
Header file for general utilities.
double fill(int &fill_type)
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.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
void sampling(long nn, Vector3< double > u)
DataType
Base data type specifier.
int quadric(double *param)
Generates a quadric surface over the whole image.
int sphere(Vector3< double > center, double radius, double width=0, int fill_type=0, double fill=0)
Fills a sphere within an image with a uniform value.
int gaussian_sphere(long nn, Vector3< double > center, double sigma, double amp)
Fills a gaussian sphere within an image with a uniform value.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.