Xmipp  v3.23.11-Nereus
ctf_phase_flip.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Roberto Marabini (roberto@cnb.csic.es)
4  * Carlos Oscar S. Sorzano (coss@cnb.csic.es)
5  *
6  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21  * 02111-1307 USA
22  *
23  * All comments concerning this program package may be sent to the
24  * e-mail address 'xmipp@cnb.csic.es'
25  ***************************************************************************/
26 
27 #include "ctf_phase_flip.h"
28 
30 {
31  addUsageLine("Correct the phase of micrographs");
32  addUsageLine("+This program flips the phase of those frequencies that were already ");
33  addUsageLine("+flipped by the CTF. Flipping the phase at the level of the micrograph is recommended.");
34  addParamsLine(" -i <file> : Input micrograph");
35  addParamsLine(" -o <file> : Output micrograph");
36  addParamsLine(" --ctf <ctfparam_file> : CTF description");
37  addParamsLine(" [--sampling <T=-1>] : Sampling rate of the input micrograph.");
38  addParamsLine(" : If not given, then it is assumed to be the sampling rate in the ctfparam times the downsampling.");
39  addParamsLine(" [--downsampling <D=1>] : Downsampling factor of the input micrograph with respect to the original");
40  addParamsLine(" : micrograph.");
41 }
42 
44 {
45  fn_in = getParam("-i");
46  fn_out = getParam("-o");
47  fnt_ctf = getParam("--ctf");
48  downsampling = getDoubleParam("--downsampling");
49  Tm = getDoubleParam("--sampling");
50 }
51 
53 {
54  if (verbose==0)
55  return;
56  std::cout
57  << "input_micrograph: " << fn_in << std::endl
58  << "output_micrograph: " << fn_out << std::endl
59  << "ctf_param_file: " << fnt_ctf << std::endl
60  << "sampling: " << Tm << std::endl
61  << "downsampling: " << downsampling << std::endl
62  ;
63 }
64 
66 {
67  show();
68 
69  // Read the micrograph in an array of doubles
71  M_in.read(fn_in);
72 
73  // Read CTF
74  CTFDescription ctf;
75  ctf.clear();
76  ctf.read(fnt_ctf);
77  if (Tm<0)
79  else
81  ctf.produceSideInfo();
82 
83  actualPhaseFlip(M_in(),ctf);
84 
85  M_in.write(fn_out);
86 }
87 
89 {
90  // Perform the Fourier transform
91  FourierTransformer transformer;
93  transformer.FourierTransform(I,M_inFourier,false);
94 
95  Matrix1D<double> freq(2); // Frequencies for Fourier plane
96  int yDim=YSIZE(I);
97  int xDim=XSIZE(I);
98  double iTm=1.0/ctf.Tm;
99  ctf.phase_shift = (ctf.phase_shift*PI)/180;
100 
101  for (size_t i=0; i<YSIZE(M_inFourier); ++i)
102  {
103  FFT_IDX2DIGFREQ(i, yDim, YY(freq));
104  YY(freq) *= iTm;
105  for (size_t j=0; j<XSIZE(M_inFourier); ++j)
106  {
107  FFT_IDX2DIGFREQ(j, xDim, XX(freq));
108  XX(freq) *= iTm;
109  ctf.precomputeValues(XX(freq),YY(freq));
110  if (ctf.getValuePureWithoutDampingAt()<0)
111  DIRECT_A2D_ELEM(M_inFourier,i,j)*=-1;
112  }
113  }
114 
115  // Perform inverse Fourier transform and finish
116  transformer.inverseFourierTransform();
117 }
#define YSIZE(v)
#define yDim
Definition: projection.cpp:42
double getDoubleParam(const char *param, int arg=0)
void inverseFourierTransform()
Definition: xmipp_fftw.cpp:329
#define xDim
Definition: projection.cpp:41
#define DIRECT_A2D_ELEM(v, i, j)
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)
void changeSamplingRate(double newTm)
Definition: ctf.h:994
double phase_shift
Definition: ctf.h:305
#define i
void read(const FileName &fn, bool disable_if_not_K=true)
Definition: ctf.cpp:1220
const char * getParam(const char *param, int arg=0)
#define XX(v)
Definition: matrix1d.h:85
#define XSIZE(v)
double Tm
Sampling rate (A/pixel)
Definition: ctf.h:240
void precomputeValues(double X, double Y)
Precompute values for a given frequency.
Definition: ctf.h:1002
int verbose
Verbosity level.
double getValuePureWithoutDampingAt(bool show=false) const
Compute pure CTF without damping at (U,V). Continuous frequencies.
Definition: ctf.h:542
void FourierTransform(T &v, T1 &V, bool getCopy=true)
Definition: xmipp_fftw.h:166
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
#define j
#define YY(v)
Definition: matrix1d.h:93
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void actualPhaseFlip(MultidimArray< double > &I, CTFDescription ctf)
void clear()
Clear.
Definition: ctf.cpp:1366
void addUsageLine(const char *line, bool verbatim=false)
#define PI
Definition: tools.h:43
void addParamsLine(const String &line)