43 fn_ref = getParam(
"--ref");
44 fn_sel = getParam(
"--sel");
45 fn_out = getParam(
"--oroot");
46 max_rot_change = getDoubleParam(
"--max_rot_change");
47 max_tilt_change = getDoubleParam(
"--max_tilt_change");
48 max_psi_change = getDoubleParam(
"--max_psi_change");
49 rot_step = getDoubleParam(
"--rot_step");
50 tilt_step = getDoubleParam(
"--tilt_step");
51 psi_step = getDoubleParam(
"--psi_step");
52 max_shift_change = getDoubleParam(
"--max_shift_change");
53 shift_step = getDoubleParam(
"--shift_step");
54 adjustGray = checkParam(
"--adjustGray");
55 generateAligned = checkParam(
"--generateAligned");
62 <<
"Reference images: " << fn_ref << std::endl
63 <<
"Input images: " << fn_sel << std::endl
64 <<
"Ouput rootname: " << fn_out << std::endl
65 <<
"Max rot change: " << max_rot_change <<
" step: " << rot_step << std::endl
66 <<
"Max tilt change: " << max_tilt_change <<
" step: " << tilt_step << std::endl
67 <<
"Max psi change: " << max_psi_change <<
" step: " << psi_step << std::endl
68 <<
"Max shift change: " << max_shift_change <<
" step: " << shift_step << std::endl
69 <<
"Adjust gray: " << adjustGray << std::endl
70 <<
"Generate aligned: " << generateAligned << std::endl
77 addUsageLine(
"Realign a tilt series with respect to a volume following a single ");
78 addUsageLine(
"particles approach, i.e., the volume is reprojected and the alignment");
79 addUsageLine(
"parameters are reoptimized.");
80 addParamsLine(
" --ref <volume> : Reference volume");
81 addParamsLine(
" --sel <selfile> : Images to align");
82 addParamsLine(
" --oroot <rootname> : rootname for the output");
83 addParamsLine(
" : rootname.doc contains a selfile with the");
84 addParamsLine(
" : images realigned");
85 addParamsLine(
" : rootname.stk contains the aligned and");
86 addParamsLine(
" : adjusted images in case --adjustGray or");
87 addParamsLine(
" : --generateAligned are given");
88 addParamsLine(
" [--max_rot_change <ang=2>] : Maximum change allowed in rot");
89 addParamsLine(
" [--max_tilt_change <ang=2>] : Maximum change allowed in tilt");
90 addParamsLine(
" [--max_psi_change <ang=2>] : Maximum change allowed in psi");
91 addParamsLine(
" [--max_shift_change <r=10>] : Maximum change allowed in shift");
92 addParamsLine(
" [--rot_step <ang=0.25>] : Rot search step");
93 addParamsLine(
" [--tilt_step <ang=0.25>] : Tilt search step");
94 addParamsLine(
" [--psi_step <ang=0.25>] : Psi search step");
95 addParamsLine(
" [--shift_step <r=2>] : Step in shift in pixels");
96 addParamsLine(
" [--adjustGray] : Adjust also gray values");
97 addParamsLine(
" [--generateAligned] : Generate aligned images");
105 V().setXmippOrigin();
112 for (
size_t objId : SF.
ids())
117 I().setXmippOrigin();
125 list_of_assigned.push_back(dummy);
139 I().setXmippOrigin();
142 double rot0=list_of_assigned[idx].rot-max_rot_change;
143 double rotF=list_of_assigned[idx].rot+max_rot_change;
144 double tilt0=list_of_assigned[idx].tilt-max_tilt_change;
145 double tiltF=list_of_assigned[idx].tilt+max_tilt_change;
148 (list_of_assigned[idx].
tilt+list_of_assigned[idx-1].
tilt)/2);
149 if (idx<list_of_assigned.size()-1)
151 (list_of_assigned[idx].
tilt+list_of_assigned[idx+1].
tilt)/2);
157 std::cout <<
"original idx,rot,tilt,psi,x,y=" << idx <<
" " 158 << newAlignment.
rot <<
" " << newAlignment.
tilt 159 <<
" " << newAlignment.
psi <<
" " 160 << newAlignment.
x <<
" " << newAlignment.
y << std::endl;
163 for (
double rot = rot0;
rot <= rotF;
rot += rot_step)
164 for (
double tilt = tilt0;
tilt <= tiltF;
tilt += tilt_step)
177 if (newCorr>newAlignment.
corr)
181 newAlignment.
corr=newCorr;
183 Ip().rangeAdjust(theo(),&mask);
184 if (adjustGray || generateAligned)
188 std::cout <<
" Improved " << idx <<
" rot=" <<
rot <<
" tilt=" <<
tilt 190 << newAlignment.
x <<
" " << newAlignment.
y <<
" psi=" 191 << newAlignment.
psi <<
" corr=" 192 << newCorr << std::endl;
195 save.
write(
"PPPexp.xmp");
197 save.
write(
"PPPtheo.xmp");
199 save.
write(
"PPPmask.xmp");
201 save.
write(
"PPPdiff.xmp");
207 alignImages(theo(),Ip(),M, xmipp_transformation::DONT_WRAP);
213 if (newCorr>newAlignment.
corr)
223 Ip().rangeAdjust(theo(),&mask);
224 if (adjustGray || generateAligned)
228 std::cout <<
" Improved " << idx <<
" rot=" <<
rot <<
" tilt=" <<
tilt 230 << newAlignment.
x <<
" " << newAlignment.
y <<
" psi=" 231 << newAlignment.
psi <<
" corr=" 232 << newCorr << std::endl;
233 newAlignment.
corr = newCorr;
236 save.
write(
"PPPexpRealigned.xmp");
238 save.
write(
"PPPdiffRealigned.xmp");
239 std::cout <<
"Press any key\n";
248 list_of_assigned[idx]=newAlignment;
264 for (
size_t i=0;
i<list_of_assigned.size();
i++)
266 if (adjustGray || generateAligned)
267 fnImgOut.
compose(
i+1,fn_out+
".stk");
269 fnImgOut=list_of_assigned[
i].fn_img;
272 predict_angles(
i,fnImgOut);
285 DF.
write(fn_out+
".doc");
void predict_angles(size_t i, const FileName &fnImgOut)
void defineParams()
Define parameters.
#define A2D_ELEM(v, i, j)
double alignImages(const MultidimArray< double > &Iref, const AlignmentTransforms &IrefTransforms, MultidimArray< double > &I, Matrix2D< double > &M, bool wrap, AlignmentAux &aux, CorrelationAux &aux2, RotationalCorrelationAux &aux3)
double psi(const size_t n=0) const
void resizeNoCopy(const MultidimArray< T1 > &v)
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)
void compose(const String &str, const size_t no, const String &ext="")
double rot(const size_t n=0) const
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams ¶ms=DefaultApplyGeoParams)
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
double tilt(const size_t n=0) const
double Yoff(const size_t n=0) const
void readParams()
Read arguments from command line.
void projectVolume(FourierProjector &projector, Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const MultidimArray< double > *ctf)
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
double Xoff(const size_t n=0) const
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
#define IMGPIXEL(I, i, j)