26 if ( !p->
FOM() )
return -1;
30 float* fom = p->
FOM();
33 cout <<
"Weighing image by its FOM" << endl << endl;
35 for ( i=0; i<n; i++ ) {
53 if ( !p->
FOM() )
return -1;
55 if ( wiener < 1e-10 ) wiener = 1e-10;
58 cout <<
"Dividing the image by its FOM" << endl << endl;
62 float* fom = p->
FOM();
64 for ( i=0; i<n; i++ ) {
65 if ( fom[i] < wiener ) v = (*p)[i]/wiener;
66 else v = (*p)[i]/fom[i];
81 cerr <<
"Error: File " << p->
file_name() <<
" must be a real space map!" << endl;
88 cout <<
"Changing the amplitudes to their square roots" << endl << endl;
94 for ( i=0; i<n; i++ ) {
113 cerr <<
"Error: File " << p->
file_name() <<
" must be a real space map!" << endl;
120 cout <<
"Changing the amplitudes to their squares" << endl << endl;
126 for ( i=0; i<n; i++ ) {
140 cerr <<
"Error: File " << p->
file_name() <<
" must be a real space map!" << endl;
149 unsigned long i, j, n, x, y, z, iradius, iradius2;
150 long xx, yy, zz, ix, iy, iz;
151 double radius, fraction, fraction2, amp;
152 double rx, ry, rz, scale;
158 double* num =
new double[maxrad];
159 double* rps =
new double[maxrad];
161 for ( n=0; n<p->
images(); n++ ) {
163 for ( i=0; i<maxrad; i++ ) num[i] = rps[i] = 0;
164 for ( z=0; z<p->
sizeZ(); z++ ) {
166 if ( z > (p->
sizeZ() - 1)/2 ) zz -= p->
sizeZ();
167 rz = zz*freq_scale.
z();
169 if ( iz < 0 ) iz += p->
sizeZ();
170 for ( y=0; y<p->
sizeY(); y++ ) {
172 if ( y > (p->
sizeY() - 1)/2 ) yy -= p->
sizeY();
173 ry = yy*freq_scale.
y();
175 if ( iy < 0 ) iy += p->
sizeY();
176 for ( x=0; x<p->
sizeX()/2; x++ ) {
179 if ( x > (p->
sizeX() - 1)/2 ) xx -= p->
sizeX();
180 rx = xx*freq_scale.
x();
182 if ( ix < 0 ) ix += p->
sizeX();
184 radius = rad_scale*sqrt(rx*rx + ry*ry + rz*rz);
185 iradius = (int) radius;
186 iradius2 = iradius + 1;
187 if ( iradius2 < maxrad ) {
188 fraction = radius - iradius;
189 fraction2 = 1.0 - fraction;
191 num[iradius] += fraction2;
192 num[iradius2] += fraction;
193 rps[iradius] += fraction2*amp;
194 rps[iradius2] += fraction*amp;
204 for ( i=0; i<maxrad; i++ )
205 if ( num[i] ) rps[i] /= num[i];
208 cout <<
"Scaling for image " << n+1 <<
":\ns\tRPS\tC\tScale" << endl;
209 for ( i=0; i<maxrad; i++ ) {
210 if ( rps[i] ) scale = curve[i]/rps[i];
212 cout << i/rad_scale <<
tab << rps[i] <<
tab << curve[i] <<
tab << scale << endl;
217 for ( i=0; i<maxrad; i++ )
218 if ( rps[i] ) rps[i] = curve[i]/rps[i];
220 for ( z=0; z<p->
sizeZ(); z++ ) {
222 if ( z > (p->
sizeZ() - 1)/2 ) zz -= p->
sizeZ();
223 rz = zz*freq_scale.
z();
224 for ( y=0; y<p->
sizeY(); y++ ) {
226 if ( y > (p->
sizeY() - 1)/2 ) yy -= p->
sizeY();
227 ry = yy*freq_scale.
y();
228 for ( x=0; x<p->
sizeX(); x++ ) {
231 if ( x > (p->
sizeX() - 1)/2 ) xx -= p->
sizeX();
232 rx = xx*freq_scale.
x();
233 radius = rad_scale*sqrt(rx*rx + ry*ry + rz*rz);
234 iradius = (int) radius;
235 iradius2 = iradius + 1;
236 if ( iradius2 < maxrad ) {
237 fraction = radius - iradius;
238 fraction2 = 1.0 - fraction;
239 scale = rps[iradius]*fraction2 + rps[iradius2]*fraction;
277 unsigned long maxrad = (
unsigned long) (2 + rad_scale/resolution);
280 cout <<
"Weighing amplitudes with a C cross-section:" << endl;
281 cout <<
"Resolution: " << resolution <<
" (" << maxrad <<
" pixels)" << endl << endl;
284 double* ccurve =
C_curve(maxrad, 1/rad_scale);
316 unsigned long maxrad = (
unsigned long) (2 + rad_scale/resolution);
317 if ( maxrad > plot->
rows() ) maxrad = plot->
rows();
320 cout <<
"Weighing amplitudes with an FSC curve:" << endl;
321 cout <<
"Resolution: " << resolution <<
" (" << maxrad <<
" pixels)" << endl << endl;
325 double* fsc =
new double[maxrad];
327 for ( i=0, j=plot->
rows(); i<maxrad; i++, j++ )
328 fsc[i] = sqrt((*plot)[j]);
359 cerr <<
"Error: File " << p->
file_name() <<
" must be a real space map!" << endl;
364 cerr <<
"Error: File " << pref->
file_name() <<
" must be a real space map!" << endl;
374 if ( !pc )
return -1;
378 unsigned long i, j, n, x, y, z, iradius, iradius2, use_this(1);
379 long xx, yy, zz, ix, iy, iz;
380 double radius, fraction, fraction2, amp1, amp2;
381 double rx, ry, rz, scale;
385 cout <<
"DEBUG img_weigh_amplitudes: pixelsize = " << p->
sampling() << endl;
397 unsigned long maxrad = (
unsigned long) (2 + rad_scale/resolution);
400 cout <<
"Weighing amplitudes:" << endl;
401 cout <<
"Reference map: " << pref->
file_name() << endl;
402 cout <<
"Resolution: " << resolution <<
" (" << maxrad <<
" pixels)" << endl << endl;
405 double* num =
new double[maxrad];
406 double* rps1 =
new double[maxrad];
407 double* rps2 =
new double[maxrad];
409 for ( n=0; n<pc->
images(); n++ ) {
410 for ( i=0; i< maxrad; i++ ) num[i] = rps1[i] = rps2[i] = 0;
411 for ( z=0; z<pc->
sizeZ(); z++ ) {
413 if ( z > (pc->
sizeZ() - 1)/2 ) zz -= pc->
sizeZ();
414 rz = zz*freq_scale.
z();
416 if ( iz < 0 ) iz += pc->
sizeZ();
417 for ( y=0; y<pc->
sizeY(); y++ ) {
419 if ( y > (pc->
sizeY() - 1)/2 ) yy -= pc->
sizeY();
420 ry = yy*freq_scale.
y();
422 if ( iy < 0 ) iy += pc->
sizeY();
423 for ( x=0; x<pc->
sizeX()/2; x++ ) {
427 if ( x > (pc->
sizeX() - 1)/2 ) xx -= pc->
sizeX();
428 rx = xx*freq_scale.
x();
430 if ( ix < 0 ) ix += pc->
sizeX();
433 radius = rad_scale*sqrt(rx*rx + ry*ry + rz*rz);
434 iradius = (int) radius;
435 iradius2 = iradius + 1;
437 if ( pmask && (*pmask)[i] < 1 ) use_this = 0;
438 if ( iradius2 >= maxrad ) use_this = 0;
440 fraction = radius - iradius;
441 fraction2 = 1.0 - fraction;
446 num[iradius] += fraction2;
447 num[iradius2] += fraction;
448 rps1[iradius] += fraction2*amp1;
449 rps1[iradius2] += fraction*amp1;
450 rps2[iradius] += fraction2*amp2;
451 rps2[iradius2] += fraction*amp2;
465 cout <<
"Scaling for image " << n <<
":\ns\tRPS1\tRPS2\tScale" << endl;
466 for ( i=0; i<maxrad; i++ ) {
467 if ( num[i] && rps1[i] ) scale = rps2[i] / rps1[i];
469 cout << i/rad_scale <<
tab << rps1[i] <<
tab << rps2[i] <<
tab << scale << endl;
474 for ( i=0; i<maxrad; i++ )
475 if ( num[i] && rps1[i] ) rps2[i] /= rps1[i];
477 for ( z=0; z<pc->
sizeZ(); z++ ) {
479 if ( z > (pc->
sizeZ() - 1)/2 ) zz -= pc->
sizeZ();
480 rz = zz*freq_scale.
z();
481 for ( y=0; y<pc->
sizeY(); y++ ) {
483 if ( y > (pc->
sizeY() - 1)/2 ) yy -= pc->
sizeY();
484 ry = yy*freq_scale.
y();
485 for ( x=0; x<pc->
sizeX(); x++ ) {
489 if ( pmask && (*pmask)[i] < 1 ) use_this = 0;
491 if ( x > (pc->
sizeX() - 1)/2 ) xx -= pc->
sizeX();
492 rx = xx*freq_scale.
x();
493 radius = rad_scale*sqrt(rx*rx + ry*ry + rz*rz);
494 iradius = (int) radius;
495 iradius2 = iradius + 1;
496 if ( iradius2 >= maxrad ) use_this = 0;
498 fraction = radius - iradius;
499 fraction2 = 1.0 - fraction;
500 scale = rps2[iradius]*fraction2 + rps2[iradius2]*fraction;
534 cerr <<
"Error: File " << p->
file_name() <<
" must be a real space map!" << endl;
544 unsigned long i, j, n, x, y, z, iradius, iradius2, use_this(1);
546 double radius, fraction, fraction2, pwr;
547 double rx, ry, rz, scale;
551 cout <<
"DEBUG img_normalize_amplitudes: pixelsize = " << p->
sampling() << endl;
563 unsigned long maxrad = (
unsigned long) (2 + rad_scale/resolution);
566 cout <<
"Normalizing amplitudes:" << endl;
567 cout <<
"Resolution: " << resolution <<
" (" << maxrad <<
" pixels)" << endl << endl;
570 double* num =
new double[maxrad];
571 double* rps =
new double[maxrad];
573 for ( n=0; n<p->
images(); n++ ) {
574 for ( i=0; i<maxrad; i++ ) num[i] = rps[i] = 0;
575 for ( z=0; z<p->
sizeZ(); z++ ) {
577 if ( z > (p->
sizeZ() - 1)/2 ) zz -= p->
sizeZ();
578 rz = zz*freq_scale.
z();
579 for ( y=0; y<p->
sizeY(); y++ ) {
581 if ( y > (p->
sizeY() - 1)/2 ) yy -= p->
sizeY();
582 ry = yy*freq_scale.
y();
583 for ( x=0; x<p->
sizeX(); x++ ) {
587 if ( x > (p->
sizeX() - 1)/2 ) xx -= p->
sizeX();
588 rx = xx*freq_scale.
x();
589 radius = rad_scale*sqrt(rx*rx + ry*ry + rz*rz);
590 iradius = (int) radius;
591 iradius2 = iradius + 1;
593 if ( pmask && (*pmask)[i] < 1 ) use_this = 0;
594 if ( iradius2 >= maxrad ) use_this = 0;
596 fraction = radius - iradius;
597 fraction2 = 1.0 - fraction;
599 num[iradius] += fraction2;
600 num[iradius2] += fraction;
601 rps[iradius] += fraction2*pwr;
602 rps[iradius2] += fraction*pwr;
609 cout <<
"Scaling for image " << n <<
":\ns\tRPS\tScale" << endl;
610 for ( i=0; i<maxrad; i++ ) {
611 if ( num[i] && rps[i] ) scale = sqrt(num[i] / rps[i]);
613 cout << i/rad_scale <<
tab << rps[i] <<
tab << scale << endl;
618 for ( i=0; i<maxrad; i++ )
619 if ( num[i] && rps[i] ) rps[i] = sqrt(num[i] / rps[i]);
621 for ( z=0; z<p->
sizeZ(); z++ ) {
623 if ( z > (p->
sizeZ() - 1)/2 ) zz -= p->
sizeZ();
624 rz = zz*freq_scale.
z();
625 for ( y=0; y<p->
sizeY(); y++ ) {
627 if ( y > (p->
sizeY() - 1)/2 ) yy -= p->
sizeY();
628 ry = yy*freq_scale.
y();
629 for ( x=0; x<p->
sizeX(); x++ ) {
633 if ( pmask && (*pmask)[i] < 1 ) use_this = 0;
635 if ( x > (p->
sizeX() - 1)/2 ) xx -= p->
sizeX();
636 rx = xx*freq_scale.
x();
637 radius = rad_scale*sqrt(rx*rx + ry*ry + rz*rz);
638 iradius = (int) radius;
639 iradius2 = iradius + 1;
640 if ( iradius2 >= maxrad ) use_this = 0;
642 fraction = radius - iradius;
643 fraction2 = 1.0 - fraction;
644 scale = rps[iradius]*fraction2 + rps[iradius2]*fraction;
void change_type(char letter)
Get the data type indicated by a single letter code.
int img_divide_by_fom(Bimage *p, double wiener)
Divides an image by its figure-of-merit.
int img_weigh_amplitudes_with_C_curve(Bimage *p, double resolution)
Weighs an image's amplitudes with the carbon scattering curve.
Header file for general utilities.
Class for complex numbers.
Generalized matrix class.
int img_weigh_amplitudes_with_curve(Bimage *p, int maxrad, double *curve)
Header file for image utilities.
void check_resolution(double &resolution)
Checks that the resolution falls within reasonable limits.
int img_sqrt_amp(Bimage *p)
Change the amlitudes to their square roots.
General image parameter class.
Vector3< double > real_size()
int img_multiply_by_fom(Bimage *p)
Weighs a set of reflections by its figure-of-merit.
Complex< double > complex(size_t j)
Returns a complex value at the given index.
General FFT for n-dimensional data.
double * C_curve(unsigned long n, double freq_step)
Calculates the carbon scattering curve.
Header file for CTF (contrast transfer function) functions.
void file_name(Bstring s)
void set(size_t j, double v)
Sets a single value at the given index.
int img_weigh_amplitudes(Bimage *p, Bimage *pref, Bimage *pmask, double resolution)
Weighs an image's amplitudes with the radial power spectrum of another.
int img_normalize_amplitudes(Bimage *p, Bimage *pmask, double resolution)
Normalizes an image's amplitudes.
Bimage * pack_two_in_complex(Bimage *p)
Packs two real images into one complex image.
int img_square_amp(Bimage *p)
Change the amlitudes to their squares.
FourierType fourier_type()
ostream & tab(ostream &out)
int img_weigh_amplitudes_with_FSC_curve(Bimage *p, Bplot *plot, double resolution)
Weighs an image's amplitudes with a given FSC curve.