Xmipp  v3.23.11-Nereus
forward_zernike_images.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sanchez Sorzano (coss@cnb.csic.es)
4  * David Herreros Calero (dherreros@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 #ifndef _PROG_FORWARD_ZERNIKE_IMAGES
28 #define _PROG_FORWARD_ZERNIKE_IMAGES
29 
31 #include "core/rerunable_program.h"
32 #include "core/matrix1d.h"
33 #include <data/blobs.h>
34 #include "core/xmipp_image.h"
35 #include "data/fourier_filter.h"
37 
41 
44 {
45 public:
53  int L1, L2;
57  double maxShift;
61  double maxResol;
63  double Ts;
65  int Rmax;
66  // Optimize alignment
68  //Optimize deformation
70  //Optimize defocus
72  // Ignore CTF
73  bool ignoreCTF;
74  //Radius optimization
76  // Phase Flipped
78  // Regularization weight
79  double lambda;
80  // Maximum radius for the deformation
81  int RmaxDef;
82  // Number of images (execution mode) (single image == 1, pair == 2, or triplet == 3)
84  // Number alignment parameters to minimize
86  // Number CTF parameters to minimize
91  bool useCTF;
92 
93 public:
95  bool resume;
96  // 2D and 3D masks in real space
98  // Volume size
99  size_t Xdim;
100  // Images Filename
101  std::vector<FileName> fnImage;
102  // Input image
104  std::vector<Image<double>> I;
105  std::vector<Image<double>> Ifiltered;
106  std::vector<Image<double>> Ifilteredp;
107  // Theoretical projections
108  std::vector<Image<double>> P;
109  // Filter
111  // Transformation matrix
113  // Original angles
114  std::vector<double> old_rot, old_tilt, old_psi, deltaRot, deltaTilt, deltaPsi;
115  // Original shift
116  std::vector<double> old_shiftX, old_shiftY, deltaX, deltaY;
117  // Original flip
118  bool old_flip;
119  // CTF Check
120  bool hasCTF;
121  // Original defocus
123  // Current defoci
125  // CTF filter
129  // Vector Size
130  int vecSize;
131  // Vector containing the degree of the spherical harmonics
133  //Copy of Optimizer steps
135  //Total Deformation, sumV, sumVd
137  int sumV;
138  // Show optimization
140  // Correlation
141  double correlation;
142  // Loop step
144  // Blob
145  struct blobtype blob;
146  double blob_r;
147 
148  // Deformation field and positions
150  std::vector<size_t> idx_z_clnm;
151  std::vector<double> z_clnm_diff;
153 
154 public:
155  enum class Direction { ROTATE, UNROTATE };
156 
159 
162 
164  void readParams();
165 
167  void show();
168 
170  void defineParams();
171 
174  void preProcess();
175 
179  void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut);
180 
182  void numCoefficients(int l1, int l2, int &vecSize);
183 
185  // void minimizepos(Matrix1D<double> &vectpos);
186  void minimizepos(int L1, int l2, Matrix1D<double> &steps);
187 
189  void fillVectorTerms(int l1, int l2, Matrix1D<int> &vL1, Matrix1D<int> &vN,
190  Matrix1D<int> &vL2, Matrix1D<int> &vM);
191 
193  void deformVol(MultidimArray<double> &mVD, const MultidimArray<double> &mV, double &def,
194  double rot, double tilt, double psi);
195 
196  void updateCTFImage(double defocusU, double defocusV, double angle);
197 
198  double transformImageSph(double *pclnm);
199 
200  template<Direction DIRECTION>
201  void rotateCoefficients();
202 
203  //AJ new
205  virtual void finishProcessing();
206 
208  virtual void writeImageParameters(MDRow &row);
209  //END AJ
210 
211  virtual void checkPoint();
212 
213  // void removePixels();
214 
215  Matrix1D<double> weightsInterpolation3D(double x, double y, double z);
216 
217  void splattingAtPos(std::array<double, 3> r, double weight, MultidimArray<double> &mP, const MultidimArray<double> &mV);
218 
219  double bspline1(double x);
220 
221  double bspline3(double x);
222 
223  void removePixels();
224 
225  void rotatePositions(double rot, double tilt, double psi);
226 
227  void preComputeDF();
228 
229 protected:
231 
232 private:
233  std::vector<MDLabel> getLabelsForEmpty() override
234  {
235  std::vector<MDLabel> labels = getInputMd()->getActiveLabels();
236  labels.push_back(MDL_SPH_DEFORMATION);
237  labels.push_back(MDL_SPH_COEFFICIENTS);
238  labels.push_back(MDL_COST);
239  return labels;
240  }
241 };
243 #endif
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
std::vector< Image< double > > Ifiltered
void minimizepos(int L1, int l2, Matrix1D< double > &steps)
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
std::vector< FileName > fnImage
std::vector< double > old_shiftY
std::vector< double > old_psi
std::vector< double > old_tilt
void rotatePositions(double rot, double tilt, double psi)
FileName fnOutDir
Output directory.
std::vector< double > old_defocusV
std::vector< double > deltaPsi
static double * y
std::vector< Image< double > > I
std::vector< double > deltaTilt
~ProgForwardZernikeImages()
Destructor.
std::vector< double > old_defocusU
Matrix1D< double > weightsInterpolation3D(double x, double y, double z)
std::vector< Image< double > > Ifilteredp
std::vector< double > deltaDefocusAngle
std::vector< double > deltaDefocusU
ProgForwardZernikeImages()
Empty constructor.
void updateCTFImage(double defocusU, double defocusV, double angle)
std::vector< double > deltaX
virtual void writeImageParameters(MDRow &row)
doublereal * x
std::vector< double > deltaY
void deformVol(MultidimArray< double > &mVD, const MultidimArray< double > &mV, double &def, double rot, double tilt, double psi)
Deform a volumen using Zernike-Spherical harmonic basis.
std::vector< Image< double > > P
virtual void createWorkFiles(bool resume, MetaData *md)
std::vector< double > currentAngle
Deformation in voxels.
Cost for the image (double)
void defineParams()
Define parameters.
std::vector< double > old_rot
std::vector< double > old_defocusAngle
MultidimArray< double > vpos
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
double z
std::vector< double > z_clnm_diff
double steps
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
std::vector< double > old_shiftX
void readParams()
Read argument from command line.
double psi(const double x)
Deformation coefficients.
void splattingAtPos(std::array< double, 3 > r, double weight, MultidimArray< double > &mP, const MultidimArray< double > &mV)
std::vector< size_t > idx_z_clnm
virtual std::vector< MDLabel > getActiveLabels() const =0
virtual void checkPoint()
For very long programs, it may be needed to write checkpoints.
std::vector< double > currentDefocusU
std::vector< double > deltaDefocusV
double transformImageSph(double *pclnm)
MultidimArray< double > df
std::vector< double > currentDefocusV
std::vector< double > deltaRot