40 addUsageLine(
"Center the tilted images of all tilted-untilted image pairs.");
41 addUsageLine(
"+This program receives as input a metadata with two sets of images, untilted and tilted.");
42 addUsageLine(
"+Untilted images must have been previously classified and aligned. Then, the tilted images");
43 addUsageLine(
"+are aligned to their untilted versions. The alignment parameters from the classification plus");
44 addUsageLine(
"+the alignment parameters from the tilted-untilted comparison are used to deduce the 3D");
45 addUsageLine(
"+alignment parameters for the tilted images.");
48 addExampleLine(
"To center tilted images allowing a maximum shift of 10 pixels:",
false);
49 addExampleLine(
"xmipp_align_tilt_pairs -i class_00001@classes.xmd -o alignedImages.xmd --max_shift 10");
52 addParamsLine(
" -i <metadata> : Input metadata with untilted and tilted images");
53 addParamsLine(
" -o <metadata> : Output metadata file with rotations & translations for 3D reconstruction.");
54 addParamsLine(
" --ref <file> : 2D average of the untilted images");
55 addParamsLine(
" [--max_shift <value=10>] : Discard images shifting more than a given threshold (in percentage of the image size).");
56 addParamsLine(
" :+Set it to 0 for no shift estimate between tilted and untilted images");
57 addParamsLine(
" [--do_stretch] : Stretch tilted image to fit into the untilted one.");
59 addParamsLine(
" [--do_not_align_tilted] : Do not align tilted images to untilted ones.");
60 addParamsLine(
" :+Do not align if the quality of the tilted images is low.");
78 <<
"Input metadata: " <<
fnIn << std::endl
79 <<
"Output metadata: " <<
fnOut << std::endl
80 <<
"Reference image: " <<
fnRef << std::endl;
83 <<
"Discard images that shift more than: " <<
max_shift << std::endl;
85 std::cout <<
"Stretching tilted images\n";
92 double inPlaneU,
double shiftXu,
double shiftYu,
93 double alphaT,
double alphaU,
102 tilt = flip ? 180. : 0.;
107 MAT_ELEM(Mu2D,0,2) = flip ? shiftXu : -shiftXu;
129 A2D = Mu2D * E2D.
inv();
136 double corr=
bestShift(imgRefU, imgT2DClass, shiftX, shiftY, auxCorr,
nullptr, max_shift_pixels);
141 std::cout <<
"alphaU=" << alphaU <<
" inplaneU=" << inPlaneU <<
" tilt=" << tilt <<
" alphaT=" << alphaT << std::endl;
142 std::cout <<
"Best shift= " << shiftX <<
" " << shiftY <<
" corr=" << corr << std::endl;
150 Tt=A2D.
inv()*Tt2D.
inv()*A2D;
155 double shift =
sqrt(shiftX * shiftX + shiftY * shiftY);
162 save.
write(
"PPPtilted.xmp");
164 save.
write(
"PPPuntiltedRef.xmp");
165 save() = imgT2DClass;
166 save.
write(
"PPPtiltedAdjusted.xmp");
167 std::cout <<
"Corrected shift= " << shiftX <<
" " << shiftY << std::endl;
168 std::cout <<
"Press any key\n";
172 return (shift < (
double)max_shift_pixels) || corr<0;
193 imgRef().setXmippOrigin();
198 double alphaU, alphaT, tilt, inPlaneU, minusInPlaneU;
199 size_t nDiscarded = 0;
206 for (
const auto& row : mdIn)
214 imgT().setXmippOrigin();
220 imgU.
read(fnUntilted);
221 imgU().setXmippOrigin();
224 save.
write(
"PPPuntilted.xmp");
227 save.
write(
"PPPuntiltedAligned.xmp");
237 double shiftXu, shiftYu;
247 minusInPlaneU = inPlaneU+alphaU;
250 minusInPlaneU=-(inPlaneU+alphaU);
254 XX(vShift) = shiftXu;
255 YY(vShift) = shiftYu;
257 Tup = E * Tu * E.
inv();
260 double shiftX = 0, shiftY = 0;
264 alphaT, alphaU, tilt, imgT(), shiftX, shiftY, auxCorr);
286 std::cout <<
" Discarded " << nDiscarded
287 <<
" tilted images that shifted too much" << std::endl;
bool centerTiltedImage(const MultidimArray< double > &imgU, bool flip, double inPlaneU, double shiftXu, double shiftYu, double alphaT, double alphaU, double tilt, const MultidimArray< double > &imgT, double &shiftX, double &shiftY, CorrelationAux &auxCorr)
Center one tilted image.
void run()
Run over the whole input metadata.
double getDoubleParam(const char *param, int arg=0)
#define REPORT_ERROR(nerr, ErrormMsg)
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
void sqrt(Image< double > &op)
void setValue(const MDObject &object) override
void initProgress(size_t total, size_t stepBin=60)
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)
void inv(Matrix2D< T > &result) const
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams ¶ms=DefaultApplyGeoParams)
#define MAT_ELEM(m, i, j)
const char * getParam(const char *param, int arg=0)
Incorrect argument received.
void addExampleLine(const char *example, bool verbatim=true)
int verbose
Verbosity level.
void defineParams()
Define parameters in the command line.
void setProgress(size_t value=0)
void readParams()
Read parameters from the command line.
template float bestShift(MultidimArray< float > &, float &, float &, const MultidimArray< int > *, int)
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)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)