 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
21 "Usage: brandom [options] [input.img] output.img",
22 "-----------------------------------------------",
23 "Generates random content images.",
24 "If an input image is not found a random output image is generated.",
25 "The default output data type is floating point.",
28 "-type gauss Distribution type (default: uniform, ",
29 " others: gaussian, poisson, logistical, spectral).",
30 "-rescale -0.1,5.2 Rescale output data to average and standard deviation.",
33 "-verbose 7 Verbosity of output.",
34 "-datatype u Data type (default: byte).",
35 "-images 12 Number of images (default: 1).",
36 "-size 10,50,8 Size (default: 256,256,1).",
37 "-sampling 1.5,1.5,1.5 Sampling (default: 1,1,1; a single value can be given).",
38 "-origin 0,-10,30 Set the origin (default image origin).",
39 "-minmax -1.2,5.6 Set minimum and maximum of input and uniform random image (default: -1.732,1.732).",
40 "-avgstd 0.5,2.3 Set average and standard deviation of input and non-uniform random image (default: 0,1).",
41 "-alpha 2 Spectral noise decay (default: white=0, pink=1, red/brown=2, blue=-1, violet=-2).",
42 "-snr 1.4,63 Signal-to-noise ratio and foreground radius (default: 1).",
47 int main(
int argc,
char **argv)
57 double min(-sqrt(3.0)), max(sqrt(3.0));
58 double avg(0), std(1);
61 double finalavg(0), finalstd(0);
63 double foreground_radius(0);
69 for ( curropt = option; curropt; curropt = curropt->
next ) {
70 if ( curropt->
tag ==
"datatype" )
72 if ( curropt->
tag ==
"origin" ) {
73 if ( curropt->
value[0] ==
'c' ) {
76 origin = curropt->
origin();
80 if ( curropt->
tag ==
"sampling" ) {
81 sampling = curropt->
scale();
84 if ( curropt->
tag ==
"type" ) {
85 if ( curropt->
value[0] ==
'u' ) rand_type = 0;
86 else if ( curropt->
value[0] ==
'g' ) rand_type = 1;
87 else if ( curropt->
value[0] ==
'p' ) rand_type = 2;
88 else if ( curropt->
value[0] ==
'l' ) rand_type = 3;
89 else if ( curropt->
value[0] ==
's' ) rand_type = 4;
91 cerr <<
"-type: Type " << curropt->
value <<
" not supported! Default to uniform distribution" << endl;
93 if ( curropt->
tag ==
"minmax" ) {
94 if ( curropt->
values(min, max) < 2 )
95 cerr <<
"-minmax: Both min and max must be specified!" << endl;
96 if ( min > max ) swap(min, max);
102 if ( curropt->
tag ==
"avgstd" ) {
103 if ( curropt->
values(avg, std) < 1 )
104 cerr <<
"-avgstd: At least the average must be specified!" << endl;
105 if ( std < 0 ) std = -std;
106 if ( std == 0 ) std = 1;
109 if ( curropt->
tag ==
"alpha" )
110 if ( ( alpha = curropt->
value.
real() ) < 0 )
111 cerr <<
"-alpha: A positive spectral decay must be specified!" << endl;
112 if ( curropt->
tag ==
"rescale" )
113 if ( curropt->
values(finalavg, finalstd) < 2 )
114 cerr <<
"-rescale: Both average and standard deviation must be specified!" << endl;
115 if ( curropt->
tag ==
"images" )
117 cerr <<
"-images: The number of images must be specified!" << endl;
118 if ( curropt->
tag ==
"size" )
119 size = curropt->
size();
120 if ( curropt->
tag ==
"snr" ) {
121 if ( curropt->
values(snr, foreground_radius) < 1 )
122 cerr <<
"-snr: A value must be specified!" << endl;
124 if ( snr <= 0 ) snr = 1;
130 cout <<
"Random number range: " <<
get_rand_max() << endl;
134 double scale, fg = 1e30;
138 if ( optind < argc - 1 ) {
139 p =
read_img(argv[optind++], 1, -1);
141 if ( rand_type > 0 ) {
158 if ( size[0] < 1 ) size[0] = 256;
159 if ( size[1] < 1 ) size[1] = 256;
160 if ( size[2] < 1 ) size[2] = 1;
164 switch ( rand_type ) {
183 if ( foreground_radius ) {
184 if ( p->
sizeZ() < 2 ) fg =
M_PI*foreground_radius*foreground_radius;
185 else fg = (
M_PI*4.0/3.0)*foreground_radius*foreground_radius*foreground_radius;
188 scale = sqrt(size.
volume()/(snr*fg));
189 p->
add(pran, scale, -avg);
198 if ( set_sampling ) pran->
sampling(sampling);
201 if ( set_origin == 2 ) pran->
origin(pran->
size()/2);
202 else pran->
origin(origin);
A class for a command line input option.
Vector3< double > scale()
Header file for functions for creating random images.
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.
int noise_uniform(double rmin, double rmax)
Generates an image with a uniform random distribution of densities.
Vector3< double > origin()
double standard_deviation()
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 main(int argc, char **argv)
void add(long j, double v)
int noise_logistical(double ravg, double rstd)
Generates an image with a gaussian random distribution of densities.
int noise_gaussian(double ravg=0, double rstd=1)
Generates an image with a gaussian random distribution of densities.
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.
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.
int rescale_to_min_max(double numin, double numax)
Rescales the image data to a given minimum and maximum.
int noise_poisson(double ravg)
Generates an image with a poisson random distribution of densities.
int option_kill(Boption *option)
Deallocates a linked list of option structures.
void sampling(long nn, Vector3< double > u)
long get_rand_max()
Finds the maximum random number for a system.
DataType
Base data type specifier.
long statistics()
Calculates the statistics for an image.
int noise_spectral(double alpha)
Generates a noise map with a defined spectral decay.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.