Xmipp  v3.23.11-Nereus
movie_alignment_correlation_base.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sanchez Sorzano coss@cnb.csic.es
4  * David Strelak (davidstrelak@gmail.com)
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 
38 #ifndef _PROG_MOVIE_ALIGNMENT_CORRELATION_BASE
39 #define _PROG_MOVIE_ALIGNMENT_CORRELATION_BASE
40 
41 #include "data/alignment_result.h"
43 #include "core/xmipp_program.h"
45 #include "core/xmipp_fftw.h"
46 #include "core/optional.h"
47 #include "eq_system_solver.h"
48 #include "bspline_helper.h"
49 #include "data/point2D.h"
50 #include <optional>
51 
55 template<typename T>
57 public:
59  virtual void readParams();
60 
62  virtual void show();
63 
65  virtual void defineParams();
66 
68  void run();
69 
70 protected:
75 
80 
92  Matrix1D<T> &bX, Matrix1D<T> &bY, Matrix2D<T> &A,
93  const core::optional<size_t> &refFrame, size_t N, int verbose);
94 
103  int findReferenceImage(size_t N, const Matrix1D<T>& shiftX,
104  const Matrix1D<T>& shiftY);
105 
116  void computeTotalShift(int iref, int j, const Matrix1D<T> &shiftX,
117  const Matrix1D<T> &shiftY, T &totalShiftX, T &totalShiftY);
118 
125  MultidimArray<T> createLPF(T Ts, const Dimensions &dims);
126 
136  void loadFrame(const MetaData &movie, const Image<T> &dark,
137  const Image<T> &igain, size_t objId,
138  Image<T> &out) const;
139 
152  virtual void applyShiftsComputeAverage(const MetaData& movie,
153  const Image<T>& dark, const Image<T>& igain, Image<T>& initialMic,
154  size_t& Ninitial, Image<T>& averageMicrograph, size_t& N,
155  const AlignmentResult<T> &globAlignment) = 0;
156 
169  virtual void applyShiftsComputeAverage(
170  const MetaData& movie, const Image<T>& dark, const Image<T>& igain,
171  Image<T>& initialMic, size_t& Ninitial, Image<T>& averageMicrograph,
172  size_t& N, const LocalAlignmentResult<T> &alignment) = 0;
173 
182  const Image<T> &dark, const Image<T> &igain) = 0;
183 
192  const Image<T> &dark, const Image<T> &igain,
193  const AlignmentResult<T> &globAlignment) = 0;
194 
198  virtual void releaseAll() = 0;
199 
203  void storeResults(const LocalAlignmentResult<T> &alignment);
204 
209  float getPixelResolution(float scaleFactor) const;
210 
214  float getScaleFactor() const;
215 
217  std::pair<size_t, size_t> getRequestedPatchSize() const {
218  return {minLocalRes / Ts, minLocalRes / Ts};
219  }
220 
221 
223  auto getBinning() const {
224  return binning;
225  }
226 
227  bool applyBinning() const {
228  return binning != 1.0;
229  }
230 
231 private:
232  void setNoOfPatches();
233 
238  void checkSettings();
239 
245  void createLPF(T Ts, MultidimArray<T> &filter);
246 
255  void scaleLPF(const MultidimArray<T>& lpf, const Dimensions &dims, MultidimArray<T>& result);
256 
262  void storeGlobalShifts(const AlignmentResult<T> &alignment,
263  MetaData &movie);
264 
269  void loadDarkCorrection(Image<T>& dark);
270 
275  void loadGainCorrection(Image<T>& igain);
276 
281  void readMovie(MetaData& movie);
282 
292  void storeResults(Image<T>& initialMic, size_t Ninitial,
293  Image<T>& averageMicrograph, size_t N, const MetaData& movie,
294  int bestIref);
295 
300  void correctLoopIndices(const MetaData& movie);
301 
306  void printGlobalShift(const AlignmentResult<T> &globAlignment);
307 
309  float getTsPrime() const;
310 
312  float getC() const;
313 
314 protected:
316  int nfirst, nlast;
318  float maxShift;
328  std::pair<size_t, size_t> localAlignPatches;
332  static constexpr int solverIterations = 2;
333 
334 private:
336  bool skipLocalAlignment;
338  FileName fnOut;
340  FileName fnMovie;
342  size_t minLocalRes;
344  float maxResForCorrelation; //
346  float Ts;
348  FileName fnDark, fnGain;
350  float binning;
352  std::optional<Dimensions> movieSizeRaw;
354  std::optional<Dimensions> movieSize;
355 };
357 #endif
int findReferenceImage(size_t N, const Matrix1D< T > &shiftX, const Matrix1D< T > &shiftY)
virtual LocalAlignmentResult< T > computeLocalAlignment(const MetaData &movie, const Image< T > &dark, const Image< T > &igain, const AlignmentResult< T > &globAlignment)=0
AlignmentResult< T > computeAlignment(Matrix1D< T > &bX, Matrix1D< T > &bY, Matrix2D< T > &A, const core::optional< size_t > &refFrame, size_t N, int verbose)
void computeTotalShift(int iref, int j, const Matrix1D< T > &shiftX, const Matrix1D< T > &shiftY, T &totalShiftX, T &totalShiftY)
void loadFrame(const MetaData &movie, const Image< T > &dark, const Image< T > &igain, size_t objId, Image< T > &out) const
void storeResults(const LocalAlignmentResult< T > &alignment)
Definition: mask.h:36
float getPixelResolution(float scaleFactor) const
MultidimArray< T > createLPF(T Ts, const Dimensions &dims)
std::pair< size_t, size_t > getRequestedPatchSize() const
virtual AlignmentResult< T > computeGlobalAlignment(const MetaData &movie, const Image< T > &dark, const Image< T > &igain)=0
int verbose
Verbosity level.
#define j
virtual void applyShiftsComputeAverage(const MetaData &movie, const Image< T > &dark, const Image< T > &igain, Image< T > &initialMic, size_t &Ninitial, Image< T > &averageMicrograph, size_t &N, const AlignmentResult< T > &globAlignment)=0
virtual void defineParams()
Define parameters.
Definition: ctf.h:38
virtual void readParams()
Read argument from command line.