Bsoft  1.9
Bernard's software package
img_ctf.h File Reference

Header file for CTF (contrast transfer function) functions. More...

#include "rwimg.h"
#include "fft.h"
#include "ctf.h"

Go to the source code of this file.

Functions

Bimage * img_ctf_calculate (CTFparam cp, int action, double wiener, Vector3< long > size, Vector3< double > sampling, double lores=0, double hires=0)
 Calculates a CTF complex image. More...
 
Bimage * img_wave_aberration (CTFparam cp, Vector3< int > size, Vector3< float > sampling)
 Calculates a wave aberration function. More...
 
int img_ctf_apply (Bimage *p, CTFparam *em_ctf, int action, double wiener, double lores, double hires)
 Applies or corrects for the contrast transfer function (CTF). More...
 
int img_ctf_apply (Bimage *p, CTFparam *em_ctf, int action, double wiener, double lores, double hires, fft_plan planf_2D, fft_plan planb_2D)
 
int img_ttf_apply (Bimage *p, CTFparam *ctf, int action, double wiener, Vector3< int > tile_size, double tilt, double axis, double res_lo, double res_hi)
 Applies or corrects for the tilted contrast transfer function (TTF). More...
 
int img_ctf_apply_to_proj (Bimage *proj, CTFparam *em_ctf, double defocus, double res_lo, double res_hi, fft_plan planf_2D, fft_plan planb_2D)
 Applies a CTF to a projection image. More...
 
Bimage * img_ctf_radial_average (Bimage *p, long n, CTFparam *em_ctf)
 Calculates the power spectrum radial average corrected for astigmatism. More...
 
double img_ctf_fit (Bimage *p, long n, CTFparam *em_ctf, double lores, double hires)
 Determines the CTF parameters from a power spectrum. More...
 
double img_ctf_fit_baseline (Bimage *p, long n, CTFparam *em_ctf, double lores, double hires)
 Fits only the baseline for a given CTF. More...
 
double img_ctf_fit_envelope (Bimage *p, long n, CTFparam *em_ctf, double lores, double hires)
 Fits only the envelope for a given CTF. More...
 
double img_ctf_find_defocus (Bimage *p, long n, CTFparam *em_ctf, double lores, double hires, double def_start=1e3, double def_end=2e5, double def_inc=1e3)
 Searches for the defocus based on correlation. More...
 
double img_ctf_fit_astigmatism (Bimage *p, long n, CTFparam *em_ctf, double lores, double hires)
 Fits the astigmatism with a given defocus, baseline and envelope. More...
 

Detailed Description

Header file for CTF (contrast transfer function) functions.

Author
Bernard Heymann
Date
Created: 20000426
Modified: 20160520

Definition in file img_ctf.h.

Function Documentation

int img_ctf_apply ( Bimage *  p,
CTFparam *  em_ctf,
int  action,
double  wiener,
double  lores,
double  hires 
)

Applies or corrects for the contrast transfer function (CTF).

Parameters
*pimage (modified).
*em_ctfCTF parameter structure.
actionaction to be taken.
wienerWiener factor (fraction).
loreslow resolution limit.
hireshigh resolution limit.
Returns
int 0, <0 on error.
The actions for this funtion are:
1   flip phase (multiply by the sign of the CTF)
2   apply a CTF (multiply with the CTF)
3   correct for the CTF: ctf/(ctf^2 + wiener_factor)
4   correct for the CTF: env*ctf/((env*ctf)^2 + noise^2)
5   correct for the CTF with baseline: ctf/(ctf^2*noise^2 + wiener_factor)
6   correct for the CTF with baseline: 1/(ctf*noise + sign*wiener_factor)
Functions:
    angle = atan(y/x)
    s2 = x*x + y*y
    defocus_average = (defocus_max + defocus_min)/2
    defocus_deviation = (defocus_max - defocus_min)/2
    defocus = defocus_average + defocus_deviation*cos(2*(angle - astigmatism_angle))
    phase = 0.5*PI*lambda*lambda*lambda*Cs*s2*s2 - PI*lambda*defocus*s2;
    phi_fac = sqrt(1-amp_fac*amp_fac)
    CTF = amp_fac*cos(phase) - phi_fac*sin(phase)
Note: Defocus is positive for underfocus and negative for overfocus.
All of the parameters required to calculate the CTF, envelope and baseline
functions are embedded in the CTF structure.

Definition at line 268 of file img_ctf.cpp.

int img_ctf_apply ( Bimage *  p,
CTFparam *  em_ctf,
int  action,
double  wiener,
double  lores,
double  hires,
fft_plan  planf_2D,
fft_plan  planb_2D 
)

Definition at line 299 of file img_ctf.cpp.

