Xmipp  v3.23.11-Nereus
Classes | Functions
angular_continuous_assign (Continuous angular assignment)
Collaboration diagram for angular_continuous_assign (Continuous angular assignment):

Classes

class  ProgAngularContinuousAssign
 
struct  cstregistrationStruct
 

Functions

double CSTSplineAssignment (MultidimArray< double > &ReDFTVolume, MultidimArray< double > &ImDFTVolume, MultidimArray< double > &image, MultidimArray< double > &weight, Matrix1D< double > &pose_parameters, int max_no_iter=60)
 

Detailed Description

Function Documentation

◆ CSTSplineAssignment()

double CSTSplineAssignment ( MultidimArray< double > &  ReDFTVolume,
MultidimArray< double > &  ImDFTVolume,
MultidimArray< double > &  image,
MultidimArray< double > &  weight,
Matrix1D< double > &  pose_parameters,
int  max_no_iter = 60 
)

Assign pose parameters for 1 image. The weight must be an image of the size of the input image with the appropriate weighting in frequency (normally a gaussian). The pose parameters at the input must have the initial guess of the pose. At the output they contain the parameters estimated by CST Spline Assignment. The maximum number of iterations controls the optimization process.

Definition at line 256 of file angular_continuous_assign.cpp.

264 {
265  // Build the parameter structure .........................................
267 
268  // Set the Volume input
269  Data.ReDftVolume = MULTIDIM_ARRAY(ReDFTVolume);
270  Data.nx_ReDftVolume = XSIZE(ReDFTVolume);
271  Data.ny_ReDftVolume = YSIZE(ReDFTVolume);
272  Data.nz_ReDftVolume = ZSIZE(ReDFTVolume);
273 
274  Data.ImDftVolume = MULTIDIM_ARRAY(ImDFTVolume);
275  Data.nx_ImDftVolume = XSIZE(ImDFTVolume);
276  Data.ny_ImDftVolume = YSIZE(ImDFTVolume);
277  Data.nz_ImDftVolume = ZSIZE(ImDFTVolume);
278 
279  // Perform the DFT of the input image
280  int Status;
281  MultidimArray<double> realImg(image), imagImg;
282  CenterFFT(realImg, false);
283  imagImg.resize(image);
285  MULTIDIM_ARRAY(imagImg), XSIZE(image), YSIZE(image), 1, &Status);
286  CenterFFT(realImg, true);
287  CenterFFT(imagImg, true);
288 
289  // Set the Image input
290  Data.ReDftImage = MULTIDIM_ARRAY(realImg);
291  Data.nx_ReDftImage = XSIZE(realImg);
292  Data.ny_ReDftImage = YSIZE(realImg);
293 
294  Data.ImDftImage = MULTIDIM_ARRAY(imagImg);
295  Data.nx_ImDftImage = XSIZE(imagImg);
296  Data.ny_ImDftImage = YSIZE(imagImg);
297 
298  // Set the weight input
299  Data.Weight = MULTIDIM_ARRAY(weight);
300  Data.nx_Weight = XSIZE(weight);
301  Data.ny_Weight = YSIZE(weight);
302 
303  // Set the sampling rates
304  Matrix1D<double> sampling_rate(3);
305  sampling_rate.initConstant(1);
306  Data.VoxelSize = MATRIX1D_ARRAY(sampling_rate);
307  Data.nx_VoxelSize = 3;
308  Data.PixelSize = MATRIX1D_ARRAY(sampling_rate);
309  Data.nx_PixelSize = 2;
310 
311  // Set the initial pose parameters
312  Data.Parameters = MATRIX1D_ARRAY(pose_parameters);
313  Data.nx_Parameters = 5;
314 
315  // Set the final pose parameters.
316  Matrix2D<double> output_pose(5, max_no_iter + 1);
317  Data.OutputParameters = MATRIX2D_ARRAY(output_pose);
318  Data.nx_OutputParameters = max_no_iter + 1;
319  Data.ny_OutputParameters = 5;
320 
321  // Set performance parameters
322  Matrix1D<double> Cost, TimePerIter, Failures;
323  Cost.initZeros(max_no_iter + 1);
324  TimePerIter.initZeros(max_no_iter + 1);
325  Failures.initZeros(max_no_iter + 1);
326  long NumberIterPerformed, NumberSuccPerformed,
327  NumberFailPerformed;
328  Data.Cost = MATRIX1D_ARRAY(Cost);
329  Data.nx_Cost = max_no_iter + 1;
330  Data.TimePerIter = MATRIX1D_ARRAY(TimePerIter);
331  Data.nx_TimePerIter = max_no_iter + 1;
332  Data.NumberIterPerformed = &NumberIterPerformed;
333  Data.NumberSuccPerformed = &NumberSuccPerformed;
334  Data.NumberFailPerformed = &NumberFailPerformed;
335  Data.Failures = MATRIX1D_ARRAY(Failures);
336  Data.nx_Failures = max_no_iter + 1;
337 
338  // Set the parameters for the extracted central slice
339  MultidimArray<double> dftProj(2, YSIZE(image), XSIZE(image));
340  Data.dftProj = MULTIDIM_ARRAY(dftProj);
341  Data.nx_dftProj = XSIZE(image);
342  Data.ny_dftProj = YSIZE(image);
343  Data.nz_dftProj = 2;
344 
345  // Set the optimizer parameters
346  Data.ScaleLambda = 2;
347  Data.LambdaInitial = 1000;
348  Data.MaxNoIter = max_no_iter;
349  Data.MaxNoFailure = (long)(0.3 * max_no_iter);
350  Data.SatisfNoSuccess = (long)(0.7 * max_no_iter);
351  ;
352  Data.MakeDesiredProj = 0;
353  Data.ToleranceAngle = 0.0;
354  Data.ToleranceShift = 0.0;
355 
356  // Call Slavica's routine ...............................................
357  Status = cstregistration(&Data);
358 
359  // Retrieve results .....................................................
360  // Skip last iterations if they are failures
361  double retval;
362  if (Status != ERROR)
363  {
364  long last_iteration_performed = *(Data.NumberIterPerformed) + 1;
365  while (Failures(last_iteration_performed - 1) > 0.0)
366  last_iteration_performed--;
367 
368  // Get the pose parameters
369  pose_parameters(0) = RAD2DEG(output_pose(0, last_iteration_performed - 1));
370  pose_parameters(1) = RAD2DEG(output_pose(1, last_iteration_performed - 1));
371  pose_parameters(2) = RAD2DEG(output_pose(2, last_iteration_performed - 1));
372  pose_parameters(3) = output_pose(3, last_iteration_performed - 1);
373  pose_parameters(4) = output_pose(4, last_iteration_performed - 1);
374 
375  // Get the cost
376  retval = Cost(last_iteration_performed - 1);
377  }
378  else
379  {
380  retval = -1;
381  std::cout << "There is a problem with one image, angles not assigned\n";
382  }
383 
384  // Return
385  return retval;
386 }
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define MULTIDIM_ARRAY(v)
void CenterFFT(MultidimArray< T > &v, bool forward)
Definition: xmipp_fft.h:291
int VolumeDftRealToRealImaginary(double *Re2Re, double *ImOut, long Nx, long Ny, long Nz, int *Status)
#define ERROR
Definition: configs.h:24
#define XSIZE(v)
#define ZSIZE(v)
void initZeros()
Definition: matrix1d.h:592
#define MATRIX1D_ARRAY(v)
Definition: matrix1d.h:58
#define RAD2DEG(r)
Definition: xmipp_macros.h:320
int cstregistration(struct cstregistrationStruct *Data)
#define MATRIX2D_ARRAY(m)
Definition: matrix2d.h:89