 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
21 "Usage: bfilter [options] input.img output.img",
22 "---------------------------------------------",
26 "-invert Invert density in the image.",
27 "-rescale -0.1,5.2 Rescale data to average and standard deviation after filtering.",
28 "-minmax -0.5,1.2 Rescale data to minimum and maximum.",
29 "-average 7,5,3 Averaging/smoothing filter: kernel size.",
30 "-gaussian 11,2.6 Gaussian smoothing filter: kernel size and sigma.",
31 "-median 3 Median filter: kernel edge size.",
32 "-peak 5 Peak filter: kernel edge size.",
33 "-gradient Gradient filter (3x3x3).",
34 "-laplacian Laplacian filter (3x3x3).",
35 "-LoG 2.5 Laplacian-of-Gaussian filter.",
36 "-DoG 1.5,3.1 Difference-of-Gaussians filter.",
37 "-denoise 2,0.4 Denoising filter: distance and density difference sigmas.",
38 "-rollingball 5,4.3 Rolling ball filter: radius and density scaling (default scaling=1).",
39 "-variance 11,1 Calculate a local variance image using the given size kernel,",
40 " with a flag to indicate standard deviation rather than variance.",
41 "-extremes his Filter image extremes: his=histogram-based, mg=for micrograph.",
42 "-replacemaxima 1.5 Replace maxima above the given threshold with surrounding average.",
43 "-bandpass 25.3,200,0.02 Bandpass filter: resolution limits (angstrom) and band edge width (1/angstrom).",
44 "-amplitude 8.3 Amplitude filter: setting all amplitudes below the threshold to zero.",
45 "-phasesonly Set all amplitudes to one.",
46 "-Bfactor 44,25.3 B-factor application: B-factor (A^2), high resolution limit (A,optional)",
47 " Multiplied in reciprocal space by exp(-B-factor/4 * s^2).",
50 "-verbose 1 Verbosity of output.",
51 "-datatype u Force writing of a new data type.",
52 "-sampling 1.5,1.5,1.5 Sampling (A/pixel; default from input file; a single value can be given).",
53 "-origin 10,-10,20 Origin for rotation (default 0,0,0).",
54 "-wrap Turn wrapping on (default off, use with -denoise option).",
57 "-kernel file.txt Convolve image with a kernel specified in a text file.",
62 int main(
int argc,
char **argv)
70 double nuavg(0), nustd(0);
72 double newmin(0), newmax(0);
74 long gauss_kernel(0), sigma(0);
75 long median_kernel(0);
81 double sigma1(0), sigma2(0);
93 double bandpass_width(0);
94 double amp_threshold(0);
96 int filter_extremes(0);
97 double replace_threshold(0);
103 for ( curropt = option; curropt; curropt = curropt->
next ) {
104 if ( curropt->
tag ==
"datatype" )
106 if ( curropt->
tag ==
"sampling" )
107 sam = curropt->
scale();
108 if ( curropt->
tag ==
"origin" ) {
109 if ( curropt->
value[0] ==
'c' ) {
112 origin = curropt->
origin();
116 if ( curropt->
tag ==
"invert" )
118 if ( curropt->
tag ==
"rescale" ) {
119 if ( curropt->
values(nuavg, nustd) < 2 )
120 cerr <<
"-rescale: Both average and standard deviation must be specified!" << endl;
121 else if ( nustd <= 0 )
122 cerr <<
"-rescale: A positive standard deviation must be specified!" << endl;
124 if ( curropt->
tag ==
"minmax" ) {
125 if ( curropt->
values(newmin, newmax) < 2 )
126 cerr <<
"-minmax: Both min and max must be specified!" << endl;
129 if ( newmin == newmax ) setminmax = 0;
131 if ( curropt->
tag ==
"average" ) {
132 if ( ( i = curropt->
values(average_kernel[0],
133 average_kernel[1], average_kernel[2]) ) < 1 )
134 cerr <<
"-average: The kernel edge size must be specified!" << endl;
136 if ( i < 2 ) average_kernel[2] = average_kernel[1] = average_kernel[0];
138 if ( curropt->
tag ==
"gaussian" )
139 if ( curropt->
values(gauss_kernel, sigma) < 2 )
140 cerr <<
"-gaussian: The kernel edge size and sigma must be specified!" << endl;
141 if ( curropt->
tag ==
"median" )
143 cerr <<
"-median: The kernel edge size must be specified!" << endl;
144 if ( curropt->
tag ==
"peak" )
146 cerr <<
"-peak: The kernel edge size must be specified!" << endl;
147 if ( curropt->
tag ==
"gradient" ) gradient = 1;
148 if ( curropt->
tag ==
"laplacian" ) laplacian = 1;
149 if ( curropt->
tag ==
"LoG" ) {
150 if ( ( log_sigma = curropt->
real() ) < 0.1 )
151 cerr <<
"-LoG: A sigma value must be specified!" << endl;
155 if ( curropt->
tag ==
"DoG" )
156 if ( curropt->
values(dog1, dog2) < 2 )
157 cerr <<
"-DoG: Two sigma values must be specified!" << endl;
158 if ( curropt->
tag ==
"denoise" )
159 if ( curropt->
values(sigma1, sigma2) < 2 )
160 cerr <<
"-denoise: Both denoising sigmas must be specified!" << endl;
161 if ( curropt->
tag ==
"rollingball" )
162 if ( curropt->
values(ball_radius, ball_scale) < 1 )
163 cerr <<
"-rollingball: At least a ball radius must be specified!" << endl;
164 if ( curropt->
tag ==
"variance" )
165 if ( curropt->
values(var_kernel, std_flag) < 1 )
166 cerr <<
"-variance: The kernel edge size must be specified!" << endl;
167 if ( curropt->
tag ==
"kernel" )
169 if ( curropt->
tag ==
"extremes" ) {
171 else if ( curropt->
value.
contains(
"mg") ) filter_extremes = 2;
172 else cerr <<
"-extremes: The type of filtering must be specified!" << endl;
174 if ( curropt->
tag ==
"replacemaxima" ) {
175 if ( ( replace_threshold = curropt->
value.
real() ) < 0.0000001 )
176 cerr <<
"-replacemaxima: A threshold must be specified!" << endl;
180 if ( curropt->
tag ==
"bandpass" ) {
181 if ( curropt->
values(res_hi, res_lo, bandpass_width) < 1 )
182 cerr <<
"-bandpass: A resolution limit must be specified!" << endl;
184 if ( res_lo > 0 && res_hi > res_lo ) swap(res_hi, res_lo);
185 if ( res_hi != res_lo ) bandpass = dofft = 1;
188 if ( curropt->
tag ==
"amplitude" ) {
189 if ( ( amp_threshold = curropt->
value.
real() ) < 0.0000001 )
190 cerr <<
"-amplitude: A threshold must be specified!" << endl;
194 if ( curropt->
tag ==
"phasesonly" )
195 phases_only = dofft = 1;
196 if ( curropt->
tag ==
"Bfactor" ) {
197 if ( curropt->
values(Bfactor, res_hi) < 1 )
198 cerr <<
"-Bfactor: A B-factor must be specified!" << endl;
209 fftwf_init_threads();
217 if ( optind < argc - 1 ) dataflag = 1;
219 if ( p == NULL )
bexit(-1);
227 if ( set_origin == 2 ) p->
origin(p->
size()/2);
241 if ( median_kernel > 0 ) p->
filter_rank(median_kernel, 0.5);
243 if ( peak_kernel > 0 ) {
251 if ( var_kernel > 0 ) {
252 if ( std_flag & 2 ) {
267 if ( kernel_file.
length() ) {
268 pkernel =
read_img(kernel_file, 1, 0);
277 if ( dog1 >0 && dog2 > 0 )
280 if ( sigma1 > 0 && sigma2 > 0 )
303 if ( setinvert ) p->
invert();
309 if ( optind < argc ) {
317 fftwf_cleanup_threads();
A class for a command line input option.
int filter_gaussian(long kernel_size, double sigma)
Applies a gaussian filter to an image.
Vector3< double > scale()
FourierType
Fourier transform format specifier.
size_t system_processors()
Returns the number of processors.
Header file for functions to read and write kernel files.
int variance(long kernel_size, int flag=0)
Calculates the local variance within the given kernel.
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.
Vector3< double > origin()
int filter_rank(long kernel_size, double rank)
Applies a median filter to an image.
int convolve(Bimage *pkernel)
Convolves an image with an arbitrary size convolution filter.
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)
FourierType fourier_type()
General image parameter class.
Utilities for timing functions.
double timer_start()
Starts timer and prints the time.
int fspace_bandpass(double res_hi, double res_lo=0, double width=0)
Applies a bandpass filter to an image.
int fspace_weigh_B_factor(double B, double resolution=0)
Weighs an image's amplitudes with B-factor (gaussian) curve.
Header file for general utilities.
int fspace_amp_threshold(double threshold)
Filters the amplitudes of the Fourier transform of an image.
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 fspace_amp_one()
Sets all amplitudes to one.
int filter_average(long kernel_size)
Applies an averaging filter to an image.
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.
Bimage * filter_peak(long kernel_size)
Finds the peaks in an image.
void square_root()
Calculates the square root of an image.
void sampling(long nn, Vector3< double > u)
int fspace_weigh_LoG(double resolution, double sigma)
Weighs an image's amplitudes with a Laplacian-of-Gaussian function.
DataType
Base data type specifier.
bool contains(const Bstring &s)
int filter_dog(double sigma1, double sigma2)
Convolves the image with a difference of gausians kernel.
int filter_ortho(int type)
Convolves the image with an orthogonal kernel with wrapping.
int filter_rolling_ball(long radius, double scale)
Apply a rolling ball filter.
int filter_bilateral(double sigma1, double sigma2, int kernel_type, long kernel_radius)
Denoise an image with combined gaussian distance and density difference kernel.
int filter_extremes()
Filters the extremes out of a micrograph 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.
long replace_maxima(double threshold)
Replaces maxima above a threshold using local averages.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.