79 <<
"Output directory: " <<
fnOutDir << std::endl
80 <<
"Reference volume: " <<
fnVolR << std::endl
81 <<
"Reference mask: " <<
fnMaskR << std::endl
82 <<
"Sampling: " <<
Ts << std::endl
83 <<
"Max. Radius Deform. " <<
RmaxDef << std::endl
84 <<
"Zernike Degree: " <<
L1 << std::endl
85 <<
"SH Degree: " <<
L2 << std::endl
86 <<
"Blob radius: " <<
blob_r << std::endl
88 <<
"Correct CTF: " <<
useCTF << std::endl
89 <<
"Correct heretogeneity: " <<
useZernike << std::endl
91 <<
"Regularization: " <<
lambda << std::endl
92 <<
"Number of iterations: " <<
niter << std::endl
93 <<
"Save every # iterations: " <<
save_iter << std::endl;
99 addUsageLine(
"Template-based canonical volume reconstruction through Zernike3D coefficients");
107 addParamsLine(
" [--odir <outputDir=\".\">] : Output directory");
108 addParamsLine(
" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
109 addParamsLine(
" [--RDef <r=-1>] : Maximum radius of the deformation (px). -1=Half of volume size");
110 addParamsLine(
" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
111 addParamsLine(
" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
112 addParamsLine(
" [--blobr <b=4>] : Blob radius for forward mapping splatting");
115 addParamsLine(
" [--useZernike] : Correct heterogeneity with Zernike3D coefficients");
116 addParamsLine(
" [--useCTF] : Correct CTF during ART reconstruction");
117 addParamsLine(
" [--phaseFlipped] : Input images have been phase flipped");
118 addParamsLine(
" [--regularization <l=0.01>] : ART regularization weight");
119 addParamsLine(
" [--niter <n=1>] : Number of ART iterations");
120 addParamsLine(
" [--save_iter <s=0>] : Save intermidiate volume after #save_iter iterations");
121 addParamsLine(
" [--sort_last <N=2>] : The algorithm sorts projections in the most orthogonally possible way. ");
122 addParamsLine(
" : The most orthogonal way is defined as choosing the projection which maximizes the ");
123 addParamsLine(
" : dot product with the N previous inserted projections. Use -1 to sort with all ");
127 addExampleLine(
"xmipp_forward_art_zernike3d -i anglesFromContinuousAssignment.xmd --ref reference.vol -o assigned_anglesAndDeformations.xmd --l1 3 --l2 2");
150 first_image.
read(fn_first_image);
151 size_t Xdim_first =
XSIZE(first_image());
152 V().initZeros(Xdim_first, Xdim_first, Xdim_first);
154 V().setXmippOrigin();
158 Vout().initZeros(
V());
159 Vout().setXmippOrigin();
268 if (img_enabled == -1)
return;
275 std::vector<double> vectortemp;
279 std::vector<double> vec(vectortemp.begin(), vectortemp.end());
301 std::cout <<
"Processing " << fnImg << std::endl;
304 I().setXmippOrigin();
307 artModel<Direction::Forward>();
310 artModel<Direction::Backward>();
315 for (
int h = 0; h <= l2; h++)
317 int numSPH = 2 * h + 1;
318 int count = l1 - h + 1;
319 int numEven = (count >> 1) + (count & 1 && !(h & 1));
322 vecSize += numSPH * numEven;
326 vecSize += numSPH * (l1 - h + 1 - numEven);
339 for (
int h = 0; h <= l2; h++)
341 int totalSPH = 2 * h + 1;
343 for (
int l = h; l <= l1; l += 2)
345 for (
int m = 0;
m < totalSPH;
m++)
357 void ProgForwardArtZernike3D::splattingAtPos(std::array<double, 2> r,
double weight,
366 double a = m *
ABS(i - r[1]);
367 double b = m *
ABS(j - r[0]);
368 double gw = 1 - a - b + a *
b;
374 void ProgForwardArtZernike3D::updateVoxel(std::array<double, 3> r,
double &voxel,
MultidimArray<double> &mV)
380 double hsigma4 = 1.5 *
sqrt(2);
381 double hsigma =
sigma / 4;
392 for (
int k = k0;
k <= kF;
k++)
394 for (
int i = i0;
i <= iF;
i++)
396 for (
int j = j0;
j <= jF;
j++)
409 auto &mVout =
Vout();
415 void ProgForwardArtZernike3D::run()
417 FileName fnImg, fnImgOut, fullBaseName;
444 std::cout <<
"Running iteration " <<
current_iter + 1 <<
" with lambda=" <<
lambda << std::endl;
453 if (rowIn ==
nullptr)
continue;
457 std::cout <<
"Current image ID: " <<
num_images << std::endl;
516 void ProgForwardArtZernike3D::sortOrthogonal()
526 int min_prod_proj = 0;
527 std::vector<double>
rot;
528 std::vector<double>
tilt;
537 for (i = 0; i < numIMG; i++)
556 std::cout <<
"Sorting projections orthogonally...\n" 559 for (i = 1; i < numIMG; i++)
567 for (j = 0; j < numIMG; j++)
575 if (
A1D_ELEM(product, j) < min_prod)
585 A1D_ELEM(chosen, min_prod_proj) = 1;
589 template <ProgForwardArtZernike3D::Direction DIRECTION>
590 void ProgForwardArtZernike3D::artModel()
592 if (DIRECTION == Direction::Forward)
596 P().setXmippOrigin();
598 W().setXmippOrigin();
600 Idiff().setXmippOrigin();
601 I_shifted().initZeros((
int)
XSIZE(
I()), (
int)
XSIZE(
I()));
602 I_shifted().setXmippOrigin();
605 zernikeModel<true, Direction::Forward>();
607 zernikeModel<false, Direction::Forward>();
629 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
634 const auto &mP =
P();
635 const auto &mW =
W();
636 const auto &mIsh = I_shifted();
644 error += (diffVal) * (diffVal);
654 std::cout <<
"Press any key" << std::endl;
664 else if (DIRECTION == Direction::Backward)
667 zernikeModel<true, Direction::Backward>();
669 zernikeModel<false, Direction::Backward>();
673 template <
bool USESZERNIKE, ProgForwardArtZernike3D::Direction DIRECTION>
674 void ProgForwardArtZernike3D::zernikeModel()
680 const size_t idxY0 = USESZERNIKE ? (
clnm.size() / 3) : 0;
681 const size_t idxZ0 = USESZERNIKE ? (2 * idxY0) : 0;
682 const double RmaxF = USESZERNIKE ?
RmaxDef : 0;
683 const double RmaxF2 = USESZERNIKE ? (RmaxF * RmaxF) : 0;
684 const double iRmaxF = USESZERNIKE ? (1.0 / RmaxF) : 0;
686 constexpr
size_t matrixSize = 3;
698 const int step = DIRECTION == Direction::Forward ?
loop_step : 1;
707 double gx = 0.0, gy = 0.0, gz = 0.0;
712 auto kr = k * iRmaxF;
713 auto k2i2 = k2 +
i *
i;
714 auto ir = i * iRmaxF;
715 auto r2 = k2i2 +
j *
j;
716 auto jr = j * iRmaxF;
717 auto rr =
sqrt(
r2) * iRmaxF;
718 for (
size_t idx = 0; idx < idxY0; idx++)
724 if (rr > 0 || l2 == 0)
727 gx +=
clnm[idx] * (zsph);
728 gy +=
clnm[idx + idxY0] * (zsph);
729 gz +=
clnm[idx + idxZ0] * (zsph);
738 if (DIRECTION == Direction::Forward)
740 auto pos = std::array<double, 2>{};
744 splattingAtPos(pos, voxel_mV, mP, mW, mV);
746 else if (DIRECTION == Direction::Backward)
750 double voxel = mId.interpolatedElement2D(pos_x, pos_y);
762 if (0. < x && x <
sigma)
764 else if (-
sigma < x && x <= 0.)
Matrix1D< double > gaussianProjectionTable
std::vector< double > clnm
void defineParams()
Define parameters.
#define A2D_ELEM(v, i, j)
void readParams()
Read argument from command line.
double alpha
Smoothness parameter.
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
double getDoubleParam(const char *param, int arg=0)
__host__ __device__ float2 floor(const float2 v)
#define REPORT_ERROR(nerr, ErrormMsg)
FileName removeFileFormat() const
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
void sqrt(Image< double > &op)
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)
~ProgForwardArtZernike3D()
Destructor.
FileName removeAllExtensions() const
double bspline1(double x)
MultidimArray< int > Vmask
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
Matrix1D< double > gaussianProjectionTable2
FileName afterLastOf(const String &str) const
FileName fnOutDir
Output directory.
bool enable_CTF
Enable CTF part.
#define MAT_ELEM(m, i, j)
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
MultidimArray< size_t > ordered_list
virtual void finishProcessing()
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
MultidimArray< int > mask2D
String findAndReplace(const String &tInput, const String &tFind, const String &tReplace)
void resize(size_t Xdim, bool copy=true)
ProgForwardArtZernike3D()
Empty constructor.
double Tm
Sampling rate (A/pixel)
void addExampleLine(const char *example, bool verbatim=true)
void readFromMdRow(const MDRow &row, bool disable_if_not_K=true)
int verbose
Verbosity level.
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
const T & getValueOrDefault(MDLabel label, const T &def) const
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)
void generate_mask(bool apply_geo=false)
void setRow(size_t i, const Matrix1D< T > &v)
virtual bool containsLabel(MDLabel label) const =0
T dotProduct(const Matrix1D< T > &v1, const Matrix1D< T > &v2)
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
bool outside(int k, int i, int j) const
#define BINARY_CIRCULAR_MASK
void produceSideInfo()
Produce Side information.
int order
Derivation order and Bessel function order.
String getFileFormat() const
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)
std::string to_string(bond_type bondType)
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
bool enable_CTFnoise
Enable CTFnoise part.
const MultidimArray< int > & get_binary_mask() const
int getIntParam(const char *param, int arg=0)
void generateMask(MultidimArray< double > &v)
void getRow(size_t i, Matrix1D< T > &v) const
FileName getBaseName() const
double radius
Spatial radius in Universal System units.
void addParamsLine(const String &line)
void applyMaskSpace(MultidimArray< double > &v)
std::map< String, CommentList > defaultComments
double gaussian1D(double x, double sigma, double mu)