33 addUsageLine(
"Generate 3D reconstructions from projections using random orientations");
35 addParamsLine(
" -i <md_file> : Metadata file with input projections");
36 addParamsLine(
" [--oroot <volume_file=\"rec_random\">] : Filename for output rootname");
37 addParamsLine(
" [--sym <symfile=c1>] : Enforce symmetry in projections");
38 addParamsLine(
" [--randomIter <N=10>] : Number of iterations with random assignment");
39 addParamsLine(
" [--greedyIter <N=0>] : Number of iterations with greedy assignment");
40 addParamsLine(
" [--rejection <p=25>] : Percentage of images to reject for reconstruction");
41 addParamsLine(
" [--initial <file=\"\">] : Initial volume if available");
42 addParamsLine(
" [--keepIntermediateVolumes] : Keep the volume of each iteration");
43 addParamsLine(
" [--dontApplyPositive] : Do not apply positive constraint in the random iterations");
44 addParamsLine(
" [--T0 <T=0.1>] : Initial temperature for simulated annealing");
46 addParamsLine(
" [--angularSampling <a=5>] : Angular sampling in degrees for generating the projection gallery");
71 std::cout <<
"Input metadata : " <<
fnIn << std::endl;
72 std::cout <<
"Output rootname : " <<
fnRoot << std::endl;
73 std::cout <<
"T0 : " <<
T0 << std::endl;
74 std::cout <<
"Number of random iterations : " <<
NiterRandom << std::endl;
75 std::cout <<
"Number of greedy iterations : " <<
NiterGreedy << std::endl;
76 std::cout <<
"Rejection percentage : " <<
rejection << std::endl;
77 std::cout <<
"Number of threads : " <<
Nthr << std::endl;
82 std::cout <<
"Symmetry for projections : " <<
fnSym << std::endl;
84 std::cout <<
"Initial volume : " <<
fnInit << std::endl;
101 size_t improvementCount=0;
102 double oldCorr=prm.
mdInp[nImg].maxcc;
106 std::cout <<
"Image: " << fnImg <<
" oldCorr=" << oldCorr << std::endl;
108 std::vector< Matrix2D<double> > allM;
109 for (
size_t nGallery=0; nGallery<
XSIZE(allCorrs); ++nGallery)
111 mCurrentImageAligned=mCurrentImage;
125 std::cout <<
" Matching Gallery: " << fnImg <<
" " << corr << std::endl;
129 improvementFraction=(double)improvementCount/
NSIZE(prm.
gallery());
132 std::cout <<
" oldcorr=" << oldCorr << std::endl;
137 double bestCorr, bestAngleRot, bestAngleTilt, bestAnglePsi, bestShiftX, bestShiftY, bestWeight;
140 double correctionFactor=1;
142 double icurrentT=1.0/currentT;
143 for (
size_t nGallery=0; nGallery<
XSIZE(allCorrs); ++nGallery)
145 bool getThis=(
A1D_ELEM(allCorrs,nGallery)>oldCorr) || (improvementCount==0 &&
A1D_ELEM(scaledCorrs,nGallery)>=0.98);
149 double diff=oldCorr-
A1D_ELEM(allCorrs,nGallery);
151 getThis=(p<exp(-diff*icurrentT));
156 double scale, shiftX, shiftY, anglePsi;
159 double weight=
A1D_ELEM(scaledCorrs,nGallery)*correctionFactor;
160 double corr=
A1D_ELEM(allCorrs,nGallery);
161 double angleRot=prm.
mdGallery[nGallery].rot;
162 double angleTilt=prm.
mdGallery[nGallery].tilt;
165 std::cout <<
" Getting Gallery: " << fnImg <<
" corr=" << corr <<
" cdf=" << weight <<
" rot=" << angleRot
166 <<
" tilt=" << angleTilt << std::endl;
171 size_t recId=mdReconstruction.
addObject();
173 fnImg=prm.
mdInp[nImg].fnImg;
188 bestAngleRot=angleRot;
189 bestAngleTilt=angleTilt;
190 bestAnglePsi=anglePsi;
203 size_t recId=mdReconstruction.
addObject();
205 fnImg=prm.
mdInp[nImg].fnImg;
219 mdReconstruction.
write(
"PPPreconstruction.xmd");
220 std::cout <<
"Press any key" << std::endl;
235 auto nMax=(int)prm.
mdInp.size();
236 for (
int nImg=0; nImg<nMax; ++nImg)
240 double corr, improvement;
244 prm.
mdInp[nImg].maxcc=corr;
282 for (
size_t objId :
mdIn.
ids())
309 std::sort(correlations.begin(),correlations.end());
311 double minCorr=correlations[skip];
314 std::vector<double> weights;
316 std::sort(weights.begin(),weights.end());
317 double minWeight=weights[skip];
320 for (
size_t objId : mdAux.
ids())
327 if (weight<minWeight)
338 if (system(cmd.c_str())==-1)
342 cmd=(
String)
"xmipp_transform_mask "+args;
343 if (system(cmd.c_str())==-1)
349 cmd=(
String)
"xmipp_transform_threshold "+args;
350 if (system(cmd.c_str())==-1)
357 if (system(cmd.c_str())==-1)
364 String args=
formatString(
"-i %s -o %s --sampling_rate %f --sym %s --compute_neighbors --angular_distance -1 --experimental_images %s -v 0",
366 String cmd=(
String)
"xmipp_angular_project_library "+args;
367 if (system(cmd.c_str())==-1)
371 for (
size_t objId : mdAux.
ids())
400 size_t xdim, ydim, zdim, ndim;
407 for (
size_t objId :
mdIn.
ids())
void run(ThreadFunction function, void *data=NULL)
Just to locate unclassified errors.
void generateProjections()
Generate projections from the current volume.
void init_progress_bar(long total)
MetaDataDb mdReconstruction
void cumlativeDensityFunction(MultidimArray< double > &cdf)
double getDoubleParam(const char *param, int arg=0)
void readParams()
Read arguments from command line.
__host__ __device__ float2 floor(const float2 v)
#define REPORT_ERROR(nerr, ErrormMsg)
std::vector< InputImage > mdInp
Image< double > inputImages
void resizeNoCopy(const MultidimArray< T1 > &v)
MetaDataDb mdReconstruction
void aliasImageInStack(const MultidimArray< T > &m, size_t select_image)
#define MULTIDIM_ARRAY(v)
FileName fnGalleryMetaData
void reconstructCurrent()
Reconstruct current volume.
void produceSideinfo()
Produce side info: fill arrays with relevant transformation matrices.
void filterByCorrelation()
Filter by correlation.
std::vector< GalleryImage > mdGallery
ThreadVolumeInitialAlignment * threadResults
bool keepIntermediateVolumes
const char * getParam(const char *param, int arg=0)
void progress_bar(long rlen)
int verbose
Verbosity level.
void * workClass
The class in which threads will be working.
void sort(struct DCEL_T *dcel)
size_t correlations(const Dimensions &d)
String formatString(const char *format,...)
int thread_id
The thread id.
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)
int getIntParam(const char *param, int arg=0)
double alignImagesConsideringMirrors(const MultidimArray< double > &Iref, const AlignmentTransforms &IrefTransforms, MultidimArray< double > &I, Matrix2D< double > &M, AlignmentAux &aux, CorrelationAux &aux2, RotationalCorrelationAux &aux3, bool wrap, const MultidimArray< int > *mask)
void addParamsLine(const String &line)
void defineParams()
Read arguments from command line.
void threadAlignSubset(ThreadArgument &thArg)
void alignSingleImage(size_t nImg, ProgVolumeInitialSimulatedAnnealing &prm, MetaData &mdReconstruction, double &newCorr, double &improvementFraction)