| Bsoft 2.0.5 Bernard's software package

bkernel.cpp
Go to the documentation of this file.
1
9 #include "rwimg.h"
10 #include "FSI_Kernel.h"
11 #include "utilities.h"
12 #include "options.h"
13 #include "timer.h"
14
15 // Declaration of global variables
16 extern int verbose; // Level of output to the screen
17
18 // Usage assistance
19 const char* use[] = {
20 " ",
21 "Usage: bkernel [options] output.krn",
22 "-----------------------------------",
23 "Calculates filter kernels.",
24 "The default kernel just calculates the mean.",
25 "The different types of kernel are mutually exclusive.",
26 " ",
27 "Actions:",
28 "-gaussian 1.7,8.4 Gaussian kernel with the indicated sigma and maximum.",
29 "-log 2.5,5 Laplacian of gaussian kernel with the indicated sigma and maximum.",
30 "-frequency 8,2 Frequency space kernel: width and power.",
31 " ",
32 "Parameters:",
33 "-verbose 7 Verbosity of output.",
34 "-size 5,7,9 Size of kernel (voxels).",
35 " ",
36 NULL
37 };
38
39 int main(int argc, char **argv)
40 {
41 // Initialize variables
42 Vector3<long> size; // Kernel size
43 double sigma(0); // Gaussian sigma
44 double log_sigma(0); // LoG sigma
45 double max(1); // Gaussian or LoG maximum
46 int kernel_width(0); // Frequency space kernel width
47 int kernel_power(2); // Frequency space kernel power
48
49 int optind;
50 Boption* option = get_option_list(use, argc, argv, optind);
51 Boption* curropt;
52 for ( curropt = option; curropt; curropt = curropt->next ) {
53 if ( curropt->tag == "gaussian" )
54 if ( curropt->values(sigma, max) < 1 )
55 cerr << "-gaussian: A sigma value must be specified!" << endl;
56 if ( curropt->tag == "log" )
57 if ( curropt->values(log_sigma, max) < 1 )
58 cerr << "-log: A sigma value must be specified!" << endl;
59 if ( curropt->tag == "frequency" )
60 if ( curropt->values(kernel_width, kernel_power) < 1 )
61 cerr << "-frequency: At least the kernel size must be specified!" << endl;
62 if ( curropt->tag == "size" )
63 size = curropt->size();
64 }
65 option_kill(option);
66
67 double ti = timer_start();
68
69 int side;
70 FSI_Kernel ker;
71
72 if ( size.volume() < 1 ) {
73 if ( log_sigma > 0.001 ) {
74 side = 2*( (int) (4*log_sigma + 0.9) ) + 1;
75 size = {side, side, side};
76 } else if ( sigma > 0.001 ) {
77 side = 2*( (int) (4*sigma + 0.9) ) + 1;
78 size = {side, side, side};
79 } else if ( kernel_width ) {
80 ker = FSI_Kernel(kernel_width, kernel_power);
81 size = {ker.width(), ker.divisions() + 1, 1};
82 } else {
83 size = {3, 3, 3};
84 }
85 }
86
87 Bimage* p = new Bimage(Float, TSimple, size, 1);
88 p->origin(p->default_origin());
89
90 if ( log_sigma ) {
91 p->kernel_laplacian_of_gaussian(log_sigma, max);
92 } else if ( sigma > 0.001 ) {
93 p->kernel_gaussian(sigma, max);
94 } else if ( kernel_width ) {
95 for ( long i=0; i<p->data_size(); ++i ) p->set(i, ker[i]);
96 } else {
97 p->fill(1);
98 }
99
100 if ( p && optind < argc ) {
101 p->label(get_cmd_line(argc, argv));
102 write_img(argv[optind], p, 0);
103 }
104
105 delete p;
106
107 if ( verbose & VERB_TIME )
108 timer_report(ti);
109
110 return 0;
111 }
112
FSI_Kernel::divisions
long divisions()
Definition: FSI_Kernel.h:72
utilities.h
Header file for general utilities.
Boption::tag
Bstring tag
Definition: options.h:29
FSI_Kernel::width
long width()
Definition: FSI_Kernel.h:70
FSI_Kernel
Definition: FSI_Kernel.h:14
get_option_list
Boption * get_option_list(const char *use[], int argc, char *argv[], int &optind)
Parses command line arguments based on a template.
Definition: options.cpp:40
FSI_Kernel.h
Header file for frequency space interpolation kernel.
get_cmd_line
string get_cmd_line(int argc, char **argv)
Returns the command line as a string.
Definition: utilities.cpp:36
TSimple
Definition: Bimage.h:58
timer.h
Utilities for timing functions.
Float
Definition: utilities.h:157
Bimage
General image parameter class.
Definition: Bimage.h:163
Boption::size
Vector3< long > size()
Definition: options.h:163
Boption
A class for a command line input option.
Definition: options.h:26
Bimage::label
void label(string s)
Definition: Bimage.h:235
VERB_TIME
#define VERB_TIME
Definition: utilities.h:110
Bimage::kernel_laplacian_of_gaussian
int kernel_laplacian_of_gaussian(double sigma, double max)
Generates a laplacian-of-gaussian kernel.
Definition: Bimage_filter.cpp:77
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1096
Boption::next
Boption * next
Definition: options.h:28
Bimage::default_origin
Vector3< double > default_origin()
Definition: Bimage.h:585
Vector3< long >
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:67
option_kill
int option_kill(Boption *option)
Deallocates a linked list of option structures.
Definition: options.cpp:109
use
const char * use[]
Definition: bkernel.cpp:19
rwimg.h
Header file for 2D and 3D image I/O.
options.h
Header file for option handlers.
Bimage::fill
void fill(double v)
Definition: Bimage.h:698
verbose
int verbose
Vector3::volume
double volume()
Definition: Vector3.h:235
Bimage::kernel_gaussian
int kernel_gaussian(double sigma, double max)
Generates a gaussian kernel image.
Definition: Bimage_filter.cpp:34
Boption::values
long values(T1 &v1, T2 &v2)
Definition: options.h:115
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:52
Bimage::data_size
long data_size()
Definition: Bimage.h:255
main
int main(int argc, char **argv)
Definition: bkernel.cpp:39
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563