Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members

#include <tomo_align_refinement.h>

Inheritance diagram for ProgTomoAlignRefinement:
Inheritance graph
[legend]
Collaboration diagram for ProgTomoAlignRefinement:
Collaboration graph
[legend]

Public Member Functions

void readParams ()
 Read arguments from command line. More...
 
void show ()
 Show. More...
 
void defineParams ()
 Define parameters. More...
 
void produce_side_info ()
 
void predict_angles (size_t i, const FileName &fnImgOut)
 
void run ()
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void show () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fn_ref
 
FileName fn_sel
 
FileName fn_out
 
double max_rot_change
 
double max_tilt_change
 
double max_psi_change
 
double rot_step
 
double tilt_step
 
double psi_step
 
double max_shift_change
 
double shift_step
 
bool adjustGray
 
bool generateAligned
 
Image< double > V
 
std::vector< AlignmentTomographylist_of_assigned
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

Angular Predict parameters.

Definition at line 53 of file tomo_align_refinement.h.

Member Function Documentation

◆ defineParams()

void ProgTomoAlignRefinement::defineParams ( )
virtual

Define parameters.

Reimplemented from XmippProgram.

Definition at line 75 of file tomo_align_refinement.cpp.

76 {
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");
98 }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ predict_angles()

void ProgTomoAlignRefinement::predict_angles ( size_t  i,
const FileName fnImgOut 
)

Predict angles and shift. This function searches in the shift-psi space and for each combination it correlates with the whole reference set.

Definition at line 132 of file tomo_align_refinement.cpp.

134 {
135  AlignmentTomography newAlignment=list_of_assigned[idx];
136  Image<double> I, Ip;
137  MultidimArray<int> mask;
138  I.read(list_of_assigned[idx].fn_img);
139  I().setXmippOrigin();
140  mask.resizeNoCopy(I());
141 
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;
146  if (idx>0)
147  tilt0=XMIPP_MAX(tilt0,
148  (list_of_assigned[idx].tilt+list_of_assigned[idx-1].tilt)/2);
149  if (idx<list_of_assigned.size()-1)
150  tiltF=XMIPP_MIN(tiltF,
151  (list_of_assigned[idx].tilt+list_of_assigned[idx+1].tilt)/2);
152 
153  Projection theo;
155 #ifdef DEBUG
156 
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;
161 #endif
162 
163  for (double rot = rot0; rot <= rotF; rot += rot_step)
164  for (double tilt = tilt0; tilt <= tiltF; tilt += tilt_step)
165  {
166  Ip()=I();
167  // Take a projection from the given direction
168  projectVolume(V(), theo, YSIZE(V()), XSIZE(V()), rot, tilt, 0);
169  mask.initConstant(1);
171  if (IMGPIXEL(theo,i,j)==0 || IMGPIXEL(Ip,i,j)==0)
172  {
173  A2D_ELEM(mask,i,j)=0;
174  IMGPIXEL(Ip,i,j)=0;
175  }
176  double newCorr=correlationIndex(theo(),Ip(),&mask);
177  if (newCorr>newAlignment.corr)
178  {
179  newAlignment.rot = rot;
180  newAlignment.tilt = tilt;
181  newAlignment.corr=newCorr;
182  if (adjustGray)
183  Ip().rangeAdjust(theo(),&mask);
185  Ip.write(fnImgOut);
186 #ifdef DEBUG
187 
188  std::cout << " Improved " << idx << " rot=" << rot << " tilt=" << tilt
189  << " x,y="
190  << newAlignment.x << " " << newAlignment.y << " psi="
191  << newAlignment.psi << " corr="
192  << newCorr << std::endl;
193  Image<double> save;
194  save()=Ip();
195  save.write("PPPexp.xmp");
196  save()=theo();
197  save.write("PPPtheo.xmp");
198  typeCast(mask,save());
199  save.write("PPPmask.xmp");
200  save()=theo()-Ip();
201  save.write("PPPdiff.xmp");
202 #endif
203 
204  }
205 
206  // Look for better alignment
207  alignImages(theo(),Ip(),M, xmipp_transformation::DONT_WRAP);
208 
209  // Measure the new correlation
210  newCorr=correlationIndex(theo(),Ip(),&mask);
211 
212  // Keep the value
213  if (newCorr>newAlignment.corr)
214  {
215  newAlignment.rot = rot;
216  newAlignment.tilt = tilt;
217  bool flip;
218  double scale;
219  newAlignment.M=M;
220  transformationMatrix2Parameters2D(M, flip, scale, newAlignment.x, newAlignment.y,
221  newAlignment.psi);
222  if (adjustGray)
223  Ip().rangeAdjust(theo(),&mask);
225  Ip.write(fnImgOut);
226 #ifdef DEBUG
227 
228  std::cout << " Improved " << idx << " rot=" << rot << " tilt=" << tilt
229  << " x,y="
230  << newAlignment.x << " " << newAlignment.y << " psi="
231  << newAlignment.psi << " corr="
232  << newCorr << std::endl;
233  newAlignment.corr = newCorr;
234  Image<double> save;
235  save() = Ip();
236  save.write("PPPexpRealigned.xmp");
237  save()=theo()-Ip();
238  save.write("PPPdiffRealigned.xmp");
239  std::cout << "Press any key\n";
240  char c;
241  std::cin >> c;
242 #endif
243 
244  }
245  }
246 
247  // Select best alignment
248  list_of_assigned[idx]=newAlignment;
249 }
#define YSIZE(v)
#define A2D_ELEM(v, i, j)
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
void transformationMatrix2Parameters2D(const Matrix2D< T > &A, bool &flip, T &scale, T &shiftX, T &shiftY, T &psi)
Matrix2D< double > M
double alignImages(const MultidimArray< double > &Iref, const AlignmentTransforms &IrefTransforms, MultidimArray< double > &I, Matrix2D< double > &M, bool wrap, AlignmentAux &aux, CorrelationAux &aux2, RotationalCorrelationAux &aux3)
Definition: filters.cpp:2047
doublereal * c
std::vector< AlignmentTomography > list_of_assigned
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 initConstant(T val)
#define i
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
#define XSIZE(v)
void projectVolume(FourierProjector &projector, Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const MultidimArray< double > *ctf)
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
#define j
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
Definition: matrix1d.h:1227
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)

