80 <<
"Output directory: " <<
fnOutDir << std::endl
81 <<
"Reference volume: " <<
fnVolR << std::endl
82 <<
"Reference mask: " <<
fnMaskR << std::endl
83 <<
"Sampling: " <<
Ts << std::endl
84 <<
"Max. Radius Deform. " <<
RmaxDef << std::endl
85 <<
"Zernike Degree: " <<
L1 << std::endl
86 <<
"SH Degree: " <<
L2 << std::endl
87 <<
"Blob radius: " <<
blob_r << std::endl
89 <<
"Correct CTF: " <<
useCTF << std::endl
90 <<
"Correct heretogeneity: " <<
useZernike << std::endl
92 <<
"Regularization: " <<
lambda << std::endl
93 <<
"Number of iterations: " <<
niter << std::endl
94 <<
"Save every # iterations: " <<
save_iter << std::endl;
100 addUsageLine(
"Template-based canonical volume reconstruction through Zernike3D coefficients");
108 addParamsLine(
" [--odir <outputDir=\".\">] : Output directory");
109 addParamsLine(
" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
110 addParamsLine(
" [--RDef <r=-1>] : Maximum radius of the deformation (px). -1=Half of volume size");
111 addParamsLine(
" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
112 addParamsLine(
" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
113 addParamsLine(
" [--blobr <b=4>] : Blob radius for forward mapping splatting");
116 addParamsLine(
" [--useZernike] : Correct heterogeneity with Zernike3D coefficients");
117 addParamsLine(
" [--useCTF] : Correct CTF during ART reconstruction");
118 addParamsLine(
" [--phaseFlipped] : Input images have been phase flipped");
119 addParamsLine(
" [--regularization <l=0.01>] : ART regularization weight");
120 addParamsLine(
" [--niter <n=1>] : Number of ART iterations");
121 addParamsLine(
" [--save_iter <s=0>] : Save intermidiate volume after #save_iter iterations");
122 addParamsLine(
" [--sort_last <N=2>] : The algorithm sorts projections in the most orthogonally possible way. ");
123 addParamsLine(
" : The most orthogonal way is defined as choosing the projection which maximizes the ");
124 addParamsLine(
" : dot product with the N previous inserted projections. Use -1 to sort with all ");
130 addExampleLine(
"xmipp_art_zernike3d -i anglesFromContinuousAssignment.xmd --ref reference.vol -o assigned_anglesAndDeformations.xmd --l1 3 --l2 2");
168 first_image.
read(fn_first_image);
169 size_t Xdim_first =
XSIZE(first_image());
170 V().initZeros(Xdim_first, Xdim_first, Xdim_first);
172 V().setXmippOrigin();
176 Vout().initZeros(
V());
177 Vout().setXmippOrigin();
290 if (img_enabled == -1)
return;
299 std::vector<double> vectortemp;
303 std::vector<double> vec(vectortemp.begin(), vectortemp.end());
333 std::cout <<
"Processing " << fnImg << std::endl;
336 I().setXmippOrigin();
339 artModel<Direction::Forward>();
343 artModel<Direction::Backward>();
355 for (
int h = 0; h <= l2; h++)
357 int numSPH = 2 * h + 1;
358 int count = l1 - h + 1;
359 int numEven = (count >> 1) + (count & 1 && !(h & 1));
362 vecSize += numSPH * numEven;
366 vecSize += numSPH * (l1 - h + 1 - numEven);
379 for (
int h = 0; h <= l2; h++)
381 int totalSPH = 2 * h + 1;
383 for (
int l = h;
l <= l1;
l += 2)
385 for (
int m = 0;
m < totalSPH;
m++)
403 void ProgForwardArtZernike3DSubtomos::splattingAtPos(std::array<double, 3> r,
double weight,
418 for (
int k = k0;
k <= kF;
k++)
420 int k_int =
ROUND(50 * (
k - z_pos));
421 for (
int i = i0;
i <= iF;
i++)
423 int i_int =
ROUND(50 * (
i - y_pos));
424 for (
int j = j0;
j <= jF;
j++)
429 int j_int =
ROUND(50 * (
j - x_pos));
432 double gw =
A3D_ELEM(mG, k_int, i_int, j_int);
441 void ProgForwardArtZernike3DSubtomos::updateVoxel(std::array<double, 3> r,
double &voxel,
MultidimArray<double> &mV)
447 double hsigma4 = 4 *
sqrt(2);
459 for (
int k = k0;
k <= kF;
k++)
461 for (
int i = i0;
i <= iF;
i++)
463 for (
int j = j0;
j <= jF;
j++)
476 auto &mVout =
Vout();
485 auto pos = std::array<double, 3>{};
505 void ProgForwardArtZernike3DSubtomos::run()
507 FileName fnImg, fnImgOut, fullBaseName;
533 std::cout <<
"Running iteration " <<
current_iter + 1 <<
" with lambda=" <<
lambda << std::endl;
542 if (rowIn ==
nullptr)
continue;
652 void ProgForwardArtZernike3DSubtomos::sortOrthogonal()
662 int min_prod_proj = 0;
663 std::vector<double>
rot;
664 std::vector<double>
tilt;
673 for (i = 0; i < numIMG; i++)
692 std::cout <<
"Sorting projections orthogonally...\n" 695 for (i = 1; i < numIMG; i++)
703 for (j = 0; j < numIMG; j++)
711 if (
A1D_ELEM(product, j) < min_prod)
721 A1D_ELEM(chosen, min_prod_proj) = 1;
725 template <ProgForwardArtZernike3DSubtomos::Direction DIRECTION>
726 void ProgForwardArtZernike3DSubtomos::artModel()
728 if (DIRECTION == Direction::Forward)
732 P().setXmippOrigin();
734 W().setXmippOrigin();
736 Idiff().setXmippOrigin();
738 I_shifted().setXmippOrigin();
741 zernikeModel<true, Direction::Forward>();
743 zernikeModel<false, Direction::Forward>();
764 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.);
774 const auto &mP =
P();
775 const auto &mW =
W();
776 const auto &mIsh = I_shifted();
784 error += (diffVal) * (diffVal);
795 std::cout <<
"Press any key" << std::endl;
802 std::cout <<
"Error for image " <<
num_images <<
" in iteration " <<
current_iter + 1 <<
" : " << error << std::endl;
804 else if (DIRECTION == Direction::Backward)
807 zernikeModel<true, Direction::Backward>();
809 zernikeModel<false, Direction::Backward>();
813 template <
bool USESZERNIKE, ProgForwardArtZernike3DSubtomos::Direction DIRECTION>
814 void ProgForwardArtZernike3DSubtomos::zernikeModel()
820 const size_t idxY0 = USESZERNIKE ? (
clnm.size() / 3) : 0;
821 const size_t idxZ0 = USESZERNIKE ? (2 * idxY0) : 0;
822 const double RmaxF = USESZERNIKE ?
RmaxDef : 0;
823 const double RmaxF2 = USESZERNIKE ? (RmaxF * RmaxF) : 0;
824 const double iRmaxF = USESZERNIKE ? (1.0 / RmaxF) : 0;
826 constexpr
size_t matrixSize = 3;
845 const int step = DIRECTION == Direction::Forward ?
loop_step : 1;
854 double gx = 0.0f, gy = 0.0f, gz = 0.0f;
859 auto kr = k * iRmaxF;
860 auto k2i2 = k2 +
i *
i;
861 auto ir = i * iRmaxF;
862 auto r2 = k2i2 +
j *
j;
863 auto jr = j * iRmaxF;
864 auto rr =
sqrt(
r2) * iRmaxF;
865 for (
size_t idx = 0; idx < idxY0; idx++)
871 if (rr > 0 || l2 == 0)
874 gx +=
clnm[idx] * (zsph);
875 gy +=
clnm[idx + idxY0] * (zsph);
876 gz +=
clnm[idx + idxZ0] * (zsph);
885 if (DIRECTION == Direction::Forward)
887 auto pos = std::array<double, 3>{};
892 splattingAtPos(pos, voxel_mV, mP, mW, mV);
894 else if (DIRECTION == Direction::Backward)
903 double voxel = mId.interpolatedElement3D(pos_x, pos_y, pos_z);
double alpha
Smoothness parameter.
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void fillVectorTerms(int l1, int l2, Matrix1D< int > &vL1, Matrix1D< int > &vN, Matrix1D< int > &vL2, Matrix1D< int > &vM)
Zernike and SPH coefficients allocation.
double getDoubleParam(const char *param, int arg=0)
__host__ __device__ float2 floor(const float2 v)
#define REPORT_ERROR(nerr, ErrormMsg)
FileName removeFileFormat() const
void readParams()
Read argument from command line.
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
MultidimArray< int > mask2D
void BinaryWedgeMask(MultidimArray< int > &mask, double theta0, double thetaF, const Matrix2D< double > &A, bool centerOrigin)
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
void sqrt(Image< double > &op)
void numCoefficients(int l1, int l2, int &vecSize)
Length of coefficients vector.
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)
~ProgForwardArtZernike3DSubtomos()
Destructor.
ProgForwardArtZernike3DSubtomos()
Empty constructor.
virtual void finishProcessing()
FileName removeAllExtensions() const
void applyMissingWedge(MultidimArray< double > &mV)
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
bool enable_CTF
Enable CTF part.
#define MAT_ELEM(m, i, j)
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
MultidimArray< size_t > ordered_list
String findAndReplace(const String &tInput, const String &tFind, const String &tReplace)
FourierTransformer transformer
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
double Tm
Sampling rate (A/pixel)
#define DIRECT_MULTIDIM_ELEM(v, n)
void addExampleLine(const char *example, bool verbatim=true)
void readFromMdRow(const MDRow &row, bool disable_if_not_K=true)
int verbose
Verbosity level.
MultidimArray< double > gaussian3d
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
FileName fnOutDir
Output directory.
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
MultidimArray< int > Vmask
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::vector< double > clnm
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 defineParams()
Define parameters.
void generateMask(MultidimArray< double > &v)
void getRow(size_t i, Matrix1D< T > &v) const
FileName getBaseName() const
void addParamsLine(const String &line)
void applyMaskSpace(MultidimArray< double > &v)
std::map< String, CommentList > defaultComments
double gaussian1D(double x, double sigma, double mu)