int img_ctf_apply_to_proj ( Bimage *  proj,
CTFparam *  em_ctf,
double  defocus,
double  res_lo,
double  res_hi,
fft_plan  planf_2D,
fft_plan  planb_2D 
)

Applies a CTF to a projection image.

Parameters
*projprojection image.
*em_ctfCTF parameters.
defocusdefocus.
res_lolow resolution limit (angstrom).
res_hihigh resolution limit (angstrom).
planf_2D2D forward fourier transform plan.
planb_2D2D backward fourier transform plan.
Returns
int error code.

Definition at line 379 of file img_ctf.cpp.

Bimage* img_ctf_calculate ( CTFparam  cp,
int  action,
double  wiener,
Vector3< long >  size,
Vector3< double >  sampling,
double  lores,
double  hires 
)

Calculates a CTF complex image.

Parameters
cpCTF parameters.
actiontype of CTF calculated (1-8).
wienerWiener factor (fraction).
sizenew image size.
samplingnew image pixel size.
loreslow resolution limit.
hireshigh resolution limit.
Returns
Bimage* p new CTF function image.
Functions:
    angle = atan(y/x)
    s2 = x*x + y*y
    defocus_average = (defocus_max + defocus_min)/2
    defocus_deviation = (defocus_max - defocus_min)/2
    defocus = defocus_average + defocus_deviation*cos(2*(angle - astigmatism_angle))
    phase = 0.5*PI*lambda*lambda*lambda*Cs*s2*s2 - PI*lambda*defocus*s2;
    CTF = cos(phase) + i*sin(phase)
Note: Defocus is positive for underfocus and negative for overfocus.

Definition at line 55 of file img_ctf.cpp.

double img_ctf_find_defocus ( Bimage *  p,
long  n,
CTFparam *  em_ctf,
double  lores,
double  hires,
double  def_start,
double  def_end,
double  def_inc 
)

Searches for the defocus based on correlation.

Parameters
*pimage structure.
nsub-image number.
*em_ctfCTF parameter structure.
loreslow resolution limit.
hireshigh resolution limit.
def_startdefocus search start (default 1e3).
def_enddefocus search end (default 2e5).
def_incdefocus search increment (default 1e3).
Returns
double R factor.
A radial power spectrum is calculated.
A range of defocus values is tested (1000-200000 angstrom, 0.1-20 um), 
and the best fitting value accepted.
The new parameters are written into the CTFparam structure.

Definition at line 942 of file img_ctf.cpp.

double img_ctf_fit ( Bimage *  p,
long  n,
CTFparam *  em_ctf,
double  lores,
double  hires 
)

Determines the CTF parameters from a power spectrum.

Parameters
*pimage structure.
nsub-image number.
*em_ctfCTF parameter structure.
loreslow resolution limit.
hireshigh resolution limit
Returns
double first zero.
Input: Power spectrum or its logarithm.
A radial power spectrum is calculated.
A range of defocus values is tested (100-200000 angstrom, 0.01-20 um), 
defining the baseline as passing through the zeroes for each defocus 
and fitting it to a 4th order polynomial.
The envelope function is a simple gaussian on top of the baseline and
fitted to minimize the RMSD between the calculated curve and the
radial power spectrum logarithm.
The fitting is limited to the spatial frequency range between the 
first and last zeroes.
Defocus values are positive for underfocus.
Functions:
    angle = atan(y/x)
    s2 = reciprocal space distance squared
    defocus_average = (defocus_max + defocus_min)/2
    defocus_deviation = (defocus_max - defocus_min)/2
    defocus = defocus_average + defocus_deviation*cos(2*(angle - astigmatism_angle))
    phase = 0.5*PI*lambda*lambda*lambda*Cs*s2*s2 - PI*lambda*defocus*s2;
    phi_fac = sqrt(1-amp_fac*amp_fac)
    CTF = amp_fac*cos(phase) - phi_fac*sin(phase)
The new parameters are written into the Bimage structure.

Definition at line 705 of file img_ctf.cpp.

double img_ctf_fit_astigmatism ( Bimage *  p,
long  n,
CTFparam *  em_ctf,
double  lores,
double  hires 
)

Fits the astigmatism with a given defocus, baseline and envelope.

Parameters
*pimage structure.
nsub-image number.
*em_ctfCTF parameter structure.
loreslow resolution limit.
hireshigh resolution limit
Returns
double objective measure (larger is better).
A radial power spectrum is calculated and the baseline subtracted.
The defocus deviation starts from a low value to get an estimate of
the astigmatism angle. The defocus deviation is modified nased on
the direction of improvements in the fit, at each iteration 
narrowing the angular search for the astigmatism angle.
The new parameters are written into the CTFparam structure.

Definition at line 1024 of file img_ctf.cpp.

