81 <<
"Output directory: " <<
fnOutDir << std::endl
82 <<
"Reference volume: " <<
fnVolR << std::endl
83 <<
"Reference mask: " <<
fnMaskR << std::endl
84 <<
"Max. Shift: " <<
maxShift << std::endl
86 <<
"Max. Resolution: " <<
maxResol << std::endl
87 <<
"Sampling: " <<
Ts << std::endl
88 <<
"Max. Radius: " <<
Rmax << std::endl
89 <<
"Max. Radius Deform. " <<
RmaxDef << std::endl
90 <<
"Zernike Degree: " <<
L1 << std::endl
91 <<
"SH Degree: " <<
L2 << std::endl
93 <<
"Correct CTF: " <<
useCTF << std::endl
98 <<
"Regularization: " <<
lambda << std::endl
99 <<
"Blob radius: " <<
blob_r << std::endl
107 addUsageLine(
"Make a continuous angular assignment with deformations");
111 defaultComments[
"-o"].addComment(
"Metadata with the angular alignment and deformation parameters");
115 addParamsLine(
" [--odir <outputDir=\".\">] : Output directory");
116 addParamsLine(
" [--max_shift <s=-1>] : Maximum shift allowed in pixels");
117 addParamsLine(
" [--max_angular_change <a=5>] : Maximum angular change allowed (in degrees)");
118 addParamsLine(
" [--max_resolution <f=4>] : Maximum resolution (A)");
119 addParamsLine(
" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
120 addParamsLine(
" [--Rmax <R=-1>] : Maximum radius (px). -1=Half of volume size");
121 addParamsLine(
" [--RDef <r=-1>] : Maximum radius of the deformation (px). -1=Half of volume size");
122 addParamsLine(
" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
123 addParamsLine(
" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
126 addParamsLine(
" [--optimizeAlignment] : Optimize alignment");
127 addParamsLine(
" [--optimizeDeformation] : Optimize deformation");
129 addParamsLine(
" [--phaseFlipped] : Input images have been phase flipped");
130 addParamsLine(
" [--regularization <l=0.01>] : Regularization weight");
131 addParamsLine(
" [--blobr <b=4>] : Blob radius for forward mapping splatting");
132 addParamsLine(
" [--image_mode <im=-1>] : Image mode (single, pairs, triplets). By default, it will be automatically identified.");
135 addExampleLine(
"xmipp_forward_zernike_images_priors -i anglesFromContinuousAssignment.xmd --ref reference.vol -o assigned_anglesAndDeformations.xmd --optimizeAlignment --optimizeDeformation --depth 1");
141 V().setXmippOrigin();
306 double deformation=0.0;
310 P[0]().setXmippOrigin();
314 deformVol(
P[0](), mV, deformation, currentRot, currentTilt, currentPsi);
326 P[1]().setXmippOrigin();
327 currentRot =
old_rot[1] + deltaRot[1];
328 currentTilt =
old_tilt[1] + deltaTilt[1];
329 currentPsi =
old_psi[1] + deltaPsi[1];
330 deformVol(
P[1](), mV, deformation, currentRot, currentTilt, currentPsi);
342 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
344 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
355 P[1]().setXmippOrigin();
356 currentRot =
old_rot[1] + deltaRot[1];
357 currentTilt =
old_tilt[1] + deltaTilt[1];
358 currentPsi =
old_psi[1] + deltaPsi[1];
359 deformVol(
P[1](), mV, deformation, currentRot, currentTilt, currentPsi);
362 P[2]().setXmippOrigin();
363 currentRot =
old_rot[2] + deltaRot[2];
364 currentTilt =
old_tilt[2] + deltaTilt[2];
365 currentPsi =
old_psi[2] + deltaPsi[2];
366 deformVol(
P[2](), mV, deformation, currentRot, currentTilt, currentPsi);
381 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
383 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
385 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
405 xmipp_transformation::IS_NOT_INV,xmipp_transformation::DONT_WRAP,0.);
434 cost=-(corr1+corr2+corr3) / 2.0;
437 cost=-(corr1+corr2+corr3) / 3.0;
440 cost=-(corr1+corr2+corr3);
445 std::cout <<
"A=" << A << std::endl;
448 save.
write(
"PPPtheo.xmp");
450 save.
write(
"PPPfilteredp.xmp");
452 save.
write(
"PPPfiltered.xmp");
454 std::cout <<
"Cost=" << cost <<
" deformation=" << deformation << std::endl;
455 std::cout <<
"Press any key" << std::endl;
456 char c; std::cin >>
c;
461 std::cout <<
"A1=" <<
A1 << std::endl;
464 save.
write(
"PPPtheo1.xmp");
466 save.
write(
"PPPfilteredp1.xmp");
468 save.
write(
"PPPfiltered1.xmp");
474 std::cout <<
"A2=" <<
A2 << std::endl;
476 save.
write(
"PPPtheo2.xmp");
478 save.
write(
"PPPfilteredp2.xmp");
480 save.
write(
"PPPfiltered2.xmp");
486 std::cout <<
"A2=" <<
A2 << std::endl;
488 save.
write(
"PPPtheo2.xmp");
490 save.
write(
"PPPfilteredp2.xmp");
492 save.
write(
"PPPfiltered2.xmp");
494 std::cout <<
"A3=" <<
A3 << std::endl;
496 save.
write(
"PPPtheo3.xmp");
498 save.
write(
"PPPfilteredp3.xmp");
500 save.
write(
"PPPfiltered3.xmp");
509 std::cout <<
"Press any key" << std::endl;
510 char c; std::cin >>
c;
516 std::cout << cost <<
" " << deformation <<
" " <<
lambda*deformation <<
" " <<
sumV <<
" " << retval << std::endl;
532 prm->
deltaX[0] = x[idx + 1];
533 prm->
deltaY[0] = x[idx + 3];
541 prm->
deltaX[1] = x[idx + 2];
542 prm->
deltaY[1] = x[idx + 4];
566 prm->
deltaX[0] = x[idx + 1];
567 prm->
deltaY[0] = x[idx + 4];
575 prm->
deltaX[1] = x[idx + 2];
576 prm->
deltaY[1] = x[idx + 5];
584 prm->
deltaX[2] = x[idx + 3];
585 prm->
deltaY[2] = x[idx + 6];
617 prm->
deltaX[0] = x[idx + 1];
618 prm->
deltaY[0] = x[idx + 2];
665 I[0]().setXmippOrigin();
680 I[1]().setXmippOrigin();
685 std::cout <<
"Processing Pair (" <<
fnImage[0] <<
"," <<
fnImage[1] <<
")" << std::endl;
696 I[1]().setXmippOrigin();
707 I[2]().setXmippOrigin();
712 std::cout <<
"Processing Triplet (" <<
fnImage[0] <<
"," <<
fnImage[1] <<
"," <<
fnImage[2] <<
")" << std::endl;
717 std::cout <<
"Processing Image (" <<
fnImage[0] <<
")" << std::endl;
729 std::vector<double> vectortemp;
737 rotateCoefficients<Direction::ROTATE>();
769 std::cout<<std::endl;
770 std::cout<<
"------------------------------ Basis Degrees: ("<<
L1<<
","<<h<<
") ----------------------------"<<std::endl;
785 for (
int i = init;
i < end;
i++)
791 int end = steps.
size();
792 for (
int i = init;
i < end;
i++)
818 std::cout<<std::endl;
819 for (
int j=1;
j<4;
j++)
824 std::cout <<
"X Coefficients=(";
827 std::cout <<
"Y Coefficients=(";
830 std::cout <<
"Z Coefficients=(";
842 std::cout <<
")" << std::endl;
844 std::cout <<
"Radius=" <<
RmaxDef << std::endl;
845 std::cout <<
" Dshift=(" <<
p(totalSize-5) <<
"," <<
p(totalSize-4) <<
") " 846 <<
"Drot=" <<
p(totalSize-3) <<
" Dtilt=" <<
p(totalSize-2)
847 <<
" Dpsi=" <<
p(totalSize-1) << std::endl;
849 std::cout<<std::endl;
854 std::cerr << XE.what() << std::endl;
855 std::cerr <<
"Warning: Cannot refine " << fnImg << std::endl;
863 rotateCoefficients<Direction::UNROTATE>();
925 std::vector<double> vectortemp;
927 for (
int j = 0;
j < end_clnm;
j++) {
928 vectortemp.push_back(
clnm(
j));
938 checkPoint.
addRow(rowAppend);
944 for (
int h=0; h<=l2; h++)
948 int numEven=(count>>1)+(count&1 && !(h&1));
950 vecSize += numSPH*numEven;
953 vecSize += numSPH*(l1-h+1-numEven);
967 for (
int idx = prevSize; idx < size; idx++)
970 VEC_ELEM(steps, idx + totalSize) = 1.;
973 VEC_ELEM(steps, idx + 2 * totalSize) = 1.;
979 for (
int idx = 0; idx < size; idx++)
982 VEC_ELEM(steps, idx + totalSize) = 1.;
985 VEC_ELEM(steps, idx + 2 * totalSize) = 1.;
999 for (
int h=0; h<=l2; h++) {
1000 int totalSPH = 2*h+1;
1002 for (
int l=h; l<=l1; l+=2) {
1003 for (
int m=0;
m<totalSPH;
m++) {
1023 template<ProgForwardZernikeImages::Direction DIRECTION>
1027 size_t idxZ0=2*idxY0;
1040 for (
size_t idx=0; idx<idxY0; idx++) {
1048 double rot,
double tilt,
double psi)
1056 size_t idxZ0=2*idxY0;
1058 double RmaxF2=RmaxF*RmaxF;
1059 double iRmaxF=1.0/RmaxF;
1072 for (
auto j=0;
j<sz;
j++)
1086 const auto &mVpos =
vpos;
1103 for (
auto j = 0;
j < sz;
j++)
1108 aux_l2,
VEC_ELEM(m,
j), xr, yr, zr, rr);
1112 auto i_diff_c_x = R_inv.
mdata[0] * diff_c_x + R_inv.
mdata[1] * diff_c_y;
1113 auto i_diff_c_y = R_inv.
mdata[3] * diff_c_x + R_inv.
mdata[4] * diff_c_y;
1114 auto i_diff_c_z = R_inv.
mdata[6] * diff_c_x + R_inv.
mdata[7] * diff_c_y;
1115 if (rr > 0 || aux_l2 == 0)
1117 gx += i_diff_c_x * (zsph);
1118 gy += i_diff_c_y * (zsph);
1119 gz += i_diff_c_z * (zsph);
1127 auto pos = std::array<double, 3>{};
1128 pos[0] = r_x + r_gx;
1129 pos[1] = r_y + r_gy;
1132 double voxel_mV =
A2D_ELEM(mVpos,
i, 7);
1135 modg += gx * gx + gy * gy + gz * gz;
1139 def =
sqrt(modg/Ncount);
1148 double fx0 = x -
x0;
1150 double fx1 = x1 -
x;
1153 double fy0 = y -
y0;
1155 double fy1 = y1 -
y;
1158 double fz0 = z -
z0;
1160 double fz1 = z1 -
z;
1175 double x_pos = r[0];
1176 double y_pos = r[1];
1183 for (
int i = i0;
i <= iF;
i++)
1185 double y_val = 1. - m *
ABS(
i - y_pos);
1186 for (
int j = j0;
j <= jF;
j++)
1188 double x_val = 1. - m *
ABS(
j - x_pos);
1189 A2D_ELEM(mP,
i,
j) += weight * x_val * y_val;
1197 if (0. < x && x <
blob_r)
1199 else if (-
blob_r < x && x <= 0.)
1210 double sx3 = sx2*sx;
1211 double double_int = 2. *
blob_r;
1212 if (-double_int < x && x < -
blob_r)
1213 return c * (sx3 + 6.*sx2 + 12.*sx + 8.);
1214 else if (-
blob_r <= x && x< 0.)
1215 return c * (-3.*sx3 - 6.*sx2 + 4.);
1216 else if (0. <= x && x <
blob_r)
1217 return c * (3.*sx3 - 6.*sx2 + 4.);
1218 else if (
blob_r <= x && x < double_int)
1219 return c * (-sx3 + 6.*sx2 - 12.*sx + 8.);
1229 aux.setXmippOrigin();
1243 for (
int img_i = i0; img_i <= iF; img_i++)
1246 for (
int img_j = j0; img_j <= jF; img_j++)
1303 size_t idxZ0=2*idxY0;
1305 const auto &mVpos =
vpos;
1322 for (
int idx = 0; idx < idxY0; idx++)
1330 auto i_c_x = R_inv.
mdata[0] * c_x + R_inv.
mdata[1] * c_y + R_inv.
mdata[2] * c_z;
1331 auto i_c_y = R_inv.
mdata[3] * c_x + R_inv.
mdata[4] * c_y + R_inv.
mdata[5] * c_z;
1332 auto i_c_z = R_inv.
mdata[6] * c_x + R_inv.
mdata[7] * c_y + R_inv.
mdata[8] * c_z;
1333 if (rr > 0 || aux_l2 == 0)
1335 gx += i_c_x * (zsph);
1336 gy += i_c_y * (zsph);
1337 gz += i_c_z * (zsph);
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
#define A2D_ELEM(v, i, j)
double alpha
Smoothness parameter.
double getDoubleParam(const char *param, int arg=0)
std::vector< double > old_psi
__host__ __device__ float2 floor(const float2 v)
std::vector< double > old_tilt
void rotatePositions(double rot, double tilt, double psi)
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
FileName fnOutDir
Output directory.
std::vector< double > old_defocusV
void sqrt(Image< double > &op)
std::vector< double > deltaPsi
std::vector< Image< double > > I
std::vector< double > deltaTilt
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
~ProgForwardZernikeImages()
Destructor.
std::vector< double > old_defocusU
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)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
Matrix1D< double > weightsInterpolation3D(double x, double y, double z)
void inv(Matrix2D< T > &result) const
std::vector< Image< double > > Ifilteredp
Matrix1D< double > prev_clnm
std::vector< double > deltaDefocusAngle
void abs(Image< double > &op)
std::vector< double > deltaDefocusU
ProgForwardZernikeImages()
Empty constructor.
void setFileName(const FileName &fn)
void updateCTFImage(double defocusU, double defocusV, double angle)
MultidimArray< int > mask2D
std::vector< double > deltaX
double bspline3(double x)
Image< double > Vdeformed
virtual void writeImageParameters(MDRow &row)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
double DeltafU
Global gain. By default, 1.
double continuousZernikeCost(double *x, void *_prm)
#define MAT_ELEM(m, i, j)
#define A3D_ELEM(V, k, i, j)
double azimuthal_angle
Azimuthal angle (between X and U) in degrees.
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
virtual void finishProcessing()
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
const FileName & getFileName() const
T & getValue(MDLabel label)
double bspline1(double x)
std::vector< double > currentAngle
const char * getParam(const char *param, int arg=0)
void rotateCoefficients()
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 Tm
Sampling rate (A/pixel)
void addExampleLine(const char *example, bool verbatim=true)
std::vector< double > z_clnm_diff
void readFromMdRow(const MDRow &row, bool disable_if_not_K=true)
int verbose
Verbosity level.
const T & getValueOrDefault(MDLabel label, const T &def) const
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
double K
Global gain. By default, 1.
void setValue(MDLabel label, const T &d, bool addLabel=true)
MultidimArray< int > V_mask
std::vector< double > old_shiftX
void generate_mask(bool apply_geo=false)
void readParams()
Read argument from command line.
virtual bool containsLabel(MDLabel label) const =0
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
#define BINARY_CIRCULAR_MASK
void produceSideInfo()
Produce Side information.
double psi(const double x)
int order
Derivation order and Bessel function order.
void splattingAtPos(std::array< double, 3 > r, double weight, MultidimArray< double > &mP, const MultidimArray< double > &mV)
std::vector< size_t > idx_z_clnm
bool checkParam(const char *param)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
virtual void checkPoint()
For very long programs, it may be needed to write checkpoints.
void addUsageLine(const char *line, bool verbatim=false)
Matrix1D< double > steps_cp
void initZeros(const MultidimArray< T1 > &op)
bool enable_CTFnoise
Enable CTFnoise part.
const MultidimArray< int > & get_binary_mask() const
std::vector< double > currentDefocusU
T * adaptForNumericalRecipes() const
int getIntParam(const char *param, int arg=0)
void generateMask(MultidimArray< double > &v)
std::vector< double > deltaDefocusV
double transformImageSph(double *pclnm)
double radius
Spatial radius in Universal System units.
void addParamsLine(const String &line)
MultidimArray< double > df
std::vector< double > currentDefocusV
void applyMaskSpace(MultidimArray< double > &v)
std::vector< double > deltaRot
std::map< String, CommentList > defaultComments