◆ produce_side_info()

void ProgTomoAlignRefinement::produce_side_info ( )

Produce side info. An exception is thrown if any of the files is not found

Definition at line 102 of file tomo_align_refinement.cpp.

103 {
104  V.read(fn_ref);
105  V().setXmippOrigin();
106  MetaDataVec SF(fn_sel);
107  Image<double> I;
108  FileName fnImg;
109  ApplyGeoParams params;
110  params.datamode = HEADER;
111 
112  for (size_t objId : SF.ids())
113  {
115  SF.getValue(MDL_IMAGE,fnImg,objId);
116  I.readApplyGeo(fnImg,SF,objId, params);
117  I().setXmippOrigin();
118  dummy.rot=I.rot();
119  dummy.tilt=I.tilt();
120  dummy.psi=I.psi();
121  dummy.x=I.Xoff();
122  dummy.y=I.Yoff();
123  dummy.fn_img=fnImg;
124  dummy.corr=-1;
125  list_of_assigned.push_back(dummy);
126  }
127 }
double psi(const size_t n=0) const
std::vector< AlignmentTomography > list_of_assigned
double rot(const size_t n=0) const
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
double tilt(const size_t n=0) const
double Yoff(const size_t n=0) const
double dummy
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)
Name of an image (std::string)

◆ readParams()

void ProgTomoAlignRefinement::readParams ( )
virtual

Read arguments from command line.

Reimplemented from XmippProgram.

Definition at line 41 of file tomo_align_refinement.cpp.

42 {
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");
56 }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
bool checkParam(const char *param)

◆ run()

void ProgTomoAlignRefinement::run ( )
virtual

Run the algorithm over all images

Reimplemented from XmippProgram.

Definition at line 253 of file tomo_align_refinement.cpp.

