Xmipp  v3.23.11-Nereus
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
FourierFilter Class Reference

#include <fourier_filter.h>

Inheritance diagram for FourierFilter:
Inheritance graph
[legend]
Collaboration diagram for FourierFilter:
Collaboration graph
[legend]

Public Member Functions

void readParams (XmippProgram *program)
 
void apply (MultidimArray< double > &img)
 
 FourierFilter ()
 
void init ()
 
void show ()
 
double maskValue (const Matrix1D< double > &w)
 
void generateMask (MultidimArray< double > &v)
 
void applyMaskSpace (MultidimArray< double > &v)
 
void applyMaskFourierSpace (const MultidimArray< double > &v, MultidimArray< std::complex< double > > &V)
 
double maskPower ()
 
void correctPhase ()
 
- Public Member Functions inherited from XmippFilter
virtual ~XmippFilter ()
 

Static Public Member Functions

static void defineParams (XmippProgram *program)
 

Public Attributes

int FilterShape
 
int FilterBand
 
double w1
 
double w2
 
double sampling_rate
 
double t1
 
double t2
 
double rot
 
double tilt
 
double psi
 
double percentage
 
FileName maskFn
 
double raised_w
 
CTFDescription ctf
 
double minCTF
 
FileName fnFSC
 
FileName fnFilter
 
bool do_generate_3dmask
 
Matrix1D< double > w
 
MultidimArray< int > maskFourier
 
MultidimArray< double > maskFourierd
 
FourierTransformer transformer
 
MultidimArray< double > vMag
 
MultidimArray< double > vMagSorted
 
std::vector< double > freqContFSC
 
std::vector< double > FSC
 

Detailed Description

Filter class for Fourier space.

Example of use for highpass filtering

I.read("image.xmp");
Filter.w1=w_cutoff;
Filter.raised_w=slope;
I().setXmippOrigin();
Filter.applyMaskSpace(I());
I.write("filtered_image.xmp");

Example of use for wedge filtering

V.read("1rux64.vol");
V().setXmippOrigin();
Filter.t1=-60;
Filter.t2= 60;
Filter.rot=Filter.tilt=Filter.psi=0;
Filter.do_generate_3dmask=true;
Filter.generateMask(V());
Filter.applyMaskSpace(V());

For volumes you the mask is computed on the fly and in this way memory is saved (unless do_generate_3dmask == true).

Definition at line 69 of file fourier_filter.h.

Constructor & Destructor Documentation

◆ FourierFilter()

FourierFilter::FourierFilter ( )

Empty constructor

Definition at line 45 of file fourier_filter.cpp.

46 {
47  init();
48 }

Member Function Documentation

◆ apply()

void FourierFilter::apply ( MultidimArray< double > &  img)
virtual

Process one image

Implements XmippFilter.

Definition at line 379 of file fourier_filter.cpp.

