33 if ( value < 1e-10 ) value = 1;
36 cout <<
"Generating a uniform kernel:" << endl;
37 cout <<
"Size: " << ksize << endl;
38 cout <<
"Value: " << value << endl << endl;
59 if ( sigma < 0.001 ) sigma = 1;
60 if ( fabs(max) < 1e-10 ) max = 1;
62 int side = 2*( (int) (4*sigma + 0.9) ) + 1;
68 cout <<
"Generating a gaussian kernel:" << endl;
69 cout <<
"Size: " << ksize << endl;
70 cout <<
"Sigma: " << sigma << endl;
71 cout <<
"Maximum: " << max << endl << endl;
79 double x2, y2, z2, s2;
80 double invsigma2 = -0.5/(sigma*sigma);
82 for ( i=z=0; z<p->
sizeZ(); z++ ) {
85 for ( y=0; y<p->
sizeY(); y++ ) {
88 for ( x=0; x<p->
sizeX(); x++, i++ ) {
92 p->
set(i, max*exp(s2*invsigma2));
102 if ( sigma < 0.001 ) sigma = 1;
104 int side = 2*( (int) (4*sigma + 0.9) ) + 1;
119 if ( ksize.
volume() <= 1 ) {
120 int side = 2*( (int) (4*sigma + 0.9) ) + 1;
124 if ( sigma < 0.001 ) sigma = 1;
125 if ( max < 1e-10 ) max = 1;
127 if ( ksize.
volume() < 1 ) {
128 cerr <<
"Error: Kernel size = 0!" << endl;
133 cout <<
"Generating a laplacian-of-gaussian kernel:" << endl;
134 cout <<
"Size: " << ksize << endl;
135 cout <<
"Sigma: " << sigma << endl;
136 cout <<
"Maximum: " << max << endl << endl;
145 int i, x, y, z, ndim = 0;
146 if ( ksize.
x() > 1 ) ndim++;
147 if ( ksize.
y() > 1 ) ndim++;
148 if ( ksize.
z() > 1 ) ndim++;
149 double x2, y2, z2, s2;
150 double invsigma2 = 1/(sigma*sigma);
151 double invsigma4 = invsigma2*invsigma2;
152 double scale = max/(ndim*invsigma2);
154 for ( i=z=0; z<p->
sizeZ(); z++ ) {
157 for ( y=0; y<p->
sizeY(); y++ ) {
160 for ( x=0; x<p->
sizeX(); x++, i++ ) {
164 p->
set(i, scale*(s2*invsigma4 - ndim*invsigma2)*exp(-0.5*s2*invsigma2));
188 cerr <<
"Error: No image data to process!" << endl << endl;
195 int i, j, bins = 256;
198 int ihi, imin, nmin, imax = bins/2, nmax = 0, isig = 0;
199 double g, sigma = 8.0/(bins*bins);
200 double scale, offset;
202 int* hist = p->
histogram(bins, scale, offset);
204 for ( i=bins/4, j=(3*bins)/4; i<j; i++ ) {
205 if ( nmax < hist[i] ) {
211 while ( imax+isig < bins - 1 && imax-isig > 0 &&
212 hist[imax] < 2*hist[imax+isig] && hist[imax] < 2*hist[imax-isig] )
216 cout <<
"DEBUG img_filter_extremes: Gaussian parameters:" << endl;
217 cout <<
"DEBUG img_filter_extremes: max=" << nmax <<
" imax=" << imax <<
" sigma=" << isig << endl;
220 if ( isig > 0 ) sigma = -0.5/(isig*isig);
222 for ( i=0; i<bins/4; i++ ) {
223 g = nmax*exp(sigma*(imax - i)*(imax - i));
224 if ( hist[i] > 20*g ) ihi = i;
228 cout <<
"DEBUG img_filter_extremes: highest peak in first quarter = " << ihi << endl;
232 for ( i=ihi; i<bins/4; i++ ) {
233 if ( nmin > hist[i] ) {
240 for ( i=bins-1, j=(3*bins)/4; i>j; i-- ) {
241 g = nmax*exp(sigma*(imax - i)*(imax - i));
242 if ( hist[i] > 20*g ) ihi = i;
246 cout <<
"DEBUG img_filter_extremes: highest peak in last quarter = " << ihi << endl;
250 for ( i=(bins*3)/4; i<ihi; i++ ) {
251 if ( nmin >= hist[i] ) {
259 if ( imin >= imax )
return -1;
261 float min = imin/scale + p->
minimum();
262 float max = imax/scale + p->
minimum();
265 cout <<
"DEBUG img_filter_extremes: imin=" << imin <<
" imax=" << imax <<
" min=" << min <<
" max=" << max << endl;
287 cerr <<
"Error: No image data to process!" << endl << endl;
Header file for image utilities.
Header file for general utilities.
int img_filter_mg_extremes(Bimage *p)
Filters the extremes out of a micrograph image.
Class for complex numbers.
Generalized matrix class.
int truncate_to_min_max(double minim, double maxim)
Truncates image data to a given minimum and maximum.
double average(size_t cc, double xf, double yf, double zf, size_t nn, double iscale)
Averages in the xy plane when scaling is less than 1.
size_t statistics()
Calculates the statistics for an image.
General image parameter class.
Bimage * img_gaussian_kernel(Vector3< int > ksize, float sigma, float max)
Generates a gaussian kernel image.
Header file for image utilities.
size_t blobs(double threshold, double min_size, double max_size, double setvalue, int sign)
Identifies contiguous regions above a given threshold (blobs) and eliminate those less than a minimum...
void set(size_t j, double v)
Sets a single value at the given index.
double standard_deviation()
unsigned char * data_pointer()
Header file for matrix functions.
int img_filter_extremes(Bimage *p, int mod_flag)
Filters the extremes out of an image.
int truncate_to_avg(double minim, double maxim)
Sets voxels in image data exceeding a given minimum and maximum to the average.
Bimage * img_laplacian_of_gaussian_kernel(Vector3< int > ksize, float sigma, float max)
Generates a laplacian-of-gaussian kernel.
Header file for 2D and 3D image I/O.
Bimage * img_average_kernel(Vector3< int > ksize, float value)
Generates a kernel with a uniform non-zero value.
int * histogram(size_t bins, double &scale, double &offset)
Calculates the histogram of an image.
void origin(double ox, double oy, double oz)
Header file for general utilities.