72 <<
"Output directory: " <<
fnOutDir << std::endl
73 <<
"Reference volume: " <<
fnVolR << std::endl
74 <<
"Sampling: " <<
Ts << std::endl
75 <<
"Max. Radius Deform. " <<
RmaxDef << std::endl
76 <<
"Zernike Degree: " <<
L1 << std::endl
77 <<
"SH Degree: " <<
L2 << std::endl
78 <<
"Correct CTF: " <<
useCTF << std::endl
79 <<
"Correct heretogeneity: " <<
useZernike << std::endl
81 <<
"Regularization: " <<
lambda << std::endl
82 <<
"Number of iterations: " <<
niter << std::endl
83 <<
"Save every # iterations: " <<
save_iter << std::endl
90 addUsageLine(
"Template-based canonical volume reconstruction through Zernike3D coefficients");
97 addParamsLine(
" [--odir <outputDir=\".\">] : Output directory");
98 addParamsLine(
" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
99 addParamsLine(
" [--RDef <r=-1>] : Maximum radius of the deformation (px). -1=Half of volume size");
100 addParamsLine(
" [--l1 <l1=3>] : Degree Zernike Polynomials=1,2,3,...");
101 addParamsLine(
" [--l2 <l2=2>] : Harmonical depth of the deformation=1,2,3,...");
102 addParamsLine(
" [--useZernike] : Correct heterogeneity with Zernike3D coefficients");
103 addParamsLine(
" [--useCTF] : Correct CTF during ART reconstruction");
104 addParamsLine(
" [--phaseFlipped] : Input images have been phase flipped");
105 addParamsLine(
" [--regularization <l=0.01>] : ART regularization weight");
106 addParamsLine(
" [--niter <n=1>] : Number of ART iterations");
107 addParamsLine(
" [--save_iter <s=0>] : Save intermidiate volume after #save_iter iterations");
108 addParamsLine(
" [--sort_last <N=2>] : The algorithm sorts projections in the most orthogonally possible way. ");
109 addParamsLine(
" : The most orthogonal way is defined as choosing the projection which maximizes the ");
110 addParamsLine(
" : dot product with the N previous inserted projections. Use -1 to sort with all ");
114 addExampleLine(
"xmipp_art_zernike3d -i anglesFromContinuousAssignment.xmd --ref reference.vol -o assigned_anglesAndDeformations.xmd --l1 3 --l2 2");
137 first_image.
read(fn_first_image);
138 int Xdim_first =
static_cast<int>(
XSIZE(first_image()));
139 V().initZeros(Xdim_first, Xdim_first, Xdim_first);
142 V().setXmippOrigin();
191 void ProgArtZernike3D::finishProcessing() {
206 std::vector<double> vectortemp;
210 for(
int i=0;
i < vectortemp.size()-8;
i++){
213 removeOverdeformation();
234 std::cout <<
"Processing " << fnImg << std::endl;
237 I().setXmippOrigin();
240 artModel<Direction::Forward>();
243 artModel<Direction::Backward>();
249 for (
int h=0; h<=l2; h++)
253 int numEven=(count>>1)+(count&1 && !(h&1));
258 vecSize += numSPH*(l1-h+1-numEven);
270 for (
int h=0; h<=l2; h++) {
271 int totalSPH = 2*h+1;
272 int aux = totalSPH/2;
273 for (
int l=h; l<=l1; l+=2) {
274 for (
int m=0;
m<totalSPH;
m++) {
285 template<
bool INTERPOLATE>
286 float ProgArtZernike3D::weightsInterpolation3D(
float x,
float y,
float z, std::array<float, 8> &
w) {
288 float fx0 =
x -
static_cast<float>(
x0);
290 float fx1 =
static_cast<float>(x1) -
x;
293 float fy0 =
y -
static_cast<float>(
y0);
295 float fy1 =
static_cast<float>(y1) -
y;
298 float fz0 =
z -
static_cast<float>(
z0);
300 float fz1 =
static_cast<float>(z1) -
z;
302 w[0] = fx1 * fy1 * fz1;
303 w[1] = fx1 * fy1 * fz0;
304 w[2] = fx1 * fy0 * fz1;
305 w[3] = fx1 * fy0 * fz0;
306 w[4] = fx0 * fy1 * fz1;
307 w[5] = fx0 * fy1 * fz0;
308 w[6] = fx0 * fy0 * fz1;
309 w[7] = fx0 * fy0 * fz0;
317 return A3D_ELEM(mVr, z0, y0, x0) * w[0] +
331 void ProgArtZernike3D::removeOverdeformation() {
333 size_t idxZ0=2*idxY0;
342 for (
size_t idx=0; idx<idxY0; idx++) {
351 void ProgArtZernike3D::run()
353 FileName fnImg, fnImgOut, fullBaseName;
378 std::cout <<
"Running iteration " <<
current_iter+1 <<
" with lambda=" <<
lambda << std::endl;
415 else if (!
fn_out.empty() )
424 setupRowOut(fnImg, *rowIn.get(), fnImgOut, rowOut);
427 setupRowOut(fnImg, *rowIn.get(), fnImgOut, rowOut);
489 void ProgArtZernike3D::sortOrthogonal() {
497 int min_prod_proj = 0;
498 std::vector<double> rot_v;
499 std::vector<double> tilt_v;
508 for (i = 0; i < numIMG; i++)
527 std::cout <<
"Sorting projections orthogonally...\n" << std::endl;
529 for (i = 1; i < numIMG; i++)
537 for (j = 0; j < numIMG; j++)
545 if (
A1D_ELEM(product, j) < min_prod)
555 A1D_ELEM(chosen, min_prod_proj) = 1;
560 template <ProgArtZernike3D::Direction DIRECTION>
561 void ProgArtZernike3D::artModel()
563 if (DIRECTION == Direction::Forward)
567 P().setXmippOrigin();
569 W().setXmippOrigin();
571 Idiff().setXmippOrigin();
572 I_shifted().initZeros((
int)
XSIZE(
I()), (
int)
XSIZE(
I()));
573 I_shifted().setXmippOrigin();
576 zernikeModel<true, Direction::Forward>();
578 zernikeModel<false, Direction::Forward>();
595 xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, 0.
f);
600 const auto &mP =
P();
601 const auto &mW =
W();
602 const auto &mIsh = I_shifted();
610 error += diffVal * diffVal;
616 std::cout <<
"Error for image " <<
num_images <<
" in iteration " <<
current_iter+1 <<
" : " << error << std::endl;
618 else if (DIRECTION == Direction::Backward)
621 zernikeModel<true, Direction::Backward>();
623 zernikeModel<false, Direction::Backward>();
627 template<
bool USESZERNIKE, ProgArtZernike3D::Direction DIRECTION>
628 void ProgArtZernike3D::zernikeModel() {
629 const auto &mV =
V();
630 const size_t idxY0 = USESZERNIKE ? (
VEC_XSIZE(
clnm) / 3) : 0;
631 const size_t idxZ0 = USESZERNIKE ? (2 * idxY0) : 0;
632 const float RmaxF = USESZERNIKE ?
static_cast<float>(
RmaxDef) : 0.
f;
633 const float RmaxF2 = USESZERNIKE ? (RmaxF * RmaxF) : 0.
f;
634 const float iRmaxF = USESZERNIKE ? (1.0f / RmaxF) : 0.
f;
636 constexpr
size_t matrixSize = 3;
654 auto pos = std::array<float, 3>{};
655 pos[0] = R.
mdata[0] *
static_cast<float>(
j) + R.
mdata[1] * static_cast<float>(
i) + R.
mdata[2] *
static_cast<float>(
k);
656 pos[1] = R.
mdata[3] *
static_cast<float>(
j) + R.
mdata[4] * static_cast<float>(
i) + R.
mdata[5] *
static_cast<float>(
k);
657 pos[2] = R.
mdata[6] *
static_cast<float>(
j) + R.
mdata[7] * static_cast<float>(
i) + R.
mdata[8] *
static_cast<float>(
k);
659 float gx=0.0f, gy=0.0f, gz=0.0f;
662 auto k2 = pos[2] * pos[2];
663 auto kr = pos[2] * iRmaxF;
664 auto k2i2 = k2 + pos[1] * pos[1];
665 auto ir = pos[1] * iRmaxF;
666 auto r2 = k2i2 + pos[0] * pos[0];
667 auto jr = pos[0] * iRmaxF;
668 auto rr =
sqrt(
r2) * iRmaxF;
669 for (
size_t idx = 0; idx < idxY0; idx++)
675 if (rr > 0 || l2 == 0)
685 auto r_x = pos[0] + gx;
686 auto r_y = pos[1] + gy;
687 auto r_z = pos[2] + gz;
689 auto w = std::array<float, 8>{};
690 if (DIRECTION == Direction::Forward)
692 auto voxel = weightsInterpolation3D<true>(r_x, r_y, r_z,
w);
696 A2D_ELEM(
W(),
i,
j) += std::inner_product(
w.begin(),
w.end(),
w.begin(),
static_cast<float>(0));
699 else if (DIRECTION == Direction::Backward)
708 weightsInterpolation3D<false>(r_x, r_y, r_z,
w);
709 if (!
Vrefined().outside(z0, y0, x0))
711 if (!
Vrefined().outside(z1, y0, x0))
713 if (!
Vrefined().outside(z0, y1, x0))
715 if (!
Vrefined().outside(z1, y1, x0))
717 if (!
Vrefined().outside(z0, y0, x1))
719 if (!
Vrefined().outside(z1, y0, x1))
721 if (!
Vrefined().outside(z0, y1, x1))
723 if (!
Vrefined().outside(z1, y1, x1))
#define A2D_ELEM(v, i, j)
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)
#define REPORT_ERROR(nerr, ErrormMsg)
FileName removeFileFormat() const
void defineParams()
Define parameters.
MultidimArray< int > mask2D
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
void readParams()
Read argument from command line.
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)
void compose(const String &str, const size_t no, const String &ext="")
void inv(Matrix2D< T > &result) const
FileName removeAllExtensions() const
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
FileName fnOutDir
Output directory.
MultidimArray< size_t > ordered_list
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
bool enable_CTF
Enable CTF part.
#define MAT_ELEM(m, i, j)
#define A3D_ELEM(V, k, i, j)
void apply_mask(const MultidimArray< T > &I, MultidimArray< T > &result, T subs_val=0, bool apply_geo=false)
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
MultidimArray< int > Vmask
ProgArtZernike3D()
Empty constructor.
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
String findAndReplace(const String &tInput, const String &tFind, const String &tReplace)
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.
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 withoutExtension() const
T dotProduct(const Matrix1D< T > &v1, const Matrix1D< T > &v2)
#define BINARY_CIRCULAR_MASK
void produceSideInfo()
Produce Side information.
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)
void numCoefficients(int l1, int l2)
Length of coefficients vector.
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
void fillVectorTerms(int l1, int l2)
Zernike and SPH coefficients allocation.
void addParamsLine(const String &line)
void applyMaskSpace(MultidimArray< double > &v)
std::map< String, CommentList > defaultComments