double img_ctf_fit_baseline ( Bimage *  p,
long  n,
CTFparam *  em_ctf,
double  lores,
double  hires 
)

Fits only the baseline for a given CTF.

Parameters
*pimage structure.
nsub-image number.
*em_ctfCTF parameter structure.
loreslow resolution limit.
hireshigh resolution limit
Returns
double R factor.
A radial power spectrum is calculated incorporating astigmatism.
The baseline of the required type is fit.
The new parameters are written into the CTFparam structure.

Definition at line 852 of file img_ctf.cpp.

double img_ctf_fit_envelope ( Bimage *  p,
long  n,
CTFparam *  em_ctf,
double  lores,
double  hires 
)

Fits only the envelope for a given CTF.

Parameters
*pimage structure.
nsub-image number.
*em_ctfCTF parameter structure.
loreslow resolution limit.
hireshigh resolution limit
Returns
double R factor.
A radial power spectrum is calculated incorporating astigmatism.
The envelope is fit.
The new parameters are written into the CTFparam structure.

Definition at line 885 of file img_ctf.cpp.

Bimage* img_ctf_radial_average ( Bimage *  p,
long  n,
CTFparam *  em_ctf 
)

Calculates the power spectrum radial average corrected for astigmatism.

Parameters
*pimage structure.
nsub-image number.
*em_ctfCTF parameter structure.
Returns
Bimage* radial average, NULL on error.
A power spectrum with its origin at the center.
Functions:
    angle = atan(y/x) - astigmatism_angle
    s2 = reciprocal space distance squared
    defocus_min = defocus_avg - defocus_dev
    defocus_max = defocus_avg + defocus_dev
    smin2 = 1 - defocus_dev/defocus_avg
    smax2 = 1 + defocus_dev/defocus_avg
    radius = sqrt(2*s2*(smax2*cos(angle)*cos(angle)+
                smin2*sin(angle)*sin(angle))/(smax2+smin2))
The radial average is returned as a new 1D image.

Definition at line 554 of file img_ctf.cpp.

int img_ttf_apply ( Bimage *  p,
CTFparam *  ctf,
int  action,
double  wiener,
Vector3< int >  tile_size,
double  tilt,
double  axis,
double  res_lo,
double  res_hi 
)

Applies or corrects for the tilted contrast transfer function (TTF).

Parameters
*pimage (modified).
*ctfCTF parameter structure.
actionaction to be taken.
wienerWiener factor (fraction).
tile_sizetile size for tilted CTF operations.
tilttilt angle (radians).
axistilt axis angle (radians).
res_lohigh resolution limit.
res_hilow resolution limit.
Returns
int 0, <0 on error.
The actions for this funtion are:
1   flip phase (multiply by the sign of the CTF)
2   apply a CTF (multiply with the CTF)
3   correct for the CTF: ctf/(ctf^2 + wiener_factor)
4   correct for the CTF: env*ctf/((env*ctf)^2 + noise^2)
5   correct for the CTF with baseline: ctf/(ctf^2*noise^2 + wiener_factor)
6   correct for the CTF with baseline: 1/(ctf*noise + sign*wiener_factor)
Functions:
    angle = atan(y/x)
    s2 = x*x + y*y
    defocus_average = (defocus_max + defocus_min)/2
    defocus_deviation = (defocus_max - defocus_min)/2
    defocus = defocus_average + defocus_deviation*cos(2*(angle - astigmatism_angle))
    phase = 0.5*PI*lambda*lambda*lambda*Cs*s2*s2 - PI*lambda*defocus*s2;
    phi_fac = sqrt(1-amp_fac*amp_fac)
    CTF = amp_fac*cos(phase) - phi_fac*sin(phase)
Note: Defocus is positive for underfocus and negative for overfocus.
All of the parameters required to calculate the CTF, envelope and baseline
functions are embedded in the CTF structure.

Definition at line 431 of file img_ctf.cpp.

Bimage* img_wave_aberration ( CTFparam  cp,
Vector3< int >  size,
Vector3< float >  sampling 
)

Calculates a wave aberration function.

Parameters
cpCTF parameters.
sizenew image size.
samplingnew image pixel size.
Returns
Bimage* p new wave aberration function image.
Functions:
    angle = atan(y/x)
    s2 = x*x + y*y
    defocus_average = (defocus_max + defocus_min)/2
    defocus_deviation = (defocus_max - defocus_min)/2
    defocus = defocus_average + defocus_deviation*cos(2*(angle - astigmatism_angle))
    phase = 0.5*PI*lambda*lambda*lambda*Cs*s2*s2 - PI*lambda*defocus*s2;
Note: Defocus is positive for underfocus and negative for overfocus.

Definition at line 193 of file img_ctf.cpp.