Xmipp  v3.23.11-Nereus
transform_center_image.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar S. Sorzano (coss@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include "core/transformations.h"
28 #include "data/filters.h"
29 
31 {
32 public:
33  int Niter;
34  bool limitShift;
38 
39  void defineParams()
40  {
43  //usage
44  addUsageLine("Center a set of images (preferably with a good SNR, e.g., class averages).");
45  addUsageLine("After calling the program, all classes will be centered and they will tend ");
46  addUsageLine("to show the same orientation. The program centers the images by comparing ");
47  addUsageLine("the image with its X, Y, and XY mirrors. The orientation is determined by ");
48  addUsageLine("comparing the image with its X mirror. ");
49  //examples
50  addExampleLine("Center images in smallStack.stk and store results in a different file:", false);
51  addExampleLine("xmipp_transform_center_image -i smallStack.stk -o stackCentered.stk ");
52  //params
53  addParamsLine(" [--iter <n=10>] : Number of iterations");
54  addParamsLine(" [--limit] : Limit the maximum shift allowed");
55  addParamsLine(" [--save_metadata_transform] : Save in the output metadata the transform parameters");
56 
57  }
58 
59  void readParams()
60  {
62  Niter = getIntParam("--iter");
63  limitShift = checkParam("--limit");
64  saveMdTransform = checkParam("--save_metadata_transform");
65  if (saveMdTransform)
66  save_metadata_stack = true;
67  }
68 
69  void show()
70  {
72  std::cout << "iterations = " << Niter << std::endl;
73  std::cout << "limit shift = " << limitShift << std::endl;
74  }
75 
76  void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
77  {
78  Image<double> img;
80  double scale, shiftX, shiftY, psi;
81  bool flip;
82  img.readApplyGeo(fnImg, rowIn);
83  img().checkDimensionWithDebug(2,__FILE__,__LINE__);
84  A = centerImage(img(), aux, aux2, Niter, limitShift);
85  if (saveMdTransform){
86  transformationMatrix2Parameters2D(A,flip,scale,shiftX,shiftY,psi);
87  rowOut.setValue(MDL_IMAGE, fnImg);
88  rowOut.setValue(MDL_SHIFT_X, shiftX);
89  rowOut.setValue(MDL_SHIFT_Y, shiftY);
90  rowOut.setValue(MDL_ANGLE_PSI, psi);
91  rowOut.setValue(MDL_FLIP, flip);
92  }
93  img.write(fnImgOut);
94 
95  }
96 
97 }
98 ;
void transformationMatrix2Parameters2D(const Matrix2D< T > &A, bool &flip, T &scale, T &shiftX, T &shiftY, T &psi)
Shift for the image in the X axis (double)
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)
Special label to be used when gathering MDs in MpiMetadataPrograms.
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
Matrix2D< double > centerImage(MultidimArray< double > &I, CorrelationAux &aux, RotationalCorrelationAux &aux2, int Niter, bool limitShift)
Definition: filters.cpp:3277
Flip the image? (bool)
void addExampleLine(const char *example, bool verbatim=true)
RotationalCorrelationAux aux2
void setValue(MDLabel label, const T &d, bool addLabel=true)
void show() const override
bool save_metadata_stack
Save the associated output metadata when output file is a stack.
double psi(const double x)
bool checkParam(const char *param)
bool each_image_produces_an_output
Indicate that an output is produced for each image in the input.
Shift for the image in the Y axis (double)
void addUsageLine(const char *line, bool verbatim=false)
int getIntParam(const char *param, int arg=0)
Name of an image (std::string)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
void addParamsLine(const String &line)