380 {
381  static bool firstTime = true;
382  do_generate_3dmask = (img.zdim > 1);
383  if (firstTime)
384  {
385  generateMask(img);
386  firstTime = false;
387  }
388  if (maskFn != "")
389  if (do_generate_3dmask==0 && MULTIDIM_SIZE(img)>1024*1024)
390  REPORT_ERROR(ERR_IO_SIZE,"Cannot save 2D mask with xdim*ydim > 1M");
391  else
392  {
393  Image<int> I;
394  Image<double> D;
395  if ( XSIZE(maskFourier) !=0 )
396  {
397  I()=maskFourier;
398  I.write(maskFn);
399  }
400  else if (XSIZE(maskFourierd)!=0)
401  {
402  D()=maskFourierd;
403  D.write(maskFn);
404  }
405  else
406  REPORT_ERROR(ERR_MATRIX_EMPTY,"Cannot save mask file");
407 
408  }
409  else
410  applyMaskSpace(img);
411 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define MULTIDIM_SIZE(v)
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
The matrix is empty.
Definition: xmipp_error.h:151
MultidimArray< double > maskFourierd
#define XSIZE(v)
MultidimArray< int > maskFourier
Incorrect file size.
Definition: xmipp_error.h:145
void generateMask(MultidimArray< double > &v)
void applyMaskSpace(MultidimArray< double > &v)

◆ applyMaskFourierSpace()

void FourierFilter::applyMaskFourierSpace ( const MultidimArray< double > &  v,
MultidimArray< std::complex< double > > &  V 
)

Apply mask in Fourier space. The image remains in Fourier space.

Definition at line 718 of file fourier_filter.cpp.

719 {
720  if (XSIZE(maskFourier)!=0 && !FilterShape==WEDGE_RC)
721  {
724  }
725  else if (XSIZE(maskFourierd)!=0)
726  {
727  auto *ptrV=(double*)&DIRECT_MULTIDIM_ELEM(V,0);
728  auto *ptrMask=(double*)&DIRECT_MULTIDIM_ELEM(maskFourierd,0);
730  {
731  *ptrV++ *= *ptrMask;
732  *ptrV++ *= *ptrMask++;
733  }
734  }
735  else if (FilterShape==SPARSIFY)
736  {
737  FFT_magnitude(V,vMag);
738  vMag.resize(1,1,1,MULTIDIM_SIZE(vMag));
740  double minMagnitude=A1D_ELEM(vMagSorted,(int)(percentage*XSIZE(vMag)));
742  if (DIRECT_MULTIDIM_ELEM(vMag,n)<minMagnitude)
743  {
744  auto *ptr=(double*)&DIRECT_MULTIDIM_ELEM(V,n);
745  *ptr=0;
746  *(ptr+1)=0;
747  }
748  }
749  else if (FilterShape==WEDGE_RC)
750  {
753 
754  w.resizeNoCopy(3);
755  for (size_t k=0; k<ZSIZE(V); k++)
756  {
757  FFT_IDX2DIGFREQ(k,ZSIZE(v),ZZ(w));
758  for (size_t i=0; i<YSIZE(V); i++)
759  {
760  FFT_IDX2DIGFREQ(i,YSIZE(v),YY(w));
761  for (size_t j=0; j<XSIZE(V); j++)
762  {
763  FFT_IDX2DIGFREQ(j,XSIZE(v),XX(w));
765  }
766  }
767  }
768  }
769  else if (FilterShape==WEDGE) {
772  }
773  else
774  {
775  w.resizeNoCopy(3);
776  for (size_t k=0; k<ZSIZE(V); k++)
777  {
778  FFT_IDX2DIGFREQ(k,ZSIZE(v),ZZ(w));
779  for (size_t i=0; i<YSIZE(V); i++)
780  {
781  FFT_IDX2DIGFREQ(i,YSIZE(v),YY(w));
782  for (size_t j=0; j<XSIZE(V); j++)
783  {
784  FFT_IDX2DIGFREQ(j,XSIZE(v),XX(w));
786  }
787  }
788  }
789  }
790 }
#define SPARSIFY
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void sort(MultidimArray< T > &result) const
#define MULTIDIM_SIZE(v)
#define A1D_ELEM(v, i)
MultidimArray< double > vMag
MultidimArray< double > maskFourierd
#define i
#define WEDGE
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
Matrix1D< double > w
#define XX(v)
Definition: matrix1d.h:85
#define XSIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define ZSIZE(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define DIRECT_A3D_ELEM(v, k, i, j)
double maskValue(const Matrix1D< double > &w)
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
#define j
#define YY(v)
Definition: matrix1d.h:93
#define WEDGE_RC
MultidimArray< double > vMagSorted
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
MultidimArray< int > maskFourier
void FFT_magnitude(const MultidimArray< std::complex< double > > &v, MultidimArray< double > &mag)
Definition: xmipp_fftw.cpp:393
int * n
#define ZZ(v)
Definition: matrix1d.h:101

◆ applyMaskSpace()

void FourierFilter::applyMaskSpace ( MultidimArray< double > &  v)

Apply mask in real space.

Definition at line 710 of file fourier_filter.cpp.

711 {
713  transformer.FourierTransform(v, aux3D, false);
714  applyMaskFourierSpace(v, aux3D);
716 }
void inverseFourierTransform()
Definition: xmipp_fftw.cpp:329
void FourierTransform(T &v, T1 &V, bool getCopy=true)
Definition: xmipp_fftw.h:166
void applyMaskFourierSpace(const MultidimArray< double > &v, MultidimArray< std::complex< double > > &V)
FourierTransformer transformer

◆ correctPhase()

void FourierFilter::correctPhase ( )

Correct phase

Definition at line 804 of file fourier_filter.cpp.

805 {
809 }
MultidimArray< double > maskFourierd
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int * n

◆ defineParams()

void FourierFilter::defineParams ( XmippProgram program)
static

Define parameters

Definition at line 51 of file fourier_filter.cpp.

52 {
53  program->addParamsLine("== Fourier ==");
54  program->addParamsLine(" [ --fourier <filter_type>] : Filter in Fourier space");
55  program->addParamsLine(" where <filter_type>");
56  program->addParamsLine(" low_pass <w1> <raisedw=0.02> : Cutoff freq (<1/2 or A)");
57  program->addParamsLine(" high_pass <w1> <raisedw=0.02> : Cutoff freq (<1/2 or A)");
58  program->addParamsLine(" band_pass <w1> <w2> <raisedw=0.02> : Cutoff freq (<1/2 or A)");
59  program->addParamsLine(" stop_band <w1> <w2> <raisedw=0.02> : Cutoff freq (<1/2 or A)");
60  program->addParamsLine(" stop_lowbandx <w1> <raisedw=0.02> : Cutoff freq (<1/2 or A)");
61  program->addParamsLine(" stop_lowbandy <w1> <raisedw=0.02> : Cutoff freq (<1/2 or A)");
62  program->addParamsLine(" wedge <th0> <thF> <rot=0> <tilt=0> <psi=0> : Missing wedge (along y) for data between th0-thF ");
63  program->addParamsLine(" : y is rotated by euler angles degrees");
64  program->addParamsLine(" cone <th0> : Missing cone for tilt angles up to th0 ");
65  program->addParamsLine(" : do not use mask type for wedge or cone filters");
66  program->addParamsLine(" real_gaussian <w1> : Gaussian in real space with sigma = w1");
67  program->addParamsLine(" gaussian <w1> : Gaussian in Fourier space with sigma = w1");
68  program->addParamsLine(" sparsify <p=0.975> : Delete p percent of the smallest Fourier coefficients");
69  program->addParamsLine(" ctf <ctfile> : Provide a .ctfparam file");
70  program->addParamsLine(" ctfpos <ctfile> : Provide a .ctfparam file");
71  program->addParamsLine(" : The CTF phase will be corrected before applying");
72  program->addParamsLine(" ctfinv <ctfile> <minCTF=0.05> : Apply the inverse of the CTF. Below the minCTF, the image is not corrected");
73  program->addParamsLine(" ctfposinv <ctfile> <minCTF=0.05> : Apply the inverse of the abs(CTF). Below the minCTF, the image is not corrected");
74  program->addParamsLine(" ctfdef <kV> <Cs> <Q0> <defocus> : Apply a CTF with this voltage (kV), spherical aberration (mm), Q0 (typically, 0.07), and defocus (A)");
75  program->addParamsLine(" ctfdefastig <kV> <Cs> <Q0> <defocusU> <defocusV> <defocusAngle> : Apply a CTF with this voltage (kV), spherical aberration (mm), Q0 (typically, 0.07), defocus (A), and defocusAngle (degrees)");
76  program->addParamsLine(" : The phase flip is not corrected");
77  program->addParamsLine(" bfactor <B> : Exponential filter (positive values for decay) ");
78  program->addParamsLine(" requires --sampling; ");
79  program->addParamsLine(" fsc <metadata> : Filter with the FSC profile contained in the metadata");
80  program->addParamsLine(" requires --sampling; ");
81  program->addParamsLine(" binary_file <file> : Binary file with the filter");
82  program->addParamsLine(" :+The filter must be defined in the whole Fourier space (not only the nonredundant part).");
83  program->addParamsLine(" :+This filter is produced, for instance, by xmipp_ctf_group");
84  program->addParamsLine(" astigmatism <sigma=120> : Filter images according to the astigmatism of their CTF");
85  program->addParamsLine(" :+sigma is the standard deviation of a Gaussian in degrees for the CTF phase");
86  program->addParamsLine(" requires --sampling; ");
87  program->addParamsLine(" alias -f;");
88  program->addParamsLine(" [--sampling <sampling_rate>] : If provided pass frequencies are taken in Ang and for the CTF case");
89  program->addParamsLine(" : and for the CTF case this is the sampling used to compute the CTF");
90  program->addParamsLine(" alias -s;");
91  program->addParamsLine(" requires --fourier;");
92  program->addParamsLine(" [--save <filename=\"\"> ] : Do not apply just save the mask");
93  program->addParamsLine(" requires --fourier;");
94 }
void addParamsLine(const String &line)

◆ generateMask()

void FourierFilter::generateMask ( MultidimArray< double > &  v)

Generate nD mask.

Definition at line 605 of file fourier_filter.cpp.

606 {
607  if (FilterShape==SPARSIFY)
608  return;
609 
610  if (FilterShape==FSCPROFILE)
611  {
612  MetaDataVec mdFSC(fnFSC);
613  mdFSC.getColumnValues(MDL_RESOLUTION_FREQ, freqContFSC);
614  mdFSC.getColumnValues(MDL_RESOLUTION_FRC, FSC);
615  }
616  // std::cout << "Generating mask " << do_generate_3dmask << std::endl;
617 
618  if (do_generate_3dmask)
619  {
620  transformer.setReal(v);
622  transformer.getFourierAlias(Fourier);
623 
625  {
626  maskFourier.initZeros(Fourier);
628  switch (FilterShape)
629  {
630  case WEDGE:
631  {
633  Euler_angles2matrix(rot,tilt,psi,A,false);
634  BinaryWedgeMask(maskFourier, t1, t2, A,true);
635  break;
636  }
637  case WEDGE_RC:
638  {
640  Euler_angles2matrix(rot,tilt,psi,A,false);
641  BinaryWedgeMask(maskFourier, t1, t2, A,true);
642  break;
643  }
644  case CONE:
645  BinaryConeMask(maskFourier, 90. - fabs(t1),INNER_MASK,true);
646  break;
647  }
648  }
649  else if (FilterShape==BINARYFILE)
650  {
651  Image<double> filter;
652  filter.read(fnFilter);
654  maskFourierd.resize(Fourier);
655  return;
656  }
657 
658  else
659  {
660  maskFourierd.initZeros(Fourier);
662 
663  w.resizeNoCopy(3);
664  for (size_t k=0; k<ZSIZE(Fourier); k++)
665  {
666  FFT_IDX2DIGFREQ(k,ZSIZE(v),ZZ(w));
667  for (size_t i=0; i<YSIZE(Fourier); i++)
668  {
669  FFT_IDX2DIGFREQ(i,YSIZE(v),YY(w));
670  for (size_t j=0; j<XSIZE(Fourier); j++)
671  {
672  FFT_IDX2DIGFREQ(j,XSIZE(v),XX(w));
674  }
675  }
676  }
677  }
678  }
679  else if (MULTIDIM_SIZE(v)<=1024*1024)
680  {
681  transformer.setReal(v);
683  transformer.getFourierAlias(Fourier);
684  if (FilterShape==BINARYFILE)
685  {
686  Image<double> filter;
687  filter.read(fnFilter);
689  maskFourierd.resize(Fourier);
690  return;
691  }
692  maskFourierd.initZeros(Fourier);
693  w.resizeNoCopy(3);
694  for (size_t k=0; k<ZSIZE(Fourier); k++)
695  {
696  FFT_IDX2DIGFREQ(k,ZSIZE(v),ZZ(w));
697  for (size_t i=0; i<YSIZE(Fourier); i++)
698  {
699  FFT_IDX2DIGFREQ(i,YSIZE(v),YY(w));
700  for (size_t j=0; j<XSIZE(Fourier); j++)
701  {
702  FFT_IDX2DIGFREQ(j,XSIZE(v),XX(w));
704  }
705  }
706  }
707  }
708 }
#define SPARSIFY
#define CONE
void BinaryConeMask(MultidimArray< int > &mask, double theta, int mode, bool centerOrigin)
Definition: mask.cpp:488
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
Definition: geometry.cpp:624
#define MULTIDIM_SIZE(v)
FileName fnFilter
void BinaryWedgeMask(MultidimArray< int > &mask, double theta0, double thetaF, const Matrix2D< double > &A, bool centerOrigin)
Definition: mask.cpp:524
std::vector< double > FSC
MultidimArray< double > maskFourierd
#define i
#define WEDGE
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
Matrix1D< double > w
#define BINARYFILE
#define XX(v)
Definition: matrix1d.h:85
void setReal(MultidimArray< double > &img)
Definition: xmipp_fftw.cpp:129
#define XSIZE(v)
#define ZSIZE(v)
#define DIRECT_A3D_ELEM(v, k, i, j)
double maskValue(const Matrix1D< double > &w)
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
std::vector< double > freqContFSC
#define j
Frequency in 1/A (double)
void scaleToSize(int SplineDegree, MultidimArrayGeneric &V2, const MultidimArrayGeneric &V1, int Xdim, int Ydim, int Zdim)
#define FSCPROFILE
#define YY(v)
Definition: matrix1d.h:93
#define WEDGE_RC
void getFourierAlias(T &V)
Definition: xmipp_fftw.h:207
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
MultidimArray< int > maskFourier
void initZeros(const MultidimArray< T1 > &op)
FourierTransformer transformer
#define ZZ(v)
Definition: matrix1d.h:101
Fourier shell correlation (double)
constexpr int INNER_MASK
Definition: mask.h:47

◆ init()

void FourierFilter::init ( void  )

Clear

Definition at line 32 of file fourier_filter.cpp.

33 {
36  w2 = w1 = 0;
37  raised_w = 0;
38  ctf.clear();
39  ctf.enable_CTFnoise = false;
40  do_generate_3dmask = false;
41  sampling_rate = -1.;
42 }
CTFDescription ctf
double sampling_rate
#define RAISED_COSINE
void clear()
Clear.
Definition: ctf.cpp:1366
bool enable_CTFnoise
Enable CTFnoise part.
Definition: ctf.h:273
#define LOWPASS

◆ maskPower()

double FourierFilter::maskPower ( )

Get the power of the nD mask.

Definition at line 793 of file fourier_filter.cpp.

794 {
795  if (XSIZE(maskFourier) != 0)
797  else if (XSIZE(maskFourierd) != 0)
799  else
800  return 0;
801 }
#define MULTIDIM_SIZE(v)
MultidimArray< double > maskFourierd
#define XSIZE(v)
double sum2() const
MultidimArray< int > maskFourier

◆ maskValue()

double FourierFilter::maskValue ( const Matrix1D< double > &  w)

Compute the mask value at a given frequency. The frequency must be normalized so that the maximum frequency in each direction is 0.5

Definition at line 414 of file fourier_filter.cpp.

415 {
416  double absw = w.module();
417  double wx=fabs(XX(w));
418  double wy=fabs(YY(w));
419 
420  // Generate mask
421  switch (FilterBand)
422  {
423  case LOWPASS:
424  switch (FilterShape)
425  {
426  case RAISED_COSINE:
427  if (absw<w1)
428  return 1;
429  else if (absw<w1+raised_w)
430  return (1+cos(PI/raised_w*(absw-w1)))/2;
431  else
432  return 0;
433  break;
434  case GAUSSIAN:
435  return 1./sqrt(2.*PI*w1)*exp(-0.5*absw*absw/(w1*w1));
436  break;
437  case REALGAUSSIAN:
438  return exp(-PI*PI*absw*absw*w1*w1); //? Should it be -2*
439  break;
440  case REALGAUSSIANZ:
441  return exp(-2.*PI*PI*absw*absw*w1*w1);
442  break;
443  case REALGAUSSIANZ2:
444  return (1./(4*PI*w1*w1))*exp(-PI*PI*absw*absw*w1*w1);
445  break;
446  case WEDGE_RC:
447  if (absw<w1)
448  return 1;
449  else if (absw<w1+raised_w)
450  return (1+cos(PI/raised_w*(absw-w1)))/2;
451  else
452  return 0;
453  break;
454  }
455  break;
456  case HIGHPASS:
457  switch (FilterShape)
458  {
459  case RAISED_COSINE:
460  if (absw>w1)
461  return 1;
462  else if (absw>w1-raised_w)
463  return (1+cos(PI/raised_w*(w1-absw)))/2;
464  else
465  return 0;
466  break;
467  }
468  break;
469  case BANDPASS:
470  switch (FilterShape)
471  {
472  case RAISED_COSINE:
473  if (absw>=w1 && absw<=w2)
474  return 1;
475  else if (absw>w1-raised_w && absw<w1)
476  return (1+cos(PI/raised_w*(w1-absw)))/2;
477  else if (absw<w2+raised_w && absw>w2)
478  return (1+cos(PI/raised_w*(w2-absw)))/2;
479  else
480  return 0;
481  break;
482  }
483  break;
484  case STOPBAND:
485  switch (FilterShape)
486  {
487  case RAISED_COSINE:
488  if (absw>=w1 && absw<=w2)
489  return 0;
490  else if (absw>w1-raised_w && absw<w1)
491  return 1-(1+cos(PI/raised_w*(w1-absw)))/2;
492  else if (absw<w2+raised_w && absw>w2)
493  return 1-(1+cos(PI/raised_w*(w2-absw)))/2;
494  else
495  return 1;
496  break;
497  }
498  break;
499  case STOPLOWBANDX:
500  switch (FilterShape)
501  {
502  case RAISED_COSINE:
503  if (wx<w1)
504  return 0;
505  else if (wx<w1+raised_w)
506  return (1+cos(PI/raised_w*(w1-wx)))/2;
507  else
508  return 1.0;
509  break;
510  }
511  break;
512  case STOPLOWBANDY:
513  switch (FilterShape)
514  {
515  case RAISED_COSINE:
516  if (wy<w1)
517  return 0;
518  else if (wy<w1+raised_w)
519  return (1+cos(PI/raised_w*(w1-wy)))/2;
520  else
521  return 1.0;
522  break;
523  }
524  break;
525  case CTF:
526  ctf.precomputeValues(XX(w)/ctf.Tm,YY(w)/ctf.Tm);
527  return ctf.getValueAt();
528  break;
529  case CTFPOS:
530  ctf.precomputeValues(XX(w)/ctf.Tm,YY(w)/ctf.Tm);
531  return fabs(ctf.getValueAt());
532  break;
533  case CTFINV:
534  {
535  ctf.precomputeValues(XX(w)/ctf.Tm,YY(w)/ctf.Tm);
536  double ctfval=ctf.getValueAt();
537  if (fabs(ctfval)<=minCTF)
538  return 0.0;
539  else
540  return 1.0/ctfval;
541  }
542  break;
543  case CTFPOSINV:
544  {
545  ctf.precomputeValues(XX(w)/ctf.Tm,YY(w)/ctf.Tm);
546  double ctfval=fabs(ctf.getValueAt());
547  if (ctfval<=minCTF)
548  return 0.0;
549  else
550  return 1.0/ctfval;
551  }
552  break;
553  case CTFDEF:
554  {
555  ctf.precomputeValues(XX(w)/ctf.Tm,YY(w)/ctf.Tm);
556  return ctf.getValueAt();
557  }
558  break;
559  case BFACTOR:
560  {
561  double R = absw / sampling_rate;
562  return exp( - (w1 / 4.) * R * R);
563  }
564  break;
565  case FSCPROFILE:
566  {
567  double R = absw / sampling_rate;
568  int idx=-1;
569  size_t imax=freqContFSC.size();
570  double *ptrFreq=&freqContFSC[0];
571  for (size_t i=0; i<imax; ++i)
572  if (ptrFreq[i]>R)
573  {
574  idx=(int)i;
575  break;
576  }
577  if (idx>=1)
578  {
579  double x0=freqContFSC[idx-1];
580  double x1=freqContFSC[idx];
581  double y0=FSC[idx-1];
582  double y1=FSC[idx];
583  return y0+(y1-y0)*(R-x0)/(x1-x0);
584  }
585  return 0;
586  }
587  case ASTIGMATISMPROFILE:
588  {
589  double R = absw / sampling_rate;
590  ctf.precomputeValues(R,0.0);
591  double phaseU=ctf.getPhaseAt();
592  ctf.precomputeValues(0.0,R);
593  double phaseV=ctf.getPhaseAt();
594  double diff=(phaseV-phaseU)*0.5;
595  return exp(-0.5*diff*diff/(w1*w1));
596  }
597  break;
598  default:
599  REPORT_ERROR(ERR_ARG_INCORRECT,"Unknown mask type");
600  }
601  return 0;
602 }
#define ASTIGMATISMPROFILE
double module() const
Definition: matrix1d.h:983
CTFDescription ctf
#define CTFINV
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void sqrt(Image< double > &op)
#define BANDPASS
std::vector< double > FSC
#define i
#define CTFDEF
#define STOPLOWBANDX
double sampling_rate
#define y0
#define x0
#define XX(v)
Definition: matrix1d.h:85
double getValueAt(bool show=false) const
Compute CTF at (U,V). Continuous frequencies.
Definition: ctf.h:1050
#define REALGAUSSIANZ
#define CTF
Incorrect argument received.
Definition: xmipp_error.h:113
#define BFACTOR
#define HIGHPASS
#define RAISED_COSINE
double Tm
Sampling rate (A/pixel)
Definition: ctf.h:240
#define STOPBAND
void precomputeValues(double X, double Y)
Precompute values for a given frequency.
Definition: ctf.h:1002
#define CTFPOSINV
std::vector< double > freqContFSC
#define FSCPROFILE
#define YY(v)
Definition: matrix1d.h:93
#define WEDGE_RC
#define CTFPOS
#define STOPLOWBANDY
#define REALGAUSSIAN
#define GAUSSIAN
#define PI
Definition: tools.h:43
#define REALGAUSSIANZ2
double getPhaseAt() const
Get Phase of the CTF.
Definition: ctf.h:1063
#define LOWPASS

◆ readParams()

void FourierFilter::readParams ( XmippProgram program)
virtual

Read parameters from command line. If a CTF description file is provided it is read.

Reimplemented from XmippFilter.

Definition at line 97 of file fourier_filter.cpp.

98 {
99  init();
100  if (program->checkParam("--save"))
101  maskFn = program->getParam("--save");
102  if (program->checkParam("--sampling"))
103  sampling_rate = program->getDoubleParam("--sampling");
104 
105  // Filter shape .........................................................
106  String filter_type;
107  filter_type = program->getParam("--fourier");
108 
109  // Read frequencies cuttoff options
110  if (filter_type == "low_pass")
111  {
112  w1 = program->getDoubleParam("--fourier", "low_pass");
113  raised_w = program->getDoubleParam("--fourier", "low_pass",1);
116  }
117  else if (filter_type == "high_pass")
118  {
119  w1 = program->getDoubleParam("--fourier", "high_pass");
120  raised_w = program->getDoubleParam("--fourier", "high_pass",1);
123  }
124  else if (filter_type == "band_pass")
125  {
126  w1 = program->getDoubleParam("--fourier", "band_pass");
127  w2 = program->getDoubleParam("--fourier", "band_pass", 1);
128  raised_w = program->getDoubleParam("--fourier", "band_pass",2);
131  }
132  else if (filter_type == "stop_band")
133  {
134  w1 = program->getDoubleParam("--fourier", "stop_band");
135  w2 = program->getDoubleParam("--fourier", "stop_band", 1);
136  raised_w = program->getDoubleParam("--fourier", "stop_band",2);
139  }
140  else if (filter_type == "stop_lowbandx")
141  {
142  w1 = program->getDoubleParam("--fourier", "stop_lowbandx");
143  raised_w = program->getDoubleParam("--fourier", "stop_lowbandx",1);
146  }
147  else if (filter_type == "stop_lowbandy")
148  {
149  w1 = program->getDoubleParam("--fourier", "stop_lowbandy");
150  raised_w = program->getDoubleParam("--fourier", "stop_lowbandy",1);
153  }
154  else if (filter_type == "wedge")
155  {
156  t1 = program->getDoubleParam("--fourier", "wedge", 0);
157  t2 = program->getDoubleParam("--fourier", "wedge", 1);
158  rot = program->getDoubleParam("--fourier", "wedge", 2);
159  tilt = program->getDoubleParam("--fourier", "wedge", 3);
160  psi = program->getDoubleParam("--fourier", "wedge", 4);
162  }
163  else if (filter_type == "cone")
164  {
165  t1 = program->getDoubleParam("--fourier", "cone", 0);
167  }
168  else if (filter_type == "gaussian")
169  {
170  w1 = program->getDoubleParam("--fourier", "gaussian");
173  }
174  else if (filter_type == "sparsify")
175  {
176  percentage = program->getDoubleParam("--fourier", "sparsify");
179  }
180  else if (filter_type == "real_gaussian")
181  {
182  w1 = program->getDoubleParam("--fourier", "real_gaussian");
185  }
186  else if (filter_type == "ctf" || filter_type == "ctfpos" || filter_type == "ctfinv" || filter_type == "ctfposinv")
187  {
188  FileName fnCTF;
189  if (filter_type == "ctf")
190  {
192  fnCTF=program->getParam("--fourier", "ctf");
193  }
194  else if (filter_type == "ctfpos")
195  {
197  fnCTF=program->getParam("--fourier", "ctfpos");
198  }
199  else if (filter_type == "ctfinv")
200  {
202  fnCTF=program->getParam("--fourier", "ctfinv");
203  minCTF = program->getDoubleParam("--fourier", "ctfinv", 1);
204  }
205  else if (filter_type == "ctfposinv")
206  {
208  fnCTF=program->getParam("--fourier", "ctfposinv");
209  minCTF = program->getDoubleParam("--fourier", "ctfposinv", 1);
210  }
211  ctf.enable_CTFnoise = false;
212  ctf.read(fnCTF);
213  if (sampling_rate > 0.)
214  {
215  std::cerr << "CTF was obtained at sampling rate: " << ctf.Tm << std::endl;
216  std::cerr << "Image sampling rate is: " << sampling_rate << std::endl;
218  }
220  }
221  else if (filter_type == "ctfdef")
222  {
224  ctf.clear();
225  ctf.kV = program->getDoubleParam("--fourier", "ctfdef");
226  ctf.Cs = program->getDoubleParam("--fourier", "ctfdef", 1);
227  ctf.Q0 = program->getDoubleParam("--fourier", "ctfdef", 2);
228  ctf.DeltafU = program->getDoubleParam("--fourier", "ctfdef", 3);
230  ctf.Tm = sampling_rate;
232  }
233  else if (filter_type == "ctfdefastig")
234  {
236  ctf.clear();
237  ctf.kV = program->getDoubleParam("--fourier", "ctfdefastig");
238  ctf.Cs = program->getDoubleParam("--fourier", "ctfdefastig", 1);
239  ctf.Q0 = program->getDoubleParam("--fourier", "ctfdefastig", 2);
240  ctf.DeltafU = program->getDoubleParam("--fourier", "ctfdefastig", 3);
241  ctf.DeltafV = program->getDoubleParam("--fourier", "ctfdefastig", 4);
242  ctf.azimuthal_angle = program->getDoubleParam("--fourier", "ctfdefastig", 5);
243  ctf.Tm = sampling_rate;
245  }
246  else if (filter_type == "bfactor")
247  {
249  w1 = program->getDoubleParam("--fourier", "bfactor");
250  }
251  else if (filter_type == "fsc")
252  {
254  fnFSC = program->getParam("--fourier", "fsc");
255  }
256  else if (filter_type == "binary_file")
257  {
259  fnFilter = program->getParam("--fourier", "binary_file");
260  }
261  else if (filter_type == "astigmatism")
262  {
264  w1 = program->getDoubleParam("--fourier", 1);
265  w1 = DEG2RAD(w1);
266  }
267  else
268  REPORT_ERROR(ERR_DEBUG_IMPOSIBLE, "This couldn't happen, check argument parser or params definition");
269 
271  {
272  if (w1 != 0)
273  w1 = sampling_rate / w1;
274  if (w2 != 0)
275  w2 = sampling_rate / w2;
276  }
277 }
#define SPARSIFY
#define ASTIGMATISMPROFILE
#define CONE
double getDoubleParam(const char *param, int arg=0)
CTFDescription ctf
#define CTFINV
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define DEG2RAD(d)
Definition: xmipp_macros.h:312
FileName fnFilter
Just for debugging, situation that can&#39;t happens.
Definition: xmipp_error.h:120
#define BANDPASS
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
Definition: ctf.h:830
#define WEDGE
void read(const FileName &fn, bool disable_if_not_K=true)
Definition: ctf.cpp:1220
#define CTFDEF
#define STOPLOWBANDX
double DeltafU
Global gain. By default, 1.
Definition: ctf.h:828
double azimuthal_angle
Azimuthal angle (between X and U) in degrees.
Definition: ctf.h:832
double sampling_rate
#define BINARYFILE
const char * getParam(const char *param, int arg=0)
#define CTF
#define BFACTOR
#define HIGHPASS
#define RAISED_COSINE
double Tm
Sampling rate (A/pixel)
Definition: ctf.h:240
#define STOPBAND
#define CTFPOSINV
double Cs
Spherical aberration (in milimeters). Typical value 5.6.
Definition: ctf.h:246
#define FSCPROFILE
#define CTFPOS
#define STOPLOWBANDY
std::string String
Definition: xmipp_strings.h:34
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
bool checkParam(const char *param)
double Q0
Factor for the importance of the Amplitude contrast.
Definition: ctf.h:261
void clear()
Clear.
Definition: ctf.cpp:1366
#define REALGAUSSIAN
double kV
Accelerating Voltage (in KiloVolts)
Definition: ctf.h:242
bool enable_CTFnoise
Enable CTFnoise part.
Definition: ctf.h:273
#define GAUSSIAN
#define LOWPASS

◆ show()

void FourierFilter::show ( )
virtual

Show.

Reimplemented from XmippFilter.

Definition at line 280 of file fourier_filter.cpp.

281 {
282  {
283  std::cout << "Filter Band: ";
284  switch (FilterBand)
285  {
286  case LOWPASS:
287  std::cout << "Lowpass before " << w1 << std::endl;
288  break;
289  case HIGHPASS:
290  std::cout << "Highpass after " << w1 << std::endl;
291  break;
292  case BANDPASS:
293  std::cout << "Bandpass between " << w1 << " and " << w2 << std::endl;
294  break;
295  case STOPBAND:
296  std::cout << "Stopband between " << w1 << " and " << w2 << std::endl;
297  break;
298  case STOPLOWBANDX:
299  std::cout << "Stop low band X up to " << w1 << std::endl;
300  break;
301  case STOPLOWBANDY:
302  std::cout << "Stop low band Y up to " << w1 << std::endl;
303  break;
304  case CTF:
305  std::cout << "CTF\n";
306  break;
307  case CTFPOS:
308  std::cout << "CTFPOS\n";
309  break;
310  case CTFINV:
311  std::cout << "CTFINV minCTF= " << minCTF << "\n";
312  break;
313  case CTFPOSINV:
314  std::cout << "CTFPOSINV minCTF= " << minCTF << "\n";
315  break;
316  case CTFDEF:
317  std::cout << "CTFDEF voltage= " << ctf.kV << "\n";
318  std::cout << "CTFDEF Cs= " << ctf.Cs << "\n";
319  std::cout << "CTFDEF Q0= " << ctf.Q0 << "\n";
320  std::cout << "CTFDEF defocus= " << ctf.DeltafU << "\n";
321  break;
322  case BFACTOR:
323  std::cout << "Bfactor "<< w1 << std::endl
324  << "Sampling rate " << sampling_rate << std::endl;
325  break;
326  case WEDGE:
327  std::cout << "Missing wedge keep data between tilting angles of " << t1 << " and " << t2 << " deg\n";
328  break;
329  case CONE:
330  std::cout << "Missing cone for RCT data with tilting angles up to " << t1 << " deg\n";
331  break;
332  case FSCPROFILE:
333  std::cout << "FSC file " << fnFSC << std::endl
334  << "Sampling rate " << sampling_rate << std::endl;
335  break;
336  case BINARYFILE:
337  std::cout << "Filter file " << fnFilter << std::endl;
338  break;
339  case ASTIGMATISMPROFILE:
340  std::cout << "Astigmatism sigma " << RAD2DEG(w1) << std::endl;
341  break;
342  }
344  std::cout << "Filter Shape: ";
345  switch (FilterShape)
346  {
347  case RAISED_COSINE:
348  std::cout << "Raised cosine with " << raised_w
349  << " raised frequencies\n";
350  break;
351  case GAUSSIAN:
352  std::cout << "Gaussian\n";
353  break;
354  case SPARSIFY:
355  std::cout << "Sparsify\n";
356  break;
357  case REALGAUSSIAN:
358  std::cout << "Real Gaussian\n";
359  break;
360  case CTF:
361  std::cout << "CTF\n" << ctf;
362  break;
363  case CTFPOS:
364  std::cout << "CTFPOS\n" << ctf;
365  break;
366  case CTFINV:
367  std::cout << "CTFINV\n" << ctf;
368  break;
369  case CTFPOSINV:
370  std::cout << "CTFPOSINV\n" << ctf;
371  break;
372  }
373  if (maskFn != "")
374  std::cout << "Save mask in file: " << maskFn
375  << " disable actual masking"<< std::endl;
376  }
377 }
#define SPARSIFY
#define ASTIGMATISMPROFILE
#define CONE
CTFDescription ctf
#define CTFINV
FileName fnFilter
#define BANDPASS
#define WEDGE
#define CTFDEF
#define STOPLOWBANDX
double DeltafU
Global gain. By default, 1.
Definition: ctf.h:828
double sampling_rate
#define BINARYFILE
#define CTF
#define BFACTOR
#define HIGHPASS
#define RAISED_COSINE
#define STOPBAND
#define CTFPOSINV
double Cs
Spherical aberration (in milimeters). Typical value 5.6.
Definition: ctf.h:246
#define FSCPROFILE
#define CTFPOS
#define RAD2DEG(r)
Definition: xmipp_macros.h:320
#define STOPLOWBANDY
double Q0
Factor for the importance of the Amplitude contrast.
Definition: ctf.h:261
#define REALGAUSSIAN
double kV
Accelerating Voltage (in KiloVolts)
Definition: ctf.h:242
#define GAUSSIAN
#define LOWPASS

Member Data Documentation

◆ ctf

CTFDescription FourierFilter::ctf

CTF parameters.

Definition at line 134 of file fourier_filter.h.

◆ do_generate_3dmask

bool FourierFilter::do_generate_3dmask

Flag to generate 3D mask

Definition at line 146 of file fourier_filter.h.

◆ FilterBand

int FourierFilter::FilterBand

Pass band. LOWPASS, HIGHPASS, BANDPASS, STOPBAND, CTF, CTFPOS, WEDGE, CONE, GAUSSIAN, FROM_FILE, REALGAUSSIAN, BFACTOR, SPARSIFY, STOPLOWBANDX, STOPLOWBANDY, FSCPROFILE, BINARYFILE, ASTIGMATISMPROFILE, CTFINV, CTFPOSINV, CTFDEF

Definition at line 105 of file fourier_filter.h.

◆ FilterShape

int FourierFilter::FilterShape

Shape of the decay in the filter. Valid types are RAISED_COSINE.

Definition at line 75 of file fourier_filter.h.

◆ fnFilter

FileName FourierFilter::fnFilter

Binary file with the filter

Definition at line 143 of file fourier_filter.h.

◆ fnFSC

FileName FourierFilter::fnFSC

FSC file

Definition at line 140 of file fourier_filter.h.

◆ freqContFSC

std::vector<double> FourierFilter::freqContFSC

Definition at line 207 of file fourier_filter.h.

◆ FSC

std::vector<double> FourierFilter::FSC

Definition at line 208 of file fourier_filter.h.

◆ maskFn

FileName FourierFilter::maskFn

Filename in which store the mask (valid only for fourier masks)

Definition at line 128 of file fourier_filter.h.

◆ maskFourier

MultidimArray<int> FourierFilter::maskFourier

Definition at line 194 of file fourier_filter.h.

◆ maskFourierd

MultidimArray<double> FourierFilter::maskFourierd

Definition at line 197 of file fourier_filter.h.

◆ minCTF

double FourierFilter::minCTF

Minimum CTF for inversion

Definition at line 137 of file fourier_filter.h.

◆ percentage

double FourierFilter::percentage

Percentage of coefficients to throw

Definition at line 125 of file fourier_filter.h.

◆ psi

double FourierFilter::psi

Definition at line 122 of file fourier_filter.h.

◆ raised_w

double FourierFilter::raised_w

Pixels around the central frequency for the raised cosine

Definition at line 131 of file fourier_filter.h.

◆ rot

double FourierFilter::rot

Definition at line 120 of file fourier_filter.h.

◆ sampling_rate

double FourierFilter::sampling_rate

Input Image sampling rate

Definition at line 115 of file fourier_filter.h.

◆ t1

double FourierFilter::t1

Wedge and cone filter parameters

Definition at line 118 of file fourier_filter.h.

◆ t2

double FourierFilter::t2

Definition at line 119 of file fourier_filter.h.

◆ tilt

double FourierFilter::tilt

Definition at line 121 of file fourier_filter.h.

◆ transformer

FourierTransformer FourierFilter::transformer

Definition at line 200 of file fourier_filter.h.

◆ vMag

MultidimArray<double> FourierFilter::vMag

Definition at line 203 of file fourier_filter.h.

◆ vMagSorted

MultidimArray<double> FourierFilter::vMagSorted

Definition at line 204 of file fourier_filter.h.

◆ w

Matrix1D<double> FourierFilter::w

Definition at line 191 of file fourier_filter.h.

◆ w1

double FourierFilter::w1

Cut frequency for Low and High pass filters, first freq for bandpass. Normalized to 1/2

Definition at line 109 of file fourier_filter.h.

◆ w2

double FourierFilter::w2

Second frequency for bandpass and stopband. Normalized to 1/2

Definition at line 112 of file fourier_filter.h.


The documentation for this class was generated from the following files: