Bsoft  2.1.0
Bernard's software package
Bimage_fspace.cpp
Go to the documentation of this file.
1 
9 #include "Bimage.h"
10 #include "ctf.h"
11 #include "matrix_linear.h"
12 #include "utilities.h"
13 
14 // Declaration of global variables
15 extern int verbose; // Level of output to the screen
16 
26 long Bimage::fspace_maximum_radius(double resolution, double sampling_ratio)
27 {
28  double rad_scale(real_size().max()/sampling_ratio);
29 
30  long maxrad(size().max());
31 
32  if ( resolution > 0.1 )
33  maxrad = (long) (rad_scale/resolution);
34  else
35  maxrad = (long) (maxrad/2.0);
36 
37  return maxrad;
38 }
39 
40 
47 {
48  long nn, xx, yy, zz, i, nb;
49  double bkg;
50  Vector3<long> bmin(0.4*x, 0.4*y, 0.4*z), bmax(0.6*x, 0.6*y, 0.6*z);
51  bmax = bmax.min(1);
52 
53  if ( verbose )
54  cout << "Calculating the Fourier transform background" << endl;
55 
56  for ( nn=0; nn<n; ++nn ) {
57  nb = 0;
58  bkg = 0;
59  for ( zz=bmin[2]; zz<bmax[2]; ++zz ) {
60  for ( yy=bmin[1]; yy<bmax[1]; ++yy ) {
61  for ( xx=bmin[0]; xx<bmax[0]; ++xx ) {
62  i = index(xx, yy, zz, nn);
63  bkg += complex(i).power();
64  nb++;
65  }
66  }
67  }
68  if ( nb ) bkg /= nb;
69  image[nn].background(bkg);
70  if ( verbose )
71  cout << nn << tab << scientific << bkg << endl;
72  }
73 
74  return 0;
75 }
76 
86 {
87  Complex<double> value(0,0);
88 
89  if ( compoundtype != TComplex ) return value;
90 
91  long xx, yy, zz, kx, ky, kz, mx, my, mz, jx, jy, jz;
92  long nx(kernel->width()), ny(kernel->width()), nz(kernel->width());
93  long ix = (long) floor(m[0]);
94  long iy = (long) floor(m[1]);
95  long iz = (long) floor(m[2]);
96  long ikx(kernel->half_width());
97  long iky(kernel->half_width());
98  long ikz(kernel->half_width());
99  double wyz;
100 
101  if ( x > 1 ) {
102  ikx = ((long) ((m[0] - ix)*kernel->divisions() + 0.5))*kernel->width();
103  ix -= kernel->half_width();
104  } else nx = 1;
105 
106  if ( y > 1 ) {
107  iky = ((long) ((m[1] - iy)*kernel->divisions() + 0.5))*kernel->width();
108  iy -= kernel->half_width();
109  } else ny = 1;
110 
111  if ( z > 1 ) {
112  ikz = ((long) ((m[2] - iz)*kernel->divisions() + 0.5))*kernel->width();
113  iz -= kernel->half_width();
114  } else nz = 1;
115 
116  for ( zz=0, kz=ikz, mz=iz; zz<nz; zz++, kz++, mz++ ) {
117  jz = mz;
118  while ( jz < 0 ) jz += z;
119  while ( jz >= z ) jz -= z;
120  jz = (img_num*z + jz)*y;
121  for ( yy=0, ky=iky, my=iy; yy<ny; yy++, ky++, my++ ) {
122  jy = my;
123  while ( jy < 0 ) jy += y;
124  while ( jy >= y ) jy -= y;
125  jy = (jz + jy)*x;
126  wyz = (*kernel)[ky]*(*kernel)[kz];
127  for ( xx=0, kx=ikx, mx=ix; xx<nx; xx++, kx++, mx++ ) {
128  jx = mx;
129  while ( jx < 0 ) jx += x;
130  while ( jx >= x ) jx -= x;
131  value += complex(jy + jx) * ((*kernel)[kx]*wyz);
132  }
133  }
134  }
135 
136  if ( !value.is_finite() )
137  cerr << "Warning: Interpolated complex value not finite! (" << value << ")" << endl;
138 
139  return value;
140 }
141 
148 {
149  if ( verbose & VERB_PROCESS ) {
150  cout << "Translating in frequency space:" << endl;
151  cout << "Shift: " << shift << endl;
152  }
153 
154  FourierType old_transform = fouriertype;
155 
156  if ( fouriertype == NoTransform )
157  fft();
158 
159  for ( long nn=0; nn<n; nn++ )
160  fspace_translate(nn, shift);
161 
162  if ( old_transform == NoTransform )
163  fft_back();
164 
165  return 0;
166 }
167 
168 
176 {
177  if ( verbose & VERB_PROCESS ) {
178  cout << "Translating in frequency space:" << endl;
179  cout << "Shift: " << shift << endl;
180  }
181 
182  FourierType old_transform = fouriertype;
183 
184  if ( fouriertype == NoTransform )
185  fft();
186 
187  phase_shift(nn, shift);
188 
189  if ( old_transform == NoTransform )
190  fft_back();
191 
192  return 0;
193 }
194 
202 int Bimage::fspace_resize(double scale, double res_hi, double res_lo)
203 {
204  Vector3<long> nusize = {x,y,z};
205  if ( x > 1 ) nusize[0] = (long) (x*scale);
206  if ( y > 1 ) nusize[1] = (long) (y*scale);
207  if ( z > 1 ) nusize[2] = (long) (z*scale);
208 
209  Vector3<long> translate = {0,0,0};
210  Vector3<long> olsize = {x,y,z};
211  if ( x > 1 ) olsize[0] = (long) (nusize[0]/scale);
212  if ( y > 1 ) olsize[1] = (long) (nusize[1]/scale);
213  if ( z > 1 ) olsize[2] = (long) (nusize[2]/scale);
214 
215  Vector3<double> error;
216  if ( x > 1 ) error[0] = olsize[0]*scale - nusize[0];
217  if ( y > 1 ) error[1] = olsize[1]*scale - nusize[1];
218  if ( z > 1 ) error[2] = olsize[2]*scale - nusize[2];
219 
220  if ( verbose ) {
221 // if ( verbose & VERB_PROCESS ) {
222  cout << "Rescaling in frequency space:" << endl;
223  cout << "Scale: " << scale << endl;
224  cout << "New size: " << nusize << " voxels" << endl;
225  cout << "Error: " << error << " voxels" << endl << endl;
226  }
227 
228  FourierType old_transform = fouriertype;
229 
230  if ( fouriertype == NoTransform ) {
232  resize(olsize, translate, FILL_BACKGROUND, 0);
233  fft();
234  }
235 
236  change_transform_size(nusize);
237 
238  if ( res_hi > 0 ) fspace_bandpass(res_hi, res_lo, 0);
239 
240  if ( old_transform == NoTransform )
241  fft_back();
242 
243  return 0;
244 }
245 
254 {
255  if ( image->origin().length() < 1 ) origin(size()/2);
256 
257  double r(pref->real_size()[0]/real_size()[0]);
258  long nx(x * r + 0.5);
259 // r = nx/(x * r);
260 
261  Vector3<long> nusize(nx, nx, nx);
262  Vector3<double> scale(1,1,1), origin(image->origin());
263 // Vector3<double> translate(nusize/2 - image->origin());
264 // Vector3<double> translate(image->origin() * (nx * r/x - 1));
265 // Vector3<double> translate((nusize - size())/2);
266  Vector3<double> translate(nusize/2 - size()/2);
267  Matrix3 mat(1);
268 
269  if ( verbose & VERB_RESULT ) {
270  cout << "Fitting " << file_name() << " to " << pref->file_name() << endl;
271  cout << "Intermediate size: " << nusize << endl;
272  cout << "Intermediate scale: " << scale << endl;
273  cout << "Intermediate translation: " << translate << endl << endl;
274  }
275 
276  if ( verbose & VERB_PROCESS ) {
277  cout << "Comparing map " << file_name() << endl;
278  cout << "Map size: " << size() << endl;
279  cout << "Map origin: " << image->origin() << endl;
280  cout << "Map sampling: " << sampling(0) << endl;
281  cout << "Map real size: " << real_size() << endl << endl;
282  cout << "Reference: " << pref->file_name() << endl;
283  cout << "Reference size: " << pref->size() << endl;
284  cout << "Reference origin: " << pref->image->origin() << endl;
285  cout << "Reference sampling: " << pref->sampling(0) << endl;
286  cout << "Reference real size: " << pref->real_size() << endl << endl;
287  }
288 
289  Bimage* pt = transform(nusize, scale, origin, translate, mat, FILL_BACKGROUND);
290 
291 // write_img("pt.pif", pt);
292 
293  if ( verbose & VERB_PROCESS ) {
294  cout << "Translate: " << translate << endl;
295  cout << "New map size: " << pt->size() << endl;
296  cout << "New map origin: " << pt->image->origin() << endl;
297  cout << "New map sampling: " << pt->sampling(0) << endl;
298  cout << "New map real size: " << pt->real_size() << endl << endl;
299  }
300 
301  pt->fft();
302 
303  pt->fspace_bandpass(2*pt->image->sampling()[0]); // Cut out the corners
304 
305  Vector3<long> sz = {pref->sizeX(), pref->sizeY(), pref->sizeZ()};
306  pt->change_transform_size(sz);
307 
308  pt->fft_back();
309 
310  return pt;
311 }
312 
324 {
325  if ( !d.uc ) {
326  cerr << "Error: No image data to process!" << endl << endl;
327  return -1;
328  }
329 
330  FourierType old_transform = fouriertype;
331 
332  if ( fouriertype == NoTransform )
333  fft();
334 
335  if ( verbose & VERB_PROCESS )
336  cout << "Setting all amplitudes to one" << endl << endl;
337 
338  long i, ds(x*y*z*n);
339  double amp;
340  Complex<double> cv;
341 
342  for ( i=0; i<ds; i++ ) {
343  cv = complex(i);
344  if ( ( amp = cv.amp() ) )
345  set(i, cv/amp);
346  }
347 
348  if ( old_transform == NoTransform )
349  fft_back();
350 
351  statistics();
352 
353  return 0;
354 }
355 
368 int Bimage::fspace_amp_threshold(double threshold)
369 {
370  if ( !d.uc ) {
371  cerr << "Error: No image data to process!" << endl << endl;
372  return -1;
373  }
374 
375  if ( threshold <= 0 ) return 0;
376 
377  FourierType old_transform = fouriertype;
378 
379  if ( fouriertype == NoTransform )
380  fft();
381 
382  if ( verbose & VERB_PROCESS )
383  cout << "Applying an amplitude filter with a threshold of " << threshold << endl;
384 
385  long i, ds(x*y*z*n);
386  long nk(0), nz(0);
387  double maxamp(0), zeroamp(1e-5*threshold);
388  double amp, ampkept(0), ampzeroed(0);
389  Complex<double> cv;
390 
391  for ( i=0; i<ds; i++ ) {
392  amp = complex(i).amp();
393  if ( maxamp < amp ) maxamp = amp;
394  if ( amp < threshold ) {
395  ampzeroed += amp;
396  if ( amp > zeroamp ) nz++;
397  set(i, cv);
398  } else {
399  ampkept += amp;
400  nk++;
401  }
402  }
403 
404  if ( verbose & VERB_PROCESS ) {
405  cout << "Number of amplitudes kept: " << nk << " (" << nk*100.0/ds << " %)" << endl;
406  cout << "Number of amplitudes zeroed: " << nz << " (" << nz*100.0/ds << " %)" << endl;
407  cout << "Maximum amplitude: " << maxamp << endl;
408  cout << "Amplitude kept sum: " << ampkept << endl;
409  cout << "Amplitude zeroed sum: " << ampzeroed << endl << endl;
410  }
411 
412  if ( old_transform == NoTransform )
413  fft_back();
414 
415  statistics();
416 
417  return 0;
418 }
419 
425 {
426  if ( fouriertype != NoTransform ) {
427  cerr << "Error: File " << file_name() << " must be a real space map!" << endl;
428  return -1;
429  }
430 
431  fft();
432 
433  if ( verbose & VERB_PROCESS )
434  cout << "Changing the amplitudes to their square roots" << endl << endl;
435 
436  long i, ds(x*y*z*n);
437  double d;
438  Complex<float> cv;
439 
440  for ( i=0; i<ds; i++ ) {
441  cv = complex(i);
442  d = sqrt(cv.amp());
443  set(i, cv/d);
444  }
445 
446  fft_back();
447 
448  return 0;
449 }
450 
456 {
457  if ( fouriertype != NoTransform ) {
458  cerr << "Error: File " << file_name() << " must be a real space map!" << endl;
459  return -1;
460  }
461 
462  fft();
463 
464  if ( verbose & VERB_PROCESS )
465  cout << "Changing the amplitudes to their squares" << endl << endl;
466 
467  long i, ds(x*y*z*n);
468  double d;
469  Complex<float> cv;
470 
471  for ( i=0; i<ds; i++ ) {
472  cv = complex(i);
473  d = cv.amp();
474  set(i, cv*d);
475  }
476 
477  fft_back();
478 
479  return 0;
480 }
481 
496 int Bimage::fspace_bandpass(double res_hi, double res_lo, double width)
497 {
498  fft_plan planf = fft_setup(FFTW_FORWARD, 0);
499  fft_plan planb = fft_setup(FFTW_BACKWARD, 0);
500 
501  fspace_bandpass(res_hi, res_lo, width, planf, planb);
502 
505 
506  return 0;
507 }
508 
525 int Bimage::fspace_bandpass(double res_hi, double res_lo, double width, fft_plan planf, fft_plan planb)
526 {
527  if ( !d.uc ) {
528  cerr << "Error: No image data to process!" << endl << endl;
529  return -1;
530  }
531 
532  if ( width < 1e-6 ) width = 1e-6;
533 
534  FourierType old_transform = fouriertype;
535 
536  if ( fouriertype == NoTransform )
537  fft(planf, 1);
538 
539  if ( res_lo > 0 && res_hi > res_lo ) swap(res_hi, res_lo);
540  if ( res_hi == res_lo ) res_lo = 0;
541 
542  if ( verbose & VERB_PROCESS ) {
543  cout << "Applying a bandpass filter:" << endl;
544  cout << "High and low resolution limits: " << res_hi << " - ";
545  if ( res_lo > 0 ) cout << res_lo << " A" << endl;
546  else cout << "inf A" << endl;
547  cout << "Gaussian edge: " << width << endl << endl;
548  }
549 
550  long i, nn, xx, yy, zz;
551  double edge_lo, edge_hi, f, test_width(10*width), a(GOLDEN/fabs(width));
552  double s, sx2, sy2, sz2;
553  double shi = 1/res_hi;
554  double slo = (res_lo > 0)? 1/res_lo : 0;
555  Vector3<long> h((size()-1)/2);
556  Vector3<double> iscale(1/real_size());
557 
558  for ( i=nn=0; nn<n; nn++ ) {
559  for ( zz=0; zz<z; zz++ ) {
560  sz2 = zz;
561  if ( zz > h[2] ) sz2 -= z;
562  sz2 *= iscale[2];
563  sz2 *= sz2;
564  for ( yy=0; yy<y; yy++ ) {
565  sy2 = yy;
566  if ( yy > h[1] ) sy2 -= y;
567  sy2 *= iscale[1];
568  sy2 *= sy2;
569  for ( xx=0; xx<x; xx++, i++ ) {
570  sx2 = xx;
571  if ( xx > h[0] ) sx2 -= x;
572  sx2 *= iscale[0];
573  sx2 *= sx2;
574  s = sqrt(sx2 + sy2 + sz2);
575  if ( slo - s > test_width ) edge_lo = 1e300;
576  else edge_lo = exp(a*(slo - s));
577  if ( s - shi > test_width ) edge_hi = 1e300;
578  else edge_hi = exp(a*(s - shi));
579  f = (edge_hi > edge_lo)? 1/(1 + edge_hi): 1/(1 + edge_lo);
580  set(i, complex(i) * f);
581  }
582  }
583  }
584  }
585 
586  if ( old_transform == NoTransform ) {
587  fft(planb, 1);
588  complex_to_real();
590  }
591 
592  statistics();
593 
594  return 0;
595 }
596 
610 Bimage* Bimage::fspace_radial_power(double resolution, double sampling_ratio)
611 {
612  if ( compoundtype != TComplex || fouriertype != Standard ) {
613  cerr << "Error: File " << file_name() << " must be a frequency space map!" << endl;
614  return NULL;
615  }
616 
617  check_resolution(resolution);
618 
619  long i, j, nn, xx, yy, zz, iradius;
620  double radius, f, f1, rx, ry, rz, v;
621  double rad_scale(real_size().max()/sampling_ratio);
622  Vector3<long> h((size()-1)/2);
623  Vector3<double> freq_scale(1/real_size());
624 // long maxrad = (long) (2 + rad_scale/resolution);
625  long maxrad = fspace_maximum_radius(resolution, sampling_ratio);
626 
627  Bimage* prad = new Bimage(Float, TSimple, maxrad, 1, 1, n);
628  prad->sampling(1.0/rad_scale, 1, 1);
629 
630  vector<float> radstd(n*maxrad);
631  vector<float> num(maxrad);
632 
633  if ( verbose & VERB_PROCESS ) {
634  cout << "Calculating a radial power spectrum:" << endl;
635  cout << "Radial scale: " << rad_scale << " A" << endl;
636  cout << "Radial step size: " << 1.0/rad_scale << " 1/A" << endl;
637  cout << "Resolution limit: " << resolution << " A" << endl;
638  cout << "Number of values: " << maxrad << endl << endl;
639  }
640 
641  for ( nn=0; nn<n; nn++ ) {
642  for ( i=0; i<maxrad; i++ ) num[i] = 0;
643  for ( zz=0; zz<z; zz++ ) {
644  rz = zz;
645  if ( zz > h[2] ) rz -= z;
646  rz *= freq_scale[2];
647  rz *= rz;
648  for ( yy=0; yy<y; yy++ ) {
649  ry = yy;
650  if ( yy > h[1] ) ry -= y;
651  ry *= freq_scale[1];
652  ry *= ry;
653  for ( xx=0; xx<x; xx++ ) {
654  rx = xx;
655  if ( xx > h[0] ) rx -= x;
656  rx *= freq_scale[0];
657  rx *= rx;
658  radius = rad_scale*sqrt(rx + ry + rz);
659  iradius = (long) radius;
660  if ( iradius < maxrad ) {
661  f = radius - iradius;
662  f1 = 1 - f;
663  i = index(xx, yy, zz, nn);
664  num[iradius] += f1;
665  j = nn*maxrad + iradius;
666  v = complex(i).power();
667  prad->add(j, f1*v);
668  radstd[j] += f1*v*v;
669  iradius++;
670  if ( iradius < maxrad ) {
671  j++;
672  num[iradius] += f;
673  prad->add(j, f*v);
674  radstd[j] += f*v*v;
675  }
676  }
677  }
678  }
679  }
680  for ( i=0; i<maxrad; i++ ) {
681  if ( num[i] ) {
682  j = nn*maxrad + i;
683  prad->set(j, (*prad)[j]/num[i]);
684  radstd[j] = radstd[j]/num[i] - (*prad)[j]*(*prad)[j];
685  if ( radstd[j] > 0 )
686  radstd[j] = sqrt(radstd[j]);
687  else
688  radstd[j] = 0;
689  }
690  }
691  prad->image[nn].origin(0.0,0.0,0.0);
692  }
693 
694  if ( verbose & VERB_DEBUG )
695  cout << "DEBUG Bimage::fspace_radial_power: Calculating statistics" << endl;
696 
697  prad->statistics();
698 
699  if ( verbose & VERB_FULL ) {
700  cout << endl << "Radial power spectrum:" << endl;
701  cout << "Radius";
702  for ( nn=0; nn<prad->images(); nn++ ) cout << " " << nn+1 << " (std)";
703  cout << endl;
704  for ( xx=0; xx<prad->sizeX(); xx++ ) {
705  cout << xx*prad->sampling(0)[0];
706  for ( nn=0, i=xx; nn<prad->images(); nn++, i+=prad->sizeX() )
707  cout << " " << (*prad)[i] << " " << radstd[i];
708  cout << endl;
709  }
710  }
711 
712  return prad;
713 }
714 
729 double* Bimage::fspace_radial(long nn, long maxrad, int flag)
730 {
731  if ( compoundtype != TComplex || fouriertype != Standard ) {
732  cerr << "Error: File " << file_name() << " must be a frequency space map!" << endl;
733  return NULL;
734  }
735 
736  bool amp(flag & 1), norm(1 - (flag & 2));
737  long i, xx, yy, zz, iradius, iradius2;
738  double radius, fraction, fraction2, v;
739  double rx, ry, rz;
740  Vector3<long> h((size()-1)/2);
741  double rad_scale(real_size().max());
742  Vector3<double> freq_scale(1.0/real_size());
743 
744  double* num = new double[maxrad];
745  double* rps = new double[maxrad];
746 
747  for ( i=0; i<maxrad; i++ ) num[i] = rps[i] = 0;
748 
749  for ( zz=0; zz<z; zz++ ) {
750  rz = zz;
751  if ( zz > h[2] ) rz -= z;
752  rz *= freq_scale[2];
753  rz *= rz;
754  for ( yy=0; yy<y; yy++ ) {
755  ry = yy;
756  if ( yy > h[1] ) ry -= y;
757  ry *= freq_scale[1];
758  ry *= ry;
759  for ( xx=0; xx<x/2; xx++ ) {
760  rx = xx;
761  if ( xx > h[0] ) rx -= x;
762  rx *= freq_scale[0];
763  rx *= rx;
764  i = index(xx, yy, zz, nn);
765  radius = rad_scale*sqrt(rx + ry + rz);
766  iradius = (long) radius;
767  iradius2 = iradius + 1;
768  if ( iradius2 < maxrad ) {
769  fraction = radius - iradius;
770  fraction2 = 1.0 - fraction;
771  if ( amp )
772  v = complex(i).amp();
773  else
774  v = complex(i).power();
775  num[iradius] += fraction2;
776  num[iradius2] += fraction;
777  rps[iradius] += fraction2*v;
778  rps[iradius2] += fraction*v;
779  }
780  }
781  }
782  }
783 
784  if ( norm ) {
785  rps[0] = 0;
786  for ( i=0; i<maxrad; i++ )
787  if ( num[i] ) rps[i] /= num[i];
788  }
789 
790  delete[] num;
791 
792  return rps;
793 }
794 
795 int Bimage::fspace_weigh(long maxrad, double* curve, int flag)
796 {
797  long i, nn;
798  double* rps;
799 
800  FourierType old_transform = fouriertype;
801 
802  if ( fouriertype == NoTransform )
803  fft();
804 
805  for ( nn=0; nn<n; nn++ ) {
806  rps = fspace_radial(nn, maxrad, flag);
807  for ( i=0; i<maxrad; i++ )
808  if ( rps[i] ) rps[i] = curve[i]/rps[i];
809  fspace_scale(nn, maxrad, rps);
810  }
811 
812  if ( old_transform == NoTransform )
813  fft_back();
814 
815  return 0;
816 }
817 
818 int Bimage::fspace_weigh(vector<double>& curve, int flag)
819 {
820  long maxrad(curve.size());
821  long i, nn;
822  double* rps;
823 
824  FourierType old_transform = fouriertype;
825 
826  if ( fouriertype == NoTransform )
827  fft();
828 
829  for ( nn=0; nn<n; nn++ ) {
830  rps = fspace_radial(nn, maxrad, flag);
831  for ( i=0; i<maxrad; i++ )
832  if ( rps[i] ) rps[i] = curve[i]/rps[i];
833  fspace_scale(nn, maxrad, rps);
834  }
835 
836  if ( old_transform == NoTransform )
837  fft_back();
838 
839  return 0;
840 }
841 
842 int Bimage::fspace_scale(long maxrad, double* scale, Bimage* pmask)
843 {
844  long nn;
845 
846  FourierType old_transform = fouriertype;
847 
848  if ( fouriertype == NoTransform )
849  fft();
850 
851  for ( nn=0; nn<n; nn++ )
852  fspace_scale(nn, maxrad, scale, pmask);
853 
854  if ( old_transform == NoTransform )
855  fft_back();
856 
857  return 0;
858 }
859 
860 int Bimage::fspace_scale(long nn, long maxrad, double* scale, Bimage* pmask)
861 {
862  int use_this;
863  long i, j, xx, yy, zz, iradius, iradius2;
864  double rx, ry, rz;
865  Vector3<long> h((size()-1)/2);
866  double radius, fraction, fraction2, w;
867  Complex<double> cv;
868 
869  double rad_scale = real_size().max();
870  Vector3<double> freq_scale = 1.0/real_size();
871 
872  for ( j=zz=0; zz<z; zz++ ) {
873  rz = zz;
874  if ( zz > h[2] ) rz -= z;
875  rz *= freq_scale[2];
876  rz *= rz;
877  for ( yy=0; yy<y; yy++ ) {
878  ry = yy;
879  if ( yy > h[1] ) ry -= y;
880  ry *= freq_scale[1];
881  ry *= ry;
882  for ( xx=0; xx<x; xx++, j++ ) {
883  rx = xx;
884  if ( xx > h[0] ) rx -= x;
885  rx *= freq_scale[0];
886  rx *= rx;
887  i = index(xx, yy, zz, nn);
888  radius = rad_scale*sqrt(rx + ry + rz);
889  iradius = (long) radius;
890  iradius2 = iradius + 1;
891  use_this = 1;
892  if ( pmask && (*pmask)[j] < 1 ) use_this = 0;
893  if ( iradius2 >= maxrad ) use_this = 0;
894  if ( use_this ) {
895  fraction = radius - iradius;
896  fraction2 = 1.0 - fraction;
897  w = scale[iradius]*fraction2 + scale[iradius2]*fraction;
898  set(i, complex(i) * w);
899  } else {
900  set(i, cv);
901  }
902  }
903  }
904  }
905 
906  return 0;
907 }
908 
909 int Bimage::fspace_scale(vector<double>& scale, Bimage* pmask)
910 {
911  long nn;
912 
913  FourierType old_transform = fouriertype;
914 
915  if ( fouriertype == NoTransform )
916  fft();
917 
918  for ( nn=0; nn<n; nn++ )
919  fspace_scale(nn, scale, pmask);
920 
921  if ( old_transform == NoTransform )
922  fft_back();
923 
924  return 0;
925 }
926 
927 int Bimage::fspace_scale(long nn, vector<double>& scale, Bimage* pmask)
928 {
929  long maxrad(scale.size());
930  int use_this;
931  long i, j, xx, yy, zz, iradius, iradius2;
932  double rx, ry, rz;
933  Vector3<long> h((size()-1)/2);
934  double radius, fraction, fraction2, w;
935  Complex<double> cv;
936 
937  double rad_scale = real_size().max();
938  Vector3<double> freq_scale = 1.0/real_size();
939 
940  for ( j=zz=0; zz<z; zz++ ) {
941  rz = zz;
942  if ( zz > h[2] ) rz -= z;
943  rz *= freq_scale[2];
944  rz *= rz;
945  for ( yy=0; yy<y; yy++ ) {
946  ry = yy;
947  if ( yy > h[1] ) ry -= y;
948  ry *= freq_scale[1];
949  ry *= ry;
950  for ( xx=0; xx<x; xx++, j++ ) {
951  rx = xx;
952  if ( xx > h[0] ) rx -= x;
953  rx *= freq_scale[0];
954  rx *= rx;
955  i = index(xx, yy, zz, nn);
956  radius = rad_scale*sqrt(rx + ry + rz);
957  iradius = (long) radius;
958  iradius2 = iradius + 1;
959  use_this = 1;
960  if ( pmask && (*pmask)[j] < 1 ) use_this = 0;
961  if ( iradius2 >= maxrad ) use_this = 0;
962  if ( use_this ) {
963  fraction = radius - iradius;
964  fraction2 = 1.0 - fraction;
965  w = scale[iradius]*fraction2 + scale[iradius2]*fraction;
966  set(i, complex(i) * w);
967  } else {
968  set(i, cv);
969  }
970  }
971  }
972  }
973 
974  return 0;
975 }
976 
994 double Bimage::fspace_fit_B_factor(double res_hi)
995 {
996  if ( !d.uc ) {
997  cerr << "Error: Cannot estimate the B-factor - the data block is empty!" << endl << endl;
998  return -1;
999  }
1000 
1001  check_resolution(res_hi);
1002 
1003  if ( verbose & VERB_PROCESS ) {
1004  cout << "B-factor estimation:" << endl;
1005  cout << "High resolution limit: " << res_hi << endl;
1006  }
1007 
1008  if ( compoundtype != TComplex ) fft();
1009 
1010  Bimage* prps = fspace_radial_power(res_hi);
1011 
1012  long i;
1013  double realsize(real_size()[0]);
1014  double frac_res2(1.0/(realsize));
1015  frac_res2 *= frac_res2;
1016  double res_lo(200);
1017  long minrad((long) (realsize/res_lo));
1018  long maxrad((long) (realsize/res_hi));
1019  double scat, logScale, Bfactor(-1);
1020 
1021  if ( verbose & VERB_DEBUG )
1022  cout << "DEBUG Bimage::fspace_fit_B_factor: minrad=" << minrad << " maxrad=" << maxrad << endl;
1023 
1024  double* s2 = new double[maxrad];
1025  double* logF = new double[maxrad];
1026 
1027  for ( i=0; i<maxrad; i++ ) {
1028  s2[i] = i*i*frac_res2;
1029  scat = 1.494*exp(-23.22*s2[i]) + 0.937*exp(-3.79*s2[i]);
1030  logF[i] = 4*(log(scat) - log((*prps)[i]));
1031  if ( verbose & VERB_FULL )
1032  cout << i << tab << sqrt(s2[i]) << tab << 1/sqrt(s2[i]) << tab << (*prps)[i] << tab << scat << endl;
1033  }
1034 
1035  double CI = linear_least_squares(minrad, maxrad, s2, logF, logScale, Bfactor);
1036 
1037  if ( verbose & VERB_PROCESS ) {
1038  cout << "B-factor: " << Bfactor << endl;
1039  cout << "Correlation index: " << CI << endl << endl;
1040  } else if ( verbose & VERB_LABEL ) {
1041  cout << "B-factor: " << Bfactor << endl << endl;
1042  }
1043 
1044  delete[] s2;
1045  delete[] logF;
1046  delete prps;
1047 
1048  return Bfactor;
1049 }
1050 
1063 {
1064  check_resolution(resolution);
1065 
1066  fft(planf, 1);
1067 
1068  long i, xx, yy, zz, nzero(0), nuse(0);
1069  Vector3<long> h(size()/2);
1070  Vector3<long> k;
1071  Vector3<double> s;
1072  double s2max(1.0/(resolution*resolution)), weight(0), s2;
1073  Vector3<double> realsize(real_size());
1074 
1075  if ( verbose & VERB_PROCESS )
1076  cout << "Filtering with a ramp to a resolution of " << resolution << " A" << endl;
1077 
1078  for ( i=zz=0; zz<z; zz++ ) {
1079  k[2] = (zz>h[2])? z - zz: zz;
1080  s[2] = k[2]/realsize[2];
1081  for ( yy=0; yy<y; yy++ ) {
1082  k[1] = (yy>h[1])? y - yy: yy;
1083  s[1] = k[1]/realsize[1];
1084  for ( xx=0; xx<x; xx++, i++ ) {
1085  k[0] = (xx>h[1])? x - xx: xx;
1086  s[0] = k[0]/realsize[0];
1087  s2 = s.length2();
1088  if ( s2 > s2max ) {
1089  weight = 0;
1090  nzero++;
1091  } else {
1092  weight = sqrt(s2);
1093  nuse++;
1094  }
1095  set(i, complex(i) * weight);
1096  }
1097  }
1098  }
1099 
1100  if ( verbose & VERB_FULL )
1101  cout << "Weighed fractions: zeroed=" << nzero*1.0/i << " used=" << nuse*1.0/i << endl << endl;
1102 
1103  fft(planb, 1);
1104 
1105  complex_to_real();
1106 
1107  statistics();
1108 
1109  return 0;
1110 }
1111 
1124 int Bimage::fspace_weigh_ramp(double resolution, double axis, fft_plan planf, fft_plan planb)
1125 {
1126  check_resolution(resolution);
1127 
1128  fft(planf, 1);
1129 
1130  long i, xx, yy, zz, nzero(0), nuse(0);
1131  Vector3<long> h(size()/2);
1132  Vector3<long> k;
1133  Vector3<double> s, a(cos(axis), sin(axis), 0);
1134  double s2max(1.0/(resolution*resolution)), weight(0), s2;
1135  Vector3<double> realsize(real_size());
1136 
1137  if ( verbose & VERB_PROCESS )
1138  cout << "Filtering with a ramp to a resolution of " << resolution << " A" << endl;
1139 
1140  for ( i=zz=0; zz<z; zz++ ) {
1141  k[2] = (zz>h[2])? z - zz: zz;
1142  for ( yy=0; yy<y; yy++ ) {
1143  k[1] = (yy>h[1])? y - yy: yy;
1144  s[1] = k[1]/realsize[1];
1145  for ( xx=0; xx<x; xx++, i++ ) {
1146  k[0] = (xx>h[1])? x - xx: xx;
1147  s[0] = k[0]/realsize[0];
1148  s2 = s.length2();
1149  if ( s2 > s2max ) {
1150  weight = 0;
1151  nzero++;
1152  } else {
1153  weight = sqrt(s2)*sin(axis-atan2(s[1],s[0]));
1154  nuse++;
1155  }
1156  set(i, complex(i) * weight);
1157  }
1158  }
1159  }
1160 
1161  if ( verbose & VERB_FULL )
1162  cout << "Weighed fractions: zeroed=" << nzero*1.0/i << " used=" << nuse*1.0/i << endl << endl;
1163 
1164  fft(planb, 1);
1165 
1166  complex_to_real();
1167 
1168  statistics();
1169 
1170  return 0;
1171 }
1172 
1183 int Bimage::fspace_weigh_B_factor(double B, double resolution)
1184 {
1185  check_resolution(resolution);
1186 
1187  // The radius scaling is set to a value consistent with one pixel width
1188  // in reciprocal space for the longest dimension.
1189  double rad_scale = real_size().max();
1190 
1191  // maxrad is the main limit for the length of all the arrays,
1192  // and is derived from the resolution set in the transform
1193  long maxrad = (long) (2 + rad_scale/resolution);
1194 
1195  if ( verbose ) {
1196  cout << "Weighing amplitudes with a B factor:" << endl;
1197  cout << "B factor: " << B << endl;
1198  cout << "Resolution: " << resolution << " A (" << maxrad << " pixels)" << endl << endl;
1199  }
1200 
1201  long i;
1202  vector<double> gcurve(maxrad);
1203  double s2, fac(-B/4);
1204 
1205  for ( i=0; i<maxrad; i++ ) {
1206  s2 = i/rad_scale;
1207  s2 *= s2;
1208  gcurve[i] = exp(fac*s2);
1209  }
1210 
1211  fspace_scale(gcurve);
1212 
1213  return 0;
1214 }
1215 
1226 int Bimage::fspace_weigh_C_curve(double resolution)
1227 {
1228  check_resolution(resolution);
1229 
1230  // The radius scaling is set to a value consistent with one pixel width
1231  // in reciprocal space for the longest dimension.
1232  double rad_scale = real_size().max();
1233 
1234  // maxrad is the main limit for the length of all the arrays,
1235  // and is derived from the resolution set in the transform
1236  long maxrad = (long) (2 + rad_scale/resolution);
1237 
1238  if ( verbose ) {
1239  cout << "Weighing amplitudes with a C cross-section:" << endl;
1240  cout << "Resolution: " << resolution << " A (" << maxrad << " pixels)" << endl << endl;
1241  }
1242 
1243  vector<double> ccurve = C_curve(maxrad, 1/rad_scale);
1244 
1245  fspace_weigh(ccurve, 1);
1246 
1247  return 0;
1248 }
1249 
1261 int Bimage::fspace_weigh_LoG(double resolution, double sigma)
1262 {
1263  check_resolution(resolution);
1264 
1265  // The radius scaling is set to a value consistent with one pixel width
1266  // in reciprocal space for the longest dimension.
1267  double rad_scale = real_size().max();
1268 
1269  // maxrad is the main limit for the length of all the arrays,
1270  // and is derived from the resolution set in the transform
1271  long maxrad = (long) (2 + rad_scale/resolution);
1272 
1273  if ( verbose ) {
1274  cout << "Weighing amplitudes with a Laplacian-of-Gaussian function:" << endl;
1275  cout << "Sigma: " << sigma << endl;
1276  cout << "Resolution: " << resolution << " A (" << maxrad << " pixels)" << endl << endl;
1277  }
1278 
1279  long i;
1280  double s2, freq_step(1/rad_scale), c1(-TWOPI*TWOPI), c2(-2*M_PI*M_PI*sigma*sigma);
1281  double* curve = new double[maxrad];
1282 
1283  for ( i=0; i<maxrad; i++ ) {
1284  s2 = i*freq_step;
1285  s2 *= s2;
1286  curve[i] = c1*s2*exp(c2*s2);
1287  }
1288 
1289  fspace_weigh(maxrad, curve, 1);
1290 
1291  delete[] curve;
1292 
1293  return 0;
1294 }
1295 
1308 int Bimage::fspace_weigh_RPS_curve(Bplot* plot, double resolution)
1309 {
1310  check_resolution(resolution);
1311 
1312  // The radius scaling is set to a value consistent with one pixel width
1313  // in reciprocal space for the longest dimension.
1314  double rad_scale = real_size().max();
1315  double scale = 1/((*plot)[1] * rad_scale);
1316 
1317  // maxrad is the main limit for the length of all the arrays,
1318  // and is derived from the resolution set in the transform
1319  long maxrad = (long) (2 + rad_scale/resolution);
1320 
1321  if ( verbose ) {
1322  cout << "Weighing amplitudes with an RPS curve:" << endl;
1323  cout << "Resolution: " << resolution << " A (" << maxrad << " pixels)" << endl << endl;
1324  }
1325 
1326  if ( verbose & VERB_DEBUG ) {
1327  cout << "rad_scale=" << rad_scale << endl;
1328  cout << "(*plot)[1]=" << (*plot)[1] << endl;
1329  cout << "scale=" << scale << endl;
1330  }
1331 
1332  long i, j;
1333  double s;
1334  vector<double> rps(maxrad);
1335 
1336  for ( i=plot->rows(); i<2*plot->rows(); ++i ) (*plot)[i] = sqrt((*plot)[i]);
1337 
1338  for ( i=0; i<maxrad; ++i ) {
1339  s = scale*i;
1340  j = long(s);
1341  s -= j;
1342  j += plot->rows();
1343  rps[i] = (1-s)*(*plot)[j] + s*(*plot)[j+1];
1344  if ( verbose & VERB_DEBUG )
1345  cout << i << tab << j-plot->rows() << tab << i/rad_scale << tab << (j-plot->rows())*(*plot)[1] << tab << rps[i] << endl;
1346  }
1347 
1348  fspace_weigh(rps, 1);
1349 
1350  return 0;
1351 }
1352 
1365 int Bimage::fspace_weigh_FSC_curve(Bplot* plot, double resolution)
1366 {
1367  check_resolution(resolution);
1368 
1369  // The radius scaling is set to a value consistent with one pixel width
1370  // in reciprocal space for the longest dimension.
1371  double rad_scale = real_size().max();
1372 
1373  // maxrad is the main limit for the length of all the arrays,
1374  // and is derived from the resolution set in the transform
1375  long maxrad = (long) (2 + rad_scale/resolution);
1376  if ( maxrad > plot->rows() ) maxrad = plot->rows();
1377 
1378  if ( verbose ) {
1379  cout << "Weighing amplitudes with an FSC curve:" << endl;
1380  cout << "Resolution: " << resolution << " A (" << maxrad << " pixels)" << endl << endl;
1381  }
1382 
1383  long i, j;
1384  double* fsc = new double[maxrad];
1385 
1386  for ( i=0, j=plot->rows(); i<maxrad; i++, j++ )
1387  fsc[i] = sqrt((*plot)[j]);
1388 
1389  fspace_weigh(maxrad, fsc, 1);
1390 
1391  delete[] fsc;
1392 
1393  return 0;
1394 }
1395 
1396 vector<double> critical_exposure_curve(long size, double real_size, int flag)
1397 {
1398  long i;
1399  double s, ds(1/real_size);
1400 // double a(0.245), b(-1.665), c(2.81); // Grant
1401  double a(0.1), b(-2), c(3); // Simplified
1402  double deb(6), des(150), ec(30); // Exponential decay
1403 
1404  if ( verbose & VERB_PROCESS ) {
1405  if ( flag )
1406  cout << "Critical exposure: "
1407  << deb << " + " << des << "exp(-" << ec << "s)"
1408  << " e/A2" << endl << endl;
1409  else
1410  cout << "Critical exposure: "
1411  << a << "s^" << b << " + " << c
1412  << " e/A2" << endl << endl;
1413  }
1414 
1415  vector<double> critexp(size, 0);
1416 
1417  for ( i=0, s=0; i<size; ++i, s+=ds ) {
1418  if ( flag )
1419  critexp[i] = 2*(deb + des*exp(-ec*s)); // Exponential decay
1420  else
1421  critexp[i] = 2*(a*pow(s, b) + c); // Grant
1422  if ( !isfinite(critexp[i]) ) critexp[i] = 1e10;
1423  }
1424 
1425  return critexp;
1426 }
1427 
1428 vector<double> radiation_damage_curve(vector<double> dose, long size, double real_size)
1429 {
1430  vector<double> rdcurve(size, 0);
1431 
1432  if ( dose.size() < 1 ) return rdcurve;
1433 // if ( dose.size() < 2 ) dose.push_back(3);
1434  if ( dose.size() < 2 ) {
1435  dose.push_back(6);
1436  dose.push_back(150);
1437  dose.push_back(30);
1438  } else if ( dose.size() < 3 ) dose.push_back(0.1);
1439 
1440  double s, is2, v, de(3), D(real_size);
1441 
1442  rdcurve[0] = 1;
1443  for ( long i=0; i<rdcurve.size(); ++i ) {
1444  s = i/D;
1445  if ( dose.size() == 3 ) {
1446  if ( i ) is2 = 1/s; // Inverse frequency
1447  else is2 = 1;
1448  is2 *= is2;
1449  de = 2*(dose[1] + dose[2]*is2); // Critical dose at frequency s (Grant)
1450  } else if ( dose.size() == 4 ) {
1451  de = 2*(dose[1] + dose[2]*exp(-dose[3]*s)); // Critical dose at frequency s
1452  }
1453  v = de*(1 - exp(-dose[0]/de));
1454  rdcurve[i] = v*v/dose[0];
1455  }
1456 
1457  return rdcurve;
1458 }
1459 
1460 int Bimage::fspace_weigh_dose(long nn, double dose_per_frame, vector<double> critdose)
1461 {
1462  long maxrad(critdose.size());
1463  long i;
1464  double dose(0);
1465 
1466  // Accumulated dose in e/Ã…2
1467  if ( dose_per_frame > 1e-3 )
1468  for ( i=0; i<=nn; ++i ) dose += dose_per_frame;
1469  else
1470  for ( i=0; i<=nn; ++i ) dose += image[i].average()/image[i].sampling().volume();
1471 
1472  if ( dose < 1e-3 ) {
1473  cerr << "Error: The dose is too low! (" << dose << ")" << endl;
1474  return -1;
1475  }
1476 
1477  vector<double> scale(maxrad);
1478 
1479  for ( i=0; i<maxrad; ++i )
1480  scale[i] = exp(-dose/critdose[i]);
1481 
1482  fspace_scale(nn, scale);
1483 
1484  return 0;
1485 }
1486 
1497 int Bimage::fspace_weigh_dose(double dose_per_frame, int flag)
1498 {
1499  long maxrad = (long) (size().length()/2+2);
1500 
1501 // long i;
1502 // double s, ds(1.0/(real_size()[0]));
1503 // double a(0.245), b(-1.665), c(2.81); // Grant
1504 // double a(0.1), b(-2), c(3); // Simplified
1505 // double deb(6), des(150), ec(30); // Exponential decay
1506 
1507  if ( verbose ) {
1508  cout << "Weighing amplitudes with the accumulated dose:" << endl;
1509  cout << "Dose per frame: " << dose_per_frame << " e/Ã…2" << endl;
1510 // cout << "Critical dose: " << a << "*s^" << b << " + " << c << " e/A2" << endl << endl;
1511  }
1512 /*
1513  vector<double> critdose(maxrad);
1514 
1515  for ( i=0, s=0; i<maxrad; ++i, s+=ds ) {
1516  if ( flag )
1517  critdose[i] = 2*(deb + des*exp(-ec*s)); // Exponential decay
1518  else
1519  critdose[i] = 2*(a*pow(s, b) + c); // Grant
1520  if ( !isfinite(critdose[i]) ) critdose[i] = 1e10;
1521  }
1522 */
1523  vector<double> critexp = critical_exposure_curve(maxrad, real_size().max(), flag);
1524 
1525 // for ( i=0, s=0; i<maxrad; ++i, s+=ds )
1526 // cout << s << tab << critdose[i] << endl;
1527 
1528  FourierType old_transform = fouriertype;
1529 
1530  if ( fouriertype == NoTransform )
1531  fft();
1532 
1533 #ifdef HAVE_GCD
1534  dispatch_apply(n, dispatch_get_global_queue(0, 0), ^(size_t nn){
1535  fspace_weigh_dose(nn, dose_per_frame, critexp);
1536  });
1537 #else
1538 #pragma omp parallel for
1539  for ( long nn=0; nn<n; ++nn )
1540  fspace_weigh_dose(nn, dose_per_frame, critexp);
1541 #endif
1542 
1543  if ( old_transform == NoTransform )
1544  fft_back();
1545 
1546  statistics();
1547 
1548  return 0;
1549 }
1550 
1562 {
1563  if ( dose.size() < 1 ) return 0;
1564 
1565  vector<double> rdcurve = radiation_damage_curve(dose, size().max(), real_size().max());
1566 
1567  fspace_weigh(rdcurve);
1568 
1569  return 0;
1570 }
1571 
1585 int Bimage::fspace_weigh(Bimage* pref, Bimage* pmask, double resolution)
1586 {
1587  if ( pmask ) pmask->change_type(UCharacter);
1588 
1589  check_resolution(resolution);
1590 
1591  // The radius scaling is set to a value consistent with one pixel width
1592  // in reciprocal space for the longest dimension.
1593  double rad_scale = real_size().max();
1594 
1595  // maxrad is the main limit for the length of all the arrays,
1596  // and is derived from the resolution set in the transform
1597  long maxrad = (long) (2 + rad_scale/resolution);
1598 
1599  if ( verbose ) {
1600  cout << "Weighing amplitudes:" << endl;
1601  cout << "Reference map: " << pref->file_name() << endl;
1602  cout << "Resolution: " << resolution << " A (" << maxrad << " pixels)" << endl << endl;
1603  }
1604 
1605  long i, nn;
1606  double* rps;
1607 
1608  if ( pref->compound_type() == TSimple && pref->fourier_type() == NoTransform )
1609  pref->fft();
1610 
1611  double* ref = pref->fspace_radial(0, maxrad, 1);
1612 
1613  if ( compoundtype == TSimple && fouriertype == NoTransform )
1614  fft();
1615 
1616  for ( nn=0; nn<n; nn++ ) {
1617  rps = fspace_radial(nn, maxrad, 1);
1618  for ( i=0; i<maxrad; i++ )
1619  if ( rps[i] ) rps[i] = ref[i]/rps[i];
1620  fspace_scale(nn, maxrad, rps, pmask);
1621  }
1622 
1623  fft_back();
1624 
1625  return 0;
1626 }
1627 
1628 
1635 {
1636  if ( fouriertype != Standard ) {
1637  cerr << "Error: File " << file_name() << " must be a Fourier transform!" << endl;
1638  return -1;
1639  }
1640 
1641  complex_power();
1642 
1643  long nn, i, j, ds(x*y*z);
1644  double scale;
1645 
1646  for ( nn=i=0; nn<n; ++nn ) {
1647  scale = 1/sqrt(image[nn].FOM());
1648  for ( j=0; j<ds; i++, j++ ) set(i, complex(i)*scale);
1649  }
1650 
1651  return 0;
1652 }
1653 
1662 int Bimage::fspace_normalize_radial(Bimage* pmask, double resolution, int flag)
1663 {
1664  if ( fouriertype != NoTransform ) {
1665  cerr << "Error: File " << file_name() << " must be a real space map!" << endl;
1666  return -1;
1667  }
1668 
1669  if ( pmask ) pmask->change_type(UCharacter);
1670 
1671  check_resolution(resolution);
1672 
1673  // The radius scaling is set to a value consistent with one pixel width
1674  // in reciprocal space for the longest dimension.
1675  double rad_scale = real_size().max();
1676 
1677  // maxrad is the main limit for the length of all the arrays,
1678  // and is derived from the resolution set in the transform
1679  long maxrad = (long) (2 + rad_scale/resolution);
1680 
1681  fft();
1682 
1683  long i, nn;
1684  double* rps;
1685 
1686  for ( nn=0; nn<n; nn++ ) {
1687  rps = fspace_radial(nn, maxrad, flag);
1688  for ( i=0; i<maxrad; i++ )
1689  if ( rps[i] ) rps[i] = 1/sqrt(rps[i]);
1690  fspace_scale(nn, maxrad, rps, pmask);
1691  }
1692 
1693  fft_back();
1694 
1695  return 0;
1696 }
1697 
1704 {
1705  int tflag(0);
1706  long i(0), ds(x*y*z);
1707  double fmax(0), scale;
1708 
1709  fmax = ds * (avg-min);
1710 
1711  if ( compoundtype != TComplex ) {
1712  tflag = 1;
1713  fft();
1714  }
1715 
1716  if ( (*this)[i] > SMALLFLOAT ) fmax = (*this)[i];
1717  if ( verbose ) {
1718  cout << "Converting to a positive definite image:" << endl;
1719  cout << "F0: " << fmax << endl << endl;
1720  }
1721 
1722  scale = 1/fmax;
1723 
1724  set(0, fmax);
1725  set(1, 0);
1726 
1727  for ( i=0; i<ds; i++ ) set(i, complex(i) * scale);
1728 
1729  if ( tflag ) fft_back();
1730 
1731  return 0;
1732 }
1733 
1745 {
1747 
1748  long i, j, nn, xx, yy, zz, xf, yf, zf;
1749  double d, w, s(0), R(0), Ri(0), Rr(0), Ra(0), Rp(0);
1750  Complex<double> v, vf;
1751 
1752  for ( nn=0; nn<n; nn++ ) {
1753  for ( zz=0; zz<z; zz++ ) {
1754  zf = (zz)? z - zz: 0;
1755  for ( yy=0; yy<y; yy++ ) {
1756  yf = (yy)? y - yy: 0;
1757  for ( xx=0; xx<(x+1)/2; xx++ ) {
1758  xf = (xx)? x - xx: 0;
1759  i = index(xx, yy, zz, nn);
1760  j = index(xf, yf, zf, nn);
1761  v = complex(i);
1762  vf = complex(j);
1763  w = (v.power() + vf.power())/2;
1764  d = v.real() - vf.real();
1765  Rr += d*d*w;
1766  d = v.imag() + vf.imag();
1767  Ri += d*d*w;
1768  d = v.amp() - vf.amp();
1769  Ra += d*d*w;
1770  d = angle_set_negPI_to_PI(v.phi() + vf.phi());
1771  Rp += d*d*w;
1772  s += w;
1773  }
1774  }
1775  }
1776  }
1777 
1778  Rr = sqrt(Rr/s);
1779  Ri = sqrt(Ri/s);
1780  Ra = sqrt(Ra/s);
1781  Rp = sqrt(Rp/s);
1782  R = sqrt(Rr*Rr + Ri*Ri);
1783 
1784  if ( verbose & VERB_PROCESS ) {
1785  cout << "Friedel symmetry residuals:" << endl;
1786  cout << "Real: " << Rr << endl;
1787  cout << "Imaginary: " << Ri << endl;
1788  cout << "Amplitude: " << Ra << endl;
1789  cout << "Phase: " << Rp*180.0/M_PI << " degrees" << endl;
1790  cout << "Overall: " << R << endl << endl;
1791  }
1792 
1793  return R;
1794 }
1795 
1807 {
1808  long i, j, nn, xx, yy, zz, xf, yf, zf, nR;
1809  double amp, amps, phi, phis, damp, dphi;
1810  double ampavg, phiavg, fomavg;
1811  double Ramp, Rphi;
1812  double tol(0.01);
1813  Complex<double> v, vf;
1814  float* fom = NULL;
1815  if ( next ) fom = (float *) next->data_pointer();
1816 
1817  if ( verbose & VERB_PROCESS ) {
1818  cout << "Applying Friedel symmetry:" << endl;
1819  cout << "Image\tRefl\tR(amp)\tR(phi)" << endl;
1820  } else if ( verbose & VERB_LABEL )
1821  cout << "Applying Friedel symmetry" << endl << endl;
1822 
1823  for ( nn=0; nn<n; nn++ ) {
1824  nR = 0;
1825  Ramp = Rphi = 0;
1826  for ( zz=0; zz<z; zz++ ) {
1827  zf = (zz)? z - zz: 0;
1828  for ( yy=0; yy<y; yy++ ) {
1829  yf = (yy)? y - yy: 0;
1830  for ( xx=0; xx<(x+1)/2; xx++ ) {
1831  xf = (xx)? x - xx: 0;
1832  i = index(xx, yy, zz, nn);
1833  j = index(xf, yf, zf, nn);
1834  v = complex(i);
1835  vf = complex(j);
1836  amp = v.amp();
1837  amps = vf.amp();
1838  phi = v.phi();
1839  phis = vf.phi();
1840  damp = amp - amps;
1841  dphi = phi + phis;
1842  dphi = angle_set_negPI_to_PI(dphi);
1843  if ( verbose & VERB_DEBUG )
1844  if ( fabs(dphi) > tol )
1845  cout << "amp dphi: " << xx << " " << yy << " "
1846  << zz << " " << j << " " << damp << " " << dphi << endl;
1847  ampavg = (amp + amps)/2;
1848  phiavg = phi - dphi/2;
1849  v = Complex<double>(ampavg*cos(phiavg), ampavg*sin(phiavg));
1850  set(i, v);
1851  set(j, v.conj());
1852  if ( fom ) {
1853  fomavg = (fom[i] + fom[j])/2;
1854  fom[i] = fomavg;
1855  fom[j] = fomavg;
1856  }
1857  Ramp += damp*damp;
1858  Rphi += dphi*dphi;
1859  nR++;
1860  }
1861  }
1862  }
1863  if ( nR ) {
1864  Ramp = sqrt(Ramp/nR);
1865  Rphi = sqrt(Rphi/nR);
1866  }
1867  if ( verbose & VERB_PROCESS )
1868  cout << nn+1 << tab << nR << tab << Ramp << tab << Rphi*180/M_PI << endl;
1869  }
1870  if ( verbose )
1871  cout << endl;
1872 
1873  return 0;
1874 }
1875 
1888 Bimage* Bimage::phase_difference(Bimage* p, int type, double res_hi, double res_lo)
1889 {
1890  if ( res_hi <= 0 ) res_hi = 0.1;
1891  if ( res_lo <= 0 ) res_lo = 1e10;
1892  if ( res_lo < res_hi + 1 ) res_lo = res_hi + 1;
1893 
1894  Bimage* ppd = pack_two_in_complex(p);
1895 
1896  ppd->fft();
1897 
1898 // if ( verbose & VERB_FULL )
1899  if ( verbose ) {
1900  if ( !(type&1) ) cout << "Phase angle";
1901  else if ( type&1 ) cout << "Cosine phase angle";
1902  cout << " difference" << endl;
1903  if ( type & 2 ) cout << "With amplitude scaling" << endl;
1904  cout << "Resolution range: "
1905  << res_hi << " - " << res_lo << endl << endl;
1906  }
1907 
1908  long i, j, xx, yy, zz, nn;
1909  long ix, iy, iz;
1911  double smax2 = 1.0/(res_hi*res_hi);
1912  double smin2 = 1.0/(res_lo*res_lo);
1913  double dy, dz, sx2, sy2, sz2, s2, w;
1914  Vector3<double> scale(1.0/ppd->real_size());
1915  Complex<float> temp1, temp2;
1916 
1917  float* dphi = new float[datasize];
1918 
1919  if ( verbose )
1920  cout << "Image\tShift" << endl;
1921  for ( nn=0; nn<ppd->images(); nn++ ) {
1922  ppd->image[nn].origin(image[nn].origin() - p->image[nn].origin());
1923  shift = ppd->image[nn].origin()/ppd->size();
1924  if ( verbose )
1925  cout << nn+1 << tab << shift << endl;
1926  for ( zz=0; zz<ppd->z; zz++ ) {
1927  iz = -zz;
1928  if ( iz < 0 ) iz += ppd->z;
1929  dz = zz;
1930  if ( zz > (ppd->z - 1)/2 ) dz -= ppd->z;
1931  sz2 = dz*scale[2];
1932  sz2 *= sz2;
1933  for ( yy=0; yy<ppd->y; yy++ ) {
1934  iy = -yy;
1935  if ( iy < 0 ) iy += ppd->y;
1936  dy = yy;
1937  if ( yy > (ppd->y - 1)/2 ) dy -= ppd->y;
1938  sy2 = dy*scale[1];
1939  sy2 *= sy2;
1940  for ( xx=0; xx<ppd->x/2+1; xx++ ) {
1941  ix = -xx;
1942  if ( ix < 0 ) ix += ppd->x;
1943  sx2 = xx*scale[0];
1944  sx2 *= sx2;
1945  s2 = sx2 + sy2 + sz2;
1946  if ( s2 >= smin2 && s2 <= smax2 ) {
1947  i = ppd->index(xx,yy,zz,nn);
1948  j = ppd->index(ix,iy,iz,nn);
1949  temp1 = ppd->complex(i).unpack_first(ppd->complex(j));
1950  temp2 = ppd->complex(i).unpack_second(ppd->complex(j));
1951  dphi[i] = temp1.phi() - temp2.phi() - TWOPI*(xx*shift[0] + yy*shift[1] + zz*shift[2]);
1952  if ( !(type & 1) ) dphi[i] = angle_set_negPI_to_PI(dphi[i]);
1953  if ( type & 1 ) dphi[i] = cos(dphi[i]);
1954  if ( type & 2 ) {
1955  w = temp1.power()*temp2.power();
1956  dphi[i] *= w/(w+1);
1957  }
1958  dphi[j] = dphi[i];
1959  }
1960  }
1961  }
1962  }
1963  }
1964 
1965  ppd->data_type(Float);
1966  ppd->compound_type(TSimple);
1967  ppd->channels(1);
1968  ppd->fourier_type(NoTransform);
1969  ppd->data_assign((unsigned char *) dphi);
1970 
1971  return ppd;
1972 }
1973 
1986 double Bimage::average_phase_difference(Bimage* p, double res_hi, double res_lo, int weighting)
1987 {
1988  if ( res_hi <= 0 ) res_hi = 0.1;
1989  if ( res_lo < res_hi + 1 ) res_lo = res_hi + 1;
1990 
1991  Bimage* ppd = pack_two_in_complex(p);
1992 
1993  ppd->fft();
1994 
1995  long i, j, xx, yy, zz, nn;
1996  long ix, iy, iz;
1998  double smax2 = 1.0/(res_hi*res_hi);
1999  double smin2 = 1.0/(res_lo*res_lo);
2000  double dy, dz, sx2, sy2, sz2, s2;
2001  Vector3<double> scale(1.0/ppd->real_size());
2002  Complex<float> temp1, temp2;
2003 
2004  double amp, dphi, sum_amp(0), avg_pd(0);
2005 
2006  for ( nn=0; nn<ppd->images(); nn++ ) {
2007 // ppd->image[nn].origin(image[nn].origin() - p->image[nn].origin());
2008  ppd->image[nn].origin(image[nn].origin() - p->image[nn].origin());
2009  shift = ppd->image[nn].origin()/ppd->size();
2010  if ( verbose & VERB_FULL )
2011  cout << nn+1 << tab << shift << endl;
2012  for ( zz=0; zz<ppd->z; zz++ ) {
2013  iz = -zz;
2014  if ( iz < 0 ) iz += ppd->z;
2015  dz = zz;
2016  if ( zz > (ppd->z - 1)/2 ) dz -= ppd->z;
2017  sz2 = dz*scale[2];
2018  sz2 *= sz2;
2019  for ( yy=0; yy<ppd->y; yy++ ) {
2020  iy = -yy;
2021  if ( iy < 0 ) iy += ppd->y;
2022  dy = yy;
2023  if ( yy > (ppd->y - 1)/2 ) dy -= ppd->y;
2024  sy2 = dy*scale[1];
2025  sy2 *= sy2;
2026  for ( xx=0; xx<ppd->x/2+1; xx++ ) {
2027  ix = -xx;
2028  if ( ix < 0 ) ix += ppd->x;
2029  sx2 = xx*scale[0];
2030  sx2 *= sx2;
2031  s2 = sx2 + sy2 + sz2;
2032  if ( s2 >= smin2 && s2 <= smax2 ) {
2033  i = ppd->index(xx,yy,zz,nn);
2034  j = ppd->index(ix,iy,iz,nn);
2035  temp1 = ppd->complex(i).unpack_first(ppd->complex(j));
2036  temp2 = ppd->complex(i).unpack_second(ppd->complex(j));
2037  dphi = temp1.phi() - temp2.phi() - TWOPI*(xx*shift[0] + yy*shift[1] + zz*shift[2]);
2038  dphi = angle_set_negPI_to_PI(dphi);
2039  switch ( weighting ) {
2040  case 1:
2041  amp = temp1.amp();
2042  break;
2043  case 2:
2044  amp = temp2.amp();
2045  break;
2046  case 3:
2047  amp = temp1.amp()*temp2.amp();
2048  break;
2049  default:
2050  amp = 1e30;
2051  }
2052  amp /= amp + 1;
2053  sum_amp += amp;
2054  avg_pd += amp*fabs(dphi);
2055  }
2056  }
2057  }
2058  }
2059  }
2060 
2061  if ( sum_amp ) avg_pd /= sum_amp;
2062  else avg_pd = M_PI;
2063 
2064  delete ppd;
2065 
2066  return avg_pd;
2067 }
2068 
2075 {
2076  fft();
2077 
2078  long i, ds(x*y*z*n);
2079 
2080  for ( i=0; i<ds; i++ )
2081  if ( (*pd)[i] < 0 ) set(i, -complex(i));
2082 
2083  fft_back();
2084 
2085  return 0;
2086 }
2087 
Bimage::fft_setup
fft_plan fft_setup(fft_direction dir, int opt=0)
Sets up a plan for fast Fourier transforms.
Definition: Bimage_fft.cpp:29
Bimage::real_size
Vector3< double > real_size()
Definition: Bimage.h:500
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
Bimage::fspace_radial_power
Bimage * fspace_radial_power(double resolution, double sampling_ratio=1)
Calculates the radial power spectrum from a Fourier transform.
Definition: Bimage_fspace.cpp:610
matrix_linear.h
Header file for matrix functions.
Bimage::friedel_apply
int friedel_apply()
Applies Friedel symmetry.
Definition: Bimage_fspace.cpp:1806
Bimage::fspace_radial
double * fspace_radial(long nn, long maxrad, int flag=0)
Calculates the radial power spectrum from a Fourier transform.
Definition: Bimage_fspace.cpp:729
FourierType
FourierType
Fourier transform format specifier.
Definition: Bimage.h:40
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
Bimage::fspace_weigh_ramp
int fspace_weigh_ramp(double resolution, fft_plan planf, fft_plan planb)
Weighs a transform with a ramp.
Definition: Bimage_fspace.cpp:1062
Bimage::shift
int shift(Vector3< double > vec, int fill_type=0, double fill=0)
Shifts an image.
Definition: Bimage_transform.cpp:589
UCharacter
@ UCharacter
Definition: utilities.h:153
Complex
Definition: Complex.h:23
Bimage::average
double average()
Definition: Bimage.h:543
Complex::real
Type real()
Definition: Complex.h:101
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1118
Bimage::fspace_positive
int fspace_positive()
Sets the image to positive definite.
Definition: Bimage_fspace.cpp:1703
Bplot::rows
void rows(long n)
Definition: Bplot.h:212
Bimage::next
Bimage * next
Definition: Bimage.h:179
Bimage::fspace_background
int fspace_background()
Calculates the background for a Fourier transform.
Definition: Bimage_fspace.cpp:46
Bimage::Bimage
Bimage()
Initializes an image.
Definition: Bimage.cpp:43
linear_least_squares
double linear_least_squares(int n1, int n2, double *x, double *y, double &a, double &b)
Does a linear least squares fit between two vectors.
Definition: matrix_linear.cpp:28
Bimage::simple_to_complex
void simple_to_complex()
A simple image is converted to a complex image.
Definition: Bimage_complex.cpp:22
Vector3< long >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
Bimage::pack_two_in_complex
Bimage * pack_two_in_complex(Bimage *p)
Packs two real images into one complex image.
Definition: Bimage_complex.cpp:679
TypePointer::uc
unsigned char * uc
Definition: Bimage.h:70
Bimage::fspace_weigh_dose
int fspace_weigh_dose(long nn, double dose_per_frame, vector< double > critdose)
Definition: Bimage_fspace.cpp:1460
GOLDEN
#define GOLDEN
Definition: utilities.h:85
Bimage::fspace_fit_B_factor
double fspace_fit_B_factor(double res_hi=0)
Determines the overall B-factor of an image.
Definition: Bimage_fspace.cpp:994
Bimage::fspace_square_amp
int fspace_square_amp()
Change the amlitudes to their squares.
Definition: Bimage_fspace.cpp:455
verbose
int verbose
TComplex
@ TComplex
Definition: Bimage.h:60
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
Bimage::phase_difference
Bimage * phase_difference(Bimage *p, int type=0, double res_hi=0, double res_lo=0)
Calculates the cosine of the phase difference between two images.
Definition: Bimage_fspace.cpp:1888
Bplot
Definition: Bplot.h:146
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
Bimage::transform
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
Definition: Bimage_transform.cpp:37
Bimage::fft_back
int fft_back()
Definition: Bimage.h:831
Bimage::fspace_weigh_accumulated_dose
int fspace_weigh_accumulated_dose(vector< double > dose)
Weighs an image's amplitudes with the accumulated dose.
Definition: Bimage_fspace.cpp:1561
critical_exposure_curve
vector< double > critical_exposure_curve(long size, double real_size, int flag)
Definition: Bimage_fspace.cpp:1396
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:111
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:558
Bimage::fspace_weigh_FSC_curve
int fspace_weigh_FSC_curve(Bplot *plot, double resolution=0)
Weighs an image's amplitudes with a given FSC curve.
Definition: Bimage_fspace.cpp:1365
Standard
@ Standard
Definition: Bimage.h:42
planf
fft_plan planf
Definition: bico.cpp:24
Bimage::phase_shift
int phase_shift(Vector3< double > shift)
Phase shifts a complex image.
Definition: Bimage_complex.cpp:256
Bimage::fspace_normalize
int fspace_normalize()
Normalizes an image's amplitudes.
Definition: Bimage_fspace.cpp:1634
Bimage::images
long images()
Definition: Bimage.h:504
Bsub_image::background
double background()
Definition: Bimage.h:125
Matrix3
Definition: Matrix3.h:18
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:136
TSimple
@ TSimple
Definition: Bimage.h:59
Bimage::change_transform_size
Vector3< double > change_transform_size(Vector3< long > nusize)
Resizes a "standard" transform.
Definition: Bimage_fft.cpp:239
Bimage::fspace_weigh_C_curve
int fspace_weigh_C_curve(double resolution=0)
Weighs an image's amplitudes with the carbon scattering curve.
Definition: Bimage_fspace.cpp:1226
Bimage::add
void add(long j, double v)
Definition: Bimage.h:321
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:391
fft_destroy_plan
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
Definition: fft.cpp:87
Bimage::file_name
string & file_name()
Definition: Bimage.h:246
SMALLFLOAT
#define SMALLFLOAT
Definition: utilities.h:46
Bimage::fft
int fft()
Definition: Bimage.h:830
Bimage::fspace_translate
int fspace_translate(Vector3< double > shift)
Translates an image in frequency space to avoid interpolation.
Definition: Bimage_fspace.cpp:147
Bimage::fourier_type
FourierType fourier_type()
Definition: Bimage.h:380
VERB_RESULT
#define VERB_RESULT
Definition: utilities.h:109
ctf.h
Header file for CTF (contrast transfer function) functions.
Bimage
General image parameter class.
Definition: Bimage.h:177
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:364
Bimage::fspace_interpolate
Complex< double > fspace_interpolate(long img_num, Vector3< double > m, FSI_Kernel *kernel)
Calculates the complex value at an image location by kernel-based interpolation.
Definition: Bimage_fspace.cpp:85
C_curve
vector< double > C_curve(long n, double freq_step)
Calculates the carbon scattering curve.
Definition: ctf.cpp:515
Bimage::fspace_weigh
int fspace_weigh(long maxrad, double *curve, int flag=0)
Definition: Bimage_fspace.cpp:795
Bimage::complex
Complex< double > complex(long j)
Returns a complex value at the given index.
Definition: Bimage.cpp:1027
Complex::imag
Type imag()
Definition: Complex.h:102
Bimage.h
Header file for image class.
Bimage::plot
Bplot * plot()
Converts a one-dimensional image into a plot.
Definition: Bimage.cpp:3839
Bimage::complex_power
double complex_power()
Calculates the power in a complex image.
Definition: Bimage_complex.cpp:200
Complex::phi
double phi()
Definition: Complex.h:105
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:245
Bimage::fspace_bandpass
int fspace_bandpass(double res_hi, double res_lo=0, double width=0)
Applies a bandpass filter to an image.
Definition: Bimage_fspace.cpp:496
Bimage::fspace_maximum_radius
long fspace_maximum_radius(double resolution, double sampling_ratio=1)
Calculates the maximum radius in frequency space from a given resolution.
Definition: Bimage_fspace.cpp:26
Bimage::data_type
DataType data_type()
Definition: Bimage.h:362
M_PI
#define M_PI
Definition: utilities.h:63
Bimage::fspace_weigh_B_factor
int fspace_weigh_B_factor(double B, double resolution=0)
Weighs an image's amplitudes with B-factor (gaussian) curve.
Definition: Bimage_fspace.cpp:1183
utilities.h
Header file for general utilities.
Bimage::fspace_amp_threshold
int fspace_amp_threshold(double threshold)
Filters the amplitudes of the Fourier transform of an image.
Definition: Bimage_fspace.cpp:368
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:22
Complex::power
double power()
Definition: Complex.h:103
Bimage::check_resolution
void check_resolution(double &resolution)
Checks that the resolution falls within reasonable limits.
Definition: Bimage.cpp:635
Bimage::fspace_normalize_radial
int fspace_normalize_radial(Bimage *pmask, double resolution=0, int flag=0)
Normalizes an image's amplitudes.
Definition: Bimage_fspace.cpp:1662
isfinite
bool isfinite(complex< T > &value)
radiation_damage_curve
vector< double > radiation_damage_curve(vector< double > dose, long size, double real_size)
Definition: Bimage_fspace.cpp:1428
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
Bimage::fsc
Bplot * fsc(double hi_res, double sampling_ratio=1)
Definition: Bimage_resolution.cpp:245
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
Bimage::index
long index(long nx, long ny) const
Definition: Bimage.h:396
Complex::conj
Complex conj()
Definition: Complex.h:106
Bimage::fspace_amp_one
int fspace_amp_one()
Sets all amplitudes to one.
Definition: Bimage_fspace.cpp:323
fft_plan
fftwf_plan fft_plan
Definition: fft.h:20
Bimage::fspace_sqrt_amp
int fspace_sqrt_amp()
Change the amlitudes to their square roots.
Definition: Bimage_fspace.cpp:424
Bsub_image::sampling
void sampling(double x, double y, double z)
Definition: Bimage.h:127
Complex::is_finite
bool is_finite()
Definition: Complex.h:100
VERB_FULL
#define VERB_FULL
Definition: utilities.h:113
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:284
Bimage::sampling
vector< Vector3< double > > sampling()
Definition: Bimage.h:529
Bimage::data_assign
unsigned char * data_assign(unsigned char *nudata)
Assign image data.
Definition: Bimage.cpp:875
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:178
Vector3::min
Type min()
Definition: Vector3.h:169
Bimage::phase_flip
int phase_flip(Bimage *pd)
Flips the phases of an image based on a phase difference map.
Definition: Bimage_fspace.cpp:2074
planb
fft_plan planb
Definition: bico.cpp:24
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
Bimage::fspace_weigh_LoG
int fspace_weigh_LoG(double resolution, double sigma)
Weighs an image's amplitudes with a Laplacian-of-Gaussian function.
Definition: Bimage_fspace.cpp:1261
Bimage::fspace_weigh_RPS_curve
int fspace_weigh_RPS_curve(Bplot *plot, double resolution=0)
Weighs an image's amplitudes with a given RPS curve.
Definition: Bimage_fspace.cpp:1308
Vector3::length
double length()
Definition: Vector3.h:222
Bimage::fspace_scale
int fspace_scale(long maxrad, double *scale, Bimage *pmask=NULL)
Definition: Bimage_fspace.cpp:842
Complex::amp
double amp()
Definition: Complex.h:104
Float
@ Float
Definition: utilities.h:161
Bimage::channels
long channels()
Definition: Bimage.h:384
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:110
Bimage::average_phase_difference
double average_phase_difference(Bimage *p, double res_hi, double res_lo, int weighting=1)
Calculates the average of the absolute phase difference between two images within given resolution sh...
Definition: Bimage_fspace.cpp:1986
Bimage::friedel_check
double friedel_check()
Checks Friedel symmetry.
Definition: Bimage_fspace.cpp:1744
NoTransform
@ NoTransform
Definition: Bimage.h:41
Bimage::fspace_resize
int fspace_resize(double scale, double res_hi, double res_lo)
Resizes an image in frequency space to avoid interpolation.
Definition: Bimage_fspace.cpp:202
Vector3::length2
double length2()
Definition: Vector3.h:221
kernel
Definition: kernlut.h:14
Bimage::complex_to_real
void complex_to_real()
The real part of a complex image is written to a simple image.
Definition: Bimage_complex.cpp:50
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Bimage::resize
int resize(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
Definition: Bimage_resize.cpp:28
FOM
@ FOM
Definition: mg_processing.h:40
FSI_Kernel
Definition: FSI_Kernel.h:14
TWOPI
#define TWOPI
Definition: utilities.h:72
Vector3::max
Type max()
Definition: Vector3.h:175