76 <<
"Output directory: " <<
fnOutDir << std::endl
77 <<
"Reference volume: " <<
fnVolR << std::endl
78 <<
"Reference mask: " <<
fnMaskR << std::endl
79 <<
"Max. Shift: " <<
maxShift << std::endl
81 <<
"Max. Resolution: " <<
maxResol << std::endl
82 <<
"Sampling: " <<
Ts << std::endl
83 <<
"Max. Radius: " <<
Rmax << std::endl
84 <<
"Max. Radius Deform. " <<
RmaxDef << std::endl
85 <<
"Zernike Degree: " <<
L1 << std::endl
86 <<
"SH Degree: " <<
L2 << std::endl
91 <<
"Regularization: " <<
lambda << std::endl
98 addUsageLine(
"Make a continuous angular assignment with deformations");
102 defaultComments[
"-o"].addComment(
"Metadata with the angular alignment and deformation parameters");
106 addParamsLine(
" [--odir <outputDir=\".\">] : Output directory");
107 addParamsLine(
" [--max_shift <s=-1>] : Maximum shift allowed in pixels");
108 addParamsLine(
" [--max_angular_change <a=5>] : Maximum angular change allowed (in degrees)");
109 addParamsLine(
" [--max_resolution <f=4>] : Maximum resolution (A)");
110 addParamsLine(
" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
111 addParamsLine(
" [--Rmax <R=-1>] : Maximum radius (px). -1=Half of volume size");
112 addParamsLine(
" [--RDef <r=-1>] : Maximum radius of the deformation (px). -1=Half of volume size");
113 addParamsLine(
" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
114 addParamsLine(
" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
115 addParamsLine(
" [--optimizeAlignment] : Optimize alignment");
116 addParamsLine(
" [--optimizeDeformation] : Optimize deformation");
118 addParamsLine(
" [--phaseFlipped] : Input images have been phase flipped");
119 addParamsLine(
" [--regularization <l=0.01>] : Regularization weight");
122 addExampleLine(
"xmipp_angular_sph_alignment -i anglesFromContinuousAssignment.xmd --ref reference.vol -o assigned_anglesAndDeformations.xmd --optimizeAlignment --optimizeDeformation --depth 1");
128 V().setXmippOrigin();
197 double deltaDefocusU,
double deltaDefocusV,
double deltaDefocusAngle)
202 double deformation=0.0;
205 P().setXmippOrigin();
206 deformVol(
P(), mV, deformation, rot, tilt, psi);
208 applyCTFImage(deltaDefocusU, deltaDefocusV, deltaDefocusAngle);
227 std::cout <<
"A=" <<
A << std::endl;
230 save.
write(
"PPPtheo.xmp");
232 save.
write(
"PPPfilteredp.xmp");
234 save.
write(
"PPPfiltered.xmp");
236 std::cout <<
"Cost=" << cost <<
" deformation=" << deformation << std::endl;
237 std::cout <<
"Press any key" << std::endl;
238 char c; std::cin >>
c;
243 std::cout <<
"A=" <<
A << std::endl;
245 save.
write(
"PPPtheo.xmp");
247 save.
write(
"PPPfilteredp.xmp");
249 save.
write(
"PPPfiltered.xmp");
250 std::cout <<
"Cost=" << cost <<
" corr=" << corr << std::endl;
252 std::cout <<
"Press any key" << std::endl;
253 char c; std::cin >>
c;
257 double retval=cost+
lambda*(deformation + massDiff);
259 std::cout << cost <<
" " << deformation <<
" " <<
lambda*deformation <<
" " <<
sumV <<
" " <<
sumVd <<
" " << massDiff <<
" " << retval << std::endl;
266 int idx = 3*(
prm->vecSize);
267 double deltax=x[idx+1];
268 double deltay=x[idx+2];
269 double deltaRot=x[idx+3];
270 double deltaTilt=x[idx+4];
271 double deltaPsi=x[idx+5];
272 double deltaDefocusU=x[idx+6];
273 double deltaDefocusV=x[idx+7];
274 double deltaDefocusAngle=x[idx+8];
277 if (
prm->maxAngularChange>0 && (fabs(deltaRot)>
prm->maxAngularChange || fabs(deltaTilt)>
prm->maxAngularChange || fabs(deltaPsi)>
prm->maxAngularChange))
287 return prm->tranformImageSph(x,
prm->old_rot+deltaRot,
prm->old_tilt+deltaTilt,
prm->old_psi+deltaPsi,
288 deltaDefocusU, deltaDefocusV, deltaDefocusAngle);
328 std::cout <<
"Processing " << fnImg << std::endl;
330 I().setXmippOrigin();
335 for (
int h=1;h<=
L2;h++)
339 std::cout<<std::endl;
340 std::cout<<
"------------------------------ Basis Degrees: ("<<
L1<<
","<<h<<
") ----------------------------"<<std::endl;
378 std::cout<<std::endl;
379 for (
int j=1;
j<4;
j++)
384 std::cout <<
"X Coefficients=(";
387 std::cout <<
"Y Coefficients=(";
390 std::cout <<
"Z Coefficients=(";
399 std::cout <<
")" << std::endl;
401 std::cout <<
"Radius=" <<
RmaxDef << std::endl;
402 std::cout <<
" Dshift=(" <<
p(totalSize-5) <<
"," <<
p(totalSize-4) <<
") " 403 <<
"Drot=" <<
p(totalSize-3) <<
" Dtilt=" <<
p(totalSize-2)
404 <<
" Dpsi=" <<
p(totalSize-1) << std::endl;
406 std::cout<<std::endl;
411 std::cerr << XE.what() << std::endl;
412 std::cerr <<
"Warning: Cannot refine " << fnImg << std::endl;
442 std::vector<double> vectortemp;
444 vectortemp.push_back(
clnm(
j));
455 for (
int h=0; h<=l2; h++)
461 int numEven=(count>>1)+(count&1 && !(h&1));
464 nc += numSPH*numEven;
467 nc += numSPH*(count-numEven);
476 auto totalSize = (int)((steps.
size()-8)/3);
477 for (
int idx=0; idx<size; idx++) {
480 VEC_ELEM(steps,idx+2*totalSize) = 1.;
491 for (
int h=0; h<=l2; h++) {
492 int totalSPH = 2*h+1;
494 for (
int l=h; l<=l1; l+=2) {
495 for (
int m=0;
m<totalSPH;
m++) {
507 double const &deltaDefocusAngle) {
531 double rot,
double tilt,
double psi)
539 size_t idxZ0=2*idxY0;
542 double RmaxF2=RmaxF*RmaxF;
543 double iRmaxF=1.0/RmaxF;
565 double k2=
ZZ(pos)*
ZZ(pos);
566 double kr=
ZZ(pos)*iRmaxF;
567 double k2i2=k2+
YY(pos)*
YY(pos);
568 double ir=
YY(pos)*iRmaxF;
569 double r2=k2i2+
XX(pos)*
XX(pos);
570 double jr=
XX(pos)*iRmaxF;
571 double rr=
sqrt(r2)*iRmaxF;
573 for (
size_t idx=0; idx<idxY0; idx++) {
588 auto k_mask = (int)(
ZZ(pos)+gz);
589 auto i_mask = (int)(
YY(pos)+gy);
590 auto j_mask = (int)(
XX(pos)+gx);
595 if (voxelI_mask == 1) {
599 modg += gx*gx+gy*gy+gz*gz;
607 def =
sqrt(modg/Ncount);
#define A2D_ELEM(v, i, j)
double getDoubleParam(const char *param, int arg=0)
__host__ __device__ float2 floor(const float2 v)
ProgAngularSphAlignment()
Empty constructor.
MultidimArray< int > mask2D
Image< double > Ifilteredp
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
double tranformImageSph(double *pclnm, double rot, double tilt, double psi, double deltaDefocusU, double deltaDefocusV, double deltaDefocusAngle)
void sqrt(Image< double > &op)
void minimizepos(int l2, Matrix1D< double > &steps) const
Determine the positions to be minimize of a vector containing spherical harmonic coefficients.
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
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)
virtual void writeImageParameters(const FileName &fnImg)
void inv(Matrix2D< T > &result) const
void abs(Image< double > &op)
void setFileName(const FileName &fn)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
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.
#define MAT_ELEM(m, i, j)
#define A3D_ELEM(V, k, i, j)
double azimuthal_angle
Azimuthal angle (between X and U) in degrees.
double continuousSphCost(double *x, void *_prm)
void numCoefficients(int l1, int l2, int &nc) const
Length of coefficients vector.
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
const FileName & getFileName() const
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
void applyCTFImage(double const &deltaDefocusU, double const &deltaDefocusV, double const &deltaDefocusAngle)
void updateCTFImage(double defocusU, double defocusV, double angle)
Image< double > Ifiltered
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
double Tm
Sampling rate (A/pixel)
virtual void finishProcessing()
#define DIRECT_MULTIDIM_ELEM(v, n)
void addExampleLine(const char *example, bool verbatim=true)
T interpolatedElement3D(double x, double y, double z, T outside_value=(T) 0) const
double maxShift
Maximum shift.
void readFromMdRow(const MDRow &row, bool disable_if_not_K=true)
int verbose
Verbosity level.
void readParams()
Read argument from command line.
FileName fnOutDir
Output directory.
virtual void createWorkFiles()
double K
Global gain. By default, 1.
Image< double > Vdeformed
void generate_mask(bool apply_geo=false)
virtual bool containsLabel(MDLabel label) const =0
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
bool outside(int k, int i, int j) const
#define BINARY_CIRCULAR_MASK
void produceSideInfo()
Produce Side information.
double psi(const double x)
MultidimArray< int > V_mask
bool checkParam(const char *param)
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.
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void addUsageLine(const char *line, bool verbatim=false)
~ProgAngularSphAlignment()
Destructor.
bool enable_CTFnoise
Enable CTFnoise part.
const MultidimArray< int > & get_binary_mask() const
Matrix1D< double > steps_cp
T * adaptForNumericalRecipes() const
int getIntParam(const char *param, int arg=0)
void generateMask(MultidimArray< double > &v)
void addParamsLine(const String &line)
void defineParams()
Define parameters.
void applyMaskSpace(MultidimArray< double > &v)
void fillVectorTerms(int l1, int l2)
Zernike and SPH coefficients allocation.
std::map< String, CommentList > defaultComments