254 {
256  MetaDataVec DF;
257  FileName fnMaskOut, fnImgOut;
258  Projection theo;
259  Image<double> Imask, I;
260  FileName fn_tmp(fn_out + ".stk");
261  if (adjustGray)
262  fn_tmp.deleteFile();
263 
264  for (size_t i=0; i<list_of_assigned.size(); i++)
265  {
267  fnImgOut.compose(i+1,fn_out+".stk");
268  else
269  fnImgOut=list_of_assigned[i].fn_img;
270 
271  // Get angles and shifts
272  predict_angles(i,fnImgOut);
273 
274  // Store them in the output docfile
275  size_t id = DF.addObject();
276  DF.setValue(MDL_IMAGE,fnImgOut,id);
283  DF.setValue(MDL_MAXCC,list_of_assigned[i].corr,id);
284  }
285  DF.write(fn_out+".doc");
286 }
void predict_angles(size_t i, const FileName &fnImgOut)
Rotation angle of an image (double,degrees)
std::vector< AlignmentTomography > list_of_assigned
Tilting angle of an image (double,degrees)
static double * y
Shift for the image in the X axis (double)
void compose(const String &str, const size_t no, const String &ext="")
Special label to be used when gathering MDs in MpiMetadataPrograms.
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
doublereal * x
#define i
Name of an image from which MDL_IMAGE is coming from.
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
Maximum cross-correlation for the image (double)
double psi(const double x)
Shift for the image in the Y axis (double)
Name of an image (std::string)

◆ show()

void ProgTomoAlignRefinement::show ( )

Show.

Definition at line 59 of file tomo_align_refinement.cpp.

60 {
61  std::cout
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
71  ;
72 }

Member Data Documentation

◆ adjustGray

bool ProgTomoAlignRefinement::adjustGray

Adjust gray

Definition at line 79 of file tomo_align_refinement.h.

◆ fn_out

FileName ProgTomoAlignRefinement::fn_out

Root filename for the output

Definition at line 61 of file tomo_align_refinement.h.

◆ fn_ref

FileName ProgTomoAlignRefinement::fn_ref

Filename of the reference volume

Definition at line 57 of file tomo_align_refinement.h.

◆ fn_sel

FileName ProgTomoAlignRefinement::fn_sel

Filename of the images

Definition at line 59 of file tomo_align_refinement.h.

◆ generateAligned

bool ProgTomoAlignRefinement::generateAligned

Generate output images

Definition at line 81 of file tomo_align_refinement.h.

◆ list_of_assigned

std::vector<AlignmentTomography> ProgTomoAlignRefinement::list_of_assigned

Definition at line 84 of file tomo_align_refinement.h.

◆ max_psi_change

double ProgTomoAlignRefinement::max_psi_change

Maximum psi change.

Definition at line 67 of file tomo_align_refinement.h.

◆ max_rot_change

double ProgTomoAlignRefinement::max_rot_change

Maximum rotation change.

Definition at line 63 of file tomo_align_refinement.h.

◆ max_shift_change

double ProgTomoAlignRefinement::max_shift_change

Maximum shift change

Definition at line 75 of file tomo_align_refinement.h.

◆ max_tilt_change

double ProgTomoAlignRefinement::max_tilt_change

Max tilt change

Definition at line 65 of file tomo_align_refinement.h.

◆ psi_step

double ProgTomoAlignRefinement::psi_step

Psi step

Definition at line 73 of file tomo_align_refinement.h.

◆ rot_step

double ProgTomoAlignRefinement::rot_step

Rot step

Definition at line 69 of file tomo_align_refinement.h.

◆ shift_step

double ProgTomoAlignRefinement::shift_step

Shift step

Definition at line 77 of file tomo_align_refinement.h.

◆ tilt_step

double ProgTomoAlignRefinement::tilt_step

Tilt step

Definition at line 71 of file tomo_align_refinement.h.

◆ V

Image<double> ProgTomoAlignRefinement::V

Definition at line 83 of file tomo_align_refinement.h.


The documentation for this class was generated from the following files: