 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
20 "Usage: bimg [options] input.img output.img",
21 "------------------------------------------",
22 "Manipulates images in a few general ways.",
23 "Image format extensions supported:",
24 "BioRad (pic), Brix (brx), CCP4 (map), Digital Instruments (di)",
25 "EM (em), Goodford (pot), GRD (grd), Imagic (img), JPEG, (jpg), MFF (mff)",
26 "Image Magick (miff), MRC (mrc), PIC (bp), PIF (pif), Spider (spi)",
27 "Suprim (spm), TIFF (tif), RAW (raw)",
30 "-delete 1,5-13,122 Delete the indicated sub-images (first image = 0).",
31 "-slices Interpret multiple 2D images as z-slices of a single 3D image",
32 "-images Interpret slices of a single 3D image as 2D images",
33 "-invert Invert density in the image.",
34 "-project Project along z axis (after reslicing).",
35 "-sum Sum images in a multi-image file.",
36 "-average Average images in a multi-image file.",
37 "-reslice -z+xy Reslice = switch axes (default xyz).",
38 "-size 10,50,8 New image size (pixels/voxels).",
39 "-translate -5,12,50 Translate (pixels, with wrapping if option -wrap is used).",
40 "-Wrap 10,50,8 Shrinking and wrapping an image (pixels).",
41 "-truncate -0.5,1.2 Truncate data to minimum and maximum.",
42 "-rescale -0.1,5.2 Rescale data to average and standard deviation (after -truncate).",
43 "-minmax -0.5,1.2 Rescale data to minimum and maximum (after -truncate).",
44 "-range -2.3,5.4 Fill with fill value outside this range.",
45 "-logarithm Calculate the logarithm of an image.",
46 "-Levels 8 Restrict to a number of levels.",
47 "-compression 2 Compression type: 5=LZW.",
50 "-verbose 7 Verbosity of output.",
51 "-datatype u Force writing of a new data type.",
52 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; a single value can be given).",
53 "-origin 0.8,-10,15.7 Set the origin (default from input image).",
54 "-select 1 Select an image (first image = 0; default: all images).",
55 "-fill 127 Fill value for resizing: average (default), background, or value.",
56 "-setbackground 0.5 Set background.",
57 "-wrap Turn wrapping on (default off).",
60 "-std stdev.mrc Standard deviation map.",
65 int main(
int argc,
char **argv)
78 double nuavg(0), nustd(0);
79 double numin(0), numax(0);
80 double rangemin(0), rangemax(0);
82 double cutmin(0), cutmax(0);
97 double nubackground(-1);
106 for ( curropt = option; curropt; curropt = curropt->
next ) {
107 if ( curropt->
tag ==
"select" ) {
110 select_list = curropt->
value;
114 if ( curropt->
tag ==
"delete" ) {
115 delete_list = curropt->
value;
116 if ( delete_list.
length() < 1 )
117 cerr <<
"-delete: Image numbers must be specified!" << endl;
119 if ( curropt->
tag ==
"datatype" )
121 if ( curropt->
tag ==
"sampling" )
122 sam = curropt->
scale();
123 if ( curropt->
tag ==
"invert" )
125 if ( curropt->
tag ==
"project" )
127 if ( curropt->
tag ==
"average" )
129 if ( curropt->
tag ==
"sum" )
131 if ( curropt->
tag ==
"wrap" )
133 if ( curropt->
tag ==
"Wrap" ) {
134 nusize = curropt->
size();
137 if ( curropt->
tag ==
"fill" )
138 fill = curropt->
fill(fill_type);
139 if ( curropt->
tag ==
"reslice" ) {
141 cerr <<
"-reslice: The order of x, y and z must be specified!" << endl;
143 order = curropt->
value;
147 if ( curropt->
tag ==
"rescale" ) {
148 if ( curropt->
values(nuavg, nustd) < 2 )
149 cerr <<
"-rescale: Both average and standard deviation must be specified!" << endl;
152 if ( nustd <= 0 ) setrescale = 0;
154 if ( curropt->
tag ==
"minmax" ) {
155 if ( curropt->
values(numin, numax) < 2 )
156 cerr <<
"-minmax: Both min and max must be specified!" << endl;
159 if ( numin == numax ) setrescale = 0;
161 if ( curropt->
tag ==
"range" )
162 if ( curropt->
values(rangemin, rangemax) < 2 )
163 cerr <<
"-range: Both range min and max must be specified!" << endl;
164 if ( curropt->
tag ==
"logarithm" )
166 if ( curropt->
tag ==
"truncate" ) {
167 if ( curropt->
values(cutmin, cutmax) < 2 )
168 cerr <<
"-truncate: Both min and max must be specified!" << endl;
171 if ( cutmin > cutmax ) swap(cutmin, cutmax);
172 if ( cutmin == cutmax ) settruncate = 0;
174 if ( curropt->
tag ==
"size" )
175 nusize = curropt->
size();
176 if ( curropt->
tag ==
"origin" ) {
177 if ( curropt->
value[0] ==
'c' ) {
180 origin = curropt->
origin();
184 if ( curropt->
tag ==
"translate" ) {
186 if ( shift.
length() ) settranslate = 1;
189 if ( curropt->
tag ==
"compression" )
190 if ( ( compression = curropt->
integer() ) < 1 )
191 cerr <<
"-compression: A number must be specified!" << endl;
192 if ( curropt->
tag ==
"setbackground" ) {
196 if ( curropt->
tag ==
"slices" )
198 if ( curropt->
tag ==
"images" )
200 if ( curropt->
tag ==
"std" )
209 if ( optind < argc - 1 ) dataflag = 1;
211 if ( p == NULL )
bexit(-1);
219 if ( select_list.
length() )
222 if ( delete_list.
length() )
230 if ( setbackground ) p->
background(nubackground);
239 if ( nusize.
volume() > 0 ) {
244 if ( setwrap ) cout <<
"Resizing with wrapping:" << endl;
245 else cout <<
"Resizing:" << endl;
246 cout <<
"Shift: " << shift << endl;
247 cout <<
"New size: " << nusize << endl;
249 cout <<
"Fill value: " << fill << endl;
252 cout <<
"Resizing" << endl << endl;
255 else p->
resize(nusize, shift, fill_type, fill);
257 }
else if ( settranslate ) {
259 else p->
shift(shift, fill_type, fill);
262 if ( setinvert ) p->
invert();
266 p->
truncate(cutmin, cutmax, fill, fill);
274 if ( rangemin < rangemax ) {
277 else p->
truncate(rangemin, rangemax, fill, fill);
282 if ( setreslice ) p->
reslice(order);
314 if ( optind < argc ) {
321 if ( stdfile.
length() && p2 )
A class for a command line input option.
int shrink_wrap(Vector3< long > nusize, Vector3< long > translate)
Shrinks an image to a new size with wrapping of the excluded edges.
Vector3< double > scale()
int truncate(double minim, double maxim, double setmin, double setmax)
Truncates image data to a given minimum and maximum.
int shift(Vector3< double > vec, int fill_type=0, double fill=0)
Shifts an image.
void reslice(const char *order)
int truncate_to_background(double minim, double maxim)
Sets voxels in image data exceeding a given minimum and maximum to the image background.
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.
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
int shift_wrap(Vector3< double > vec)
Shifts an image.
Vector3< double > origin()
long delete_images(Bstring list, int retain=0)
Retains or deletes sub-images from a multi-image structure.
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.
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Bimage * project(char axis, int flags=1)
Projects a 3D image to a 2D image down one of the three major axes.
int resize_wrap(Vector3< long > nusize, Vector3< long > translate)
Resizes without interpolation or rescaling.
int slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
int truncate_to_avg(double minim, double maxim)
Sets voxels in image data exceeding a given minimum and maximum to the average.
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.
void sum_images()
Adds all sub-images.
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.
Vector3< double > vector3()
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)
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.
int rescale_to_min_max(double numin, double numax)
Rescales the image data to a given minimum and maximum.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
void invert()
Inverts the data in the image.
void sampling(long nn, Vector3< double > u)
int limit_levels(int nlevels)
Converts a full gray scale image to a limited level image.
DataType
Base data type specifier.
bool contains(const Bstring &s)
void logarithm()
Calculates the logarithm of the image data.
int resize(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
long select_images(Bstring list)
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.