Xmipp  v3.23.11-Nereus
Functions
refinement (Shift refinement)
Collaboration diagram for refinement (Shift refinement):

Functions

void calculate_and_find_correlation_max_proj (Projection const &proj1, Projection const &proj2, Projection &proj_tmp, double &shift_X, double &shift_Y, double const max_step, int ref_trans_after, int act_proj, CorrelationAux &aux)
 
template<class T >
void calculate_and_find_correlation_max_mat (MultidimArray< T > const &mat1, MultidimArray< T > const &mat2, MultidimArray< T > &mat_temp, double &shift_X, double &shift_Y, double const max_step, CorrelationAux &aux)
 

Detailed Description

Function Documentation

◆ calculate_and_find_correlation_max_mat()

template<class T >
void calculate_and_find_correlation_max_mat ( MultidimArray< T > const &  mat1,
MultidimArray< T > const &  mat2,
MultidimArray< T > &  mat_temp,
double &  shift_X,
double &  shift_Y,
double const  max_step,
CorrelationAux aux 
)

Correlates two matrices and finds the maximun of the correlation matrix. This center may not be at an integer position. The routine works as follows:

  • Search for the maximun with pixel acuraccy inside the selfWindow
  • Calculate the gravity centre of the corelation in a neighborhood such as maximum/sqrt(2) > value
  • Look for the gravity centre in this neighborhood Note: The neighborhood is circular

Definition at line 31 of file refinement.cpp.

37 {
38 
39  //WRAP is OK for crystal but may be not for single particles
40 
41  //calculate correlation matrix
42  correlation_matrix(mat1, mat2, mat_temp, aux);
43  mat_temp.setXmippOrigin();
44 
45  //search for the maximun inside selfWindow "selfWindow"
46  auto max_step_int = (int)ROUND(max_step);
47  int imax=0, jmax=0;
48 
49  MultidimArray<int> window(2*max_step_int + 1, 2*max_step_int + 1);
50  window.setXmippOrigin();
51 
52  T temp_max = -100000000;
53 
54  //******* search for the maximun with pixel acuraccy **************/
56  {
57  if (temp_max < mat_temp(i, j))
58  {
59  temp_max = mat_temp(i, j);
60  imax = i;
61  jmax = j;
62  }
63  }
64  // #define DEBUG_calculate_and_find_correlation_max_mat
65 #ifdef DEBUG_calculate_and_find_correlation_max_mat
66  std::cout << "\n imax, jmax: " << imax << " " << jmax << std::endl;
67  std::cout.flush();
68 #endif
69 
70  /******* Calculate the gravity centre of the corelation ****/
71  /******* in a neighborhood such as maximum/sqrt(2) > value ****/
72  int n_max;
73  int stop_loop;
74  int i, j, i_actual, j_actual;
75  int radius;
76  stop_loop = false;
77  n_max = 0;
78  while (!stop_loop)
79  {
80  n_max ++;
81  radius = n_max * n_max;
82  for (i = -n_max; i <= n_max; i++)
83  for (j = -n_max; j <= n_max; j++)
84  {
85  i_actual = i + imax;
86  j_actual = j + jmax;
87  if ((i*i + j*j) > radius)
88  continue;
89  if (!mat_temp.outside(i_actual, j_actual))
90  {
91  if (temp_max / 1.414 > mat_temp(i_actual, j_actual))
92  stop_loop = true;
93  }
94  else
95  {
96  stop_loop = true;
97  std::cout << "\nWarning(calculate_and_find_correlation_max_mat)"
98  << "\n some points neede to determine the maxima"
99  << "\n are not available" << std::endl;
100  }
101  }
102  }
103 
104  // #define DEBUG_calculate_and_find_correlation_max_mat
105 #ifdef DEBUG_calculate_and_find_correlation_max_mat
106  std::cout << "\n n_max, temp_max: " << n_max << " " << temp_max << std::endl;
107  std::cout.flush();
108 #endif
109 
110  /*** We have the neighborhood => looking for the gravity centre ***/
111 
112  double jj_max ;
113  double ii_max ;
114  double sum_corr ;
115  //n_max and radius has been calculated above
116  jj_max = ii_max = sum_corr = 0.;
117  for (i = -n_max; i <= n_max; i++)
118  for (j = -n_max; j <= n_max; j++)
119  {
120  i_actual = i + imax;
121  j_actual = j + jmax;
122  if ((i*i + j*j) > radius)
123  continue;
124  if (!mat_temp.outside(i_actual, j_actual))
125  {
126  ii_max += i_actual * mat_temp(i_actual, j_actual);
127  jj_max += j_actual * mat_temp(i_actual, j_actual);
128  sum_corr += mat_temp(i_actual, j_actual);
129  }
130  }
131  shift_X = jj_max / sum_corr; /***This is the gravity centre ***/
132  shift_Y = ii_max / sum_corr;
133 
134  // #define DEBUG_calculate_and_find_correlation_max_mat
135 #ifdef DEBUG_calculate_and_find_correlation_max_mat
136  std::cout << "\n shift_XX " << shift_X << std::endl;
137  std::cout << "\n shift_Y " << shift_Y << std::endl;
138  std::cout << "\n jj_max " << jj_max << std::endl;
139  std::cout << "\n ii_max " << ii_max << std::endl;
140  std::cout << "\n sum_corr " << sum_corr << std::endl;
141  std::cout.flush();
142 #endif
143 
144 }
void correlation_matrix(const MultidimArray< double > &m1, const MultidimArray< double > &m2, MultidimArray< double > &R, CorrelationAux &aux, bool center)
Definition: xmipp_fftw.cpp:869
#define i
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
#define ROUND(x)
Definition: xmipp_macros.h:210
#define j
bool outside(int k, int i, int j) const

◆ calculate_and_find_correlation_max_proj()

void calculate_and_find_correlation_max_proj ( Projection const &  proj1,
Projection const &  proj2,
Projection proj_tmp,
double &  shift_X,
double &  shift_Y,
double const  max_step,
int  ref_trans_after,
int  act_proj,
CorrelationAux aux 
)

Correlates two projections and finds the maximun of the correlation matrix.

Definition at line 151 of file refinement.cpp.

158 {
159 // #define DEBUG_calculate_and_find_correlation_max_proj
160 #ifdef DEBUG_calculate_and_find_correlation_max_proj
161  std::cout << "\n (cal_find_corr_proj) imagen_no: " << imagen_no << std::endl;
162 #endif
163 
164 
165  proj_temp().resize(proj1());
167  IMGMATRIX(proj2),
168  IMGMATRIX(proj_temp),
169  shift_X, shift_Y, max_step,
170  aux);
171 
172 }//calculate_and_find_correlation_max end
void calculate_and_find_correlation_max_mat(MultidimArray< T > const &mat1, MultidimArray< T > const &mat2, MultidimArray< T > &mat_temp, double &shift_X, double &shift_Y, double const max_step, CorrelationAux &aux)
Definition: refinement.cpp:31
#define IMGMATRIX(I)