57 addUsageLine(
"This function determines the local resolution of a tomogram. It makes use of two reconstructions, odd and even. The difference between them" 58 "gives a noise reconstruction. Thus, by computing the local amplitude of the signal at different frequencies and establishing a comparison with" 59 "the noise, the local resolution is computed");
62 addParamsLine(
" [--mask <vol_file=\"\">] : Mask defining the signal. ");
63 addParamsLine(
" -o <output=\"MGresolution.vol\"> : Local resolution volume (in Angstroms)");
64 addParamsLine(
" [--maskWedge <vol_file=\"\">] : Mask containing the missing wedge in Fourier space");
65 addParamsLine(
" [--filteredMap <vol_file=\"\">] : Local resolution volume filtered considering the missing wedge (in Angstroms)");
66 addParamsLine(
" --meanVol <vol_file=\"\"> : Mean volume of half1 and half2 (only it is necessary the two haves are used)");
67 addParamsLine(
" [--sampling_rate <s=1>] : Sampling rate (A/px)");
68 addParamsLine(
" [--step <s=0.25>] : The resolution is computed at a number of frequencies between minimum and");
69 addParamsLine(
" : maximum resolution px/A. This parameter determines that number");
73 addParamsLine(
" [--significance <s=0.95>] : The level of confidence for the hypothesis test.");
80 std::cout <<
"Starting..." << std::endl;
81 std::cout <<
" " << std::endl;
82 std::cout <<
"IMPORTANT: If the angular step of the tilt series is higher than 3 degrees"<< std::endl;
83 std::cout <<
" then, the tomogram is not properly for MonoTomo. Despite this is not "<< std::endl;
84 std::cout <<
" optimal, MonoTomo will try to compute the local resolution." << std::endl;
85 std::cout <<
" " << std::endl;
104 double modulus, xx, yy, zz;
107 for(
size_t k=0;
k<
ZSIZE(inputVol); ++
k)
110 for(
size_t i=0;
i<
YSIZE(inputVol); ++
i)
113 for(
size_t j=0;
j<
XSIZE(inputVol); ++
j)
124 saveiu.
write(
"franjas.vol");
133 double uz, uy, ux, uz2, u2, uz2y2;
149 if ((
k != 0) || (
i != 0) || (
j != 0))
160 saveiu.
write(
"iu.vol");
175 mask().setXmippOrigin();
179 size_t Zdim, Ydim, Xdim, Ndim;
181 mask().resizeNoCopy(Ndim, Zdim, Ydim, Xdim);
182 mask().initConstant(1);
210 V1.
write(
"diff_volume.vol");
213 int N_smoothing = 10;
215 int siz_z =
ZSIZE(inputVol)*0.5;
216 int siz_y =
YSIZE(inputVol)*0.5;
217 int siz_x =
XSIZE(inputVol)*0.5;
220 int limit_distance_x = (siz_x-N_smoothing);
221 int limit_distance_y = (siz_y-N_smoothing);
222 int limit_distance_z = (siz_z-N_smoothing);
225 for(
int k=0;
k<
ZSIZE(inputVol); ++
k)
228 for(
int i=0;
i<
YSIZE(inputVol); ++
i)
231 for(
int j=0;
j<
XSIZE(inputVol); ++
j)
235 if (
abs(ux)>=limit_distance_x)
240 if (
abs(uy)>=limit_distance_y)
245 if (
abs(uz)>=limit_distance_z)
295 std::complex<double> J(0,1);
299 double ideltal=
PI/(freq-freqH);
305 if (freqH<=un && un<=freq)
333 if (fnDebug.c_str() !=
"")
335 saveImg2.
write(fnDebug+iternumber);
348 for(
size_t k=0;
k<
ZSIZE(myfftV); ++
k)
350 for(
size_t i=0;
i<
YSIZE(myfftV); ++
i)
352 for(
size_t j=0;
j<
XSIZE(myfftV); ++
j)
366 for(
size_t k=0;
k<
ZSIZE(myfftV); ++
k)
369 for(
size_t i=0;
i<
YSIZE(myfftV); ++
i)
372 for(
size_t j=0;
j<
XSIZE(myfftV); ++
j)
393 if (fnDebug.c_str() !=
"")
399 saveImg.
write(fnDebug+iternumber);
406 double raised_w =
PI/(freqL-freq);
413 if (freqL>=un && un>=freq)
430 saveImg2 = amplitude;
432 if (fnDebug.c_str() !=
"")
434 iternumber =
formatString(
"_Filtered_Amplitude_%i.vol", count);
435 saveImg2.
write(fnDebug+iternumber);
449 int Nx = xdim/boxsize;
450 int Ny = ydim/boxsize;
461 double hX = xdim / (double)(lX-3);
462 double hY = ydim / (double)(lY-3);
464 if ( (xdim<boxsize) || (ydim<boxsize) )
465 std::cout <<
"Error: The tomogram in x-direction or y-direction is too small" << std::endl;
467 std::vector<double> noiseVector(1);
468 std::vector<double>
x,
y,t;
470 int xLimit, yLimit, xStart, yStart;
475 for (
int X_boxIdx=0; X_boxIdx<Nx; ++X_boxIdx)
479 xStart =
STARTINGX(noiseMap) + X_boxIdx*boxsize;
484 xStart =
STARTINGX(noiseMap) + X_boxIdx*boxsize;
485 xLimit =
STARTINGX(noiseMap) + (X_boxIdx+1)*boxsize;
488 for (
int Y_boxIdx=0; Y_boxIdx<Ny; ++Y_boxIdx)
492 yStart =
STARTINGY(noiseMap) + Y_boxIdx*boxsize;
497 yStart =
STARTINGY(noiseMap) + Y_boxIdx*boxsize;
498 yLimit =
STARTINGY(noiseMap) + (Y_boxIdx+1)*boxsize;
504 for (
int i = yStart;
i<yLimit;
i++)
506 for (
int j = xStart;
j<xLimit;
j++)
510 if (counter%257 == 0)
511 noiseVector.push_back(
A3D_ELEM(noiseMap,
k,
i,
j) );
517 std::sort(noiseVector.begin(),noiseVector.end());
518 MAT_ELEM(noiseMatrix, Y_boxIdx, X_boxIdx) = noiseVector[size_t(noiseVector.size()*
significance)];
520 double tileCenterY=0.5*(yLimit+yStart)-
STARTINGY(noiseMap);
521 double tileCenterX=0.5*(xLimit+xStart)-
STARTINGX(noiseMap);
524 for(
int controlIdxY = -1; controlIdxY < (lY - 1); ++controlIdxY)
526 double tmpY =
Bspline03((tileCenterY / hY) - controlIdxY);
534 for(
int controlIdxX = -1; controlIdxX < (lX - 1); ++controlIdxX)
536 double tmpX =
Bspline03((tileCenterX / hX) - controlIdxX);
537 MAT_ELEM(helper.
A,idxBox,idxSpline) = tmpY * tmpX;
541 x.push_back(tileCenterX);
542 y.push_back(tileCenterY);
543 t.push_back(
MAT_ELEM(noiseMatrix, Y_boxIdx, X_boxIdx));
562 for(
int controlIdxY = -1; controlIdxY < (lY - 1); ++controlIdxY)
564 double tmpY =
Bspline03((
i / hY) - controlIdxY);
573 for(
int controlIdxX = -1; controlIdxX < (lX - 1); ++controlIdxX)
575 double tmpX =
Bspline03((
j / hX) - controlIdxX);
576 xContrib+=
VEC_ELEM(cij,idxSpline) * tmpX;
588 std::vector<double> &list)
591 double init_res, last_res;
594 last_res = list[(list.size()-1)];
596 double last_resolution_2 = list[last_res];
599 lowest_res = list[1];
603 std::vector<double> resolVec(0);
608 if ( (rVol>=(last_resolution_2-0.001)) && (rVol<=lowest_res) )
610 resolVec.push_back(rVol);
616 std::sort(resolVec.begin(), resolVec.end());
618 std::cout <<
"median Resolution = " << resolVec[(int)(0.5*N)] << std::endl;
624 std::vector<double> &list,
double &cut_value,
double &resolutionThreshold)
626 double last_resolution_2 = list[(list.size()-1)];
629 lowest_res = list[0];
634 std::vector<double> resolVec(0);
638 if (rVol>=(last_resolution_2-0.001))
640 resolVec.push_back(rVol);
647 std::sort(resolVec.begin(), resolVec.end());
649 resolutionThreshold = resolVec[(int)((0.95)*N)];
651 std::cout <<
"resolutionThreshold = " << resolutionThreshold << std::endl;
656 double &resolution,
double &last_resolution,
657 double &freq,
double &freqL,
658 int &last_fourier_idx,
659 bool &continueIter,
bool &breakIter)
661 resolution =
maxRes - count_res*step;
666 double aux_frequency;
673 freq = aux_frequency;
675 if (fourier_idx == last_fourier_idx)
681 last_fourier_idx = fourier_idx;
682 resolution =
sampling/aux_frequency;
686 last_resolution = resolution;
688 if (resolution<Nyquist)
694 freqL =
sampling/(resolution + step);
700 if (fourier_idx_2 == fourier_idx)
702 if (fourier_idx > 0){
706 freqL =
sampling/(resolution + step);
719 outputResolution().resizeNoCopy(
VRiesz);
720 outputResolution().initConstant(
maxRes);
730 double resolution, resolution_2, last_resolution = 10000;
732 double freq, freqH, freqL;
733 double max_meanS = -1e38;
734 double cut_value = 0.025;
747 bool doNextIteration=
true;
749 bool lefttrimming =
false;
750 int last_fourier_idx = -1;
756 std::vector<double> list;
758 std::cout <<
"Analyzing frequencies" << std::endl;
759 std::cout <<
" " << std::endl;
760 std::vector<double> noiseValues;
767 bool continueIter =
false;
768 bool breakIter =
false;
771 resolution, last_resolution,
773 last_fourier_idx, continueIter, breakIter);
781 std::cout <<
"resolution = " << resolution << std::endl;
784 list.push_back(resolution);
787 resolution_2 = list[0];
789 resolution_2 = list[iter - 2];
802 localNoise(amplitudeMN, noiseMatrix, boxsize, thresholdMatrix);
805 double sumS=0, sumS2=0, sumN=0, sumN2=0, NN = 0, NS = 0;
815 sumS += amplitudeValue;
816 noiseValues.push_back(amplitudeValueN);
817 sumN += amplitudeValueN;
824 std::cout <<
"NS" << NS << std::endl;
832 std::cout <<
"There are no points to compute inside the mask" << std::endl;
833 std::cout <<
"If the number of computed frequencies is low, perhaps the provided" 834 "mask is not enough tight to the volume, in that case please try another mask" << std::endl;
838 double meanS=sumS/NS;
841 std::cout <<
"Iteration = " << iter <<
", Resolution= " << resolution <<
842 ", Signal = " << meanS <<
", Noise = " << meanN <<
", Threshold = " 843 << thresholdNoise <<std::endl;
850 if (meanS<0.001*max_meanS)
852 std::cout <<
"Search of resolutions stopped due to too low signal" << std::endl;
888 if (resolution <= (
minRes-0.001))
889 doNextIteration =
false;
894 last_resolution = resolution;
895 }
while (doNextIteration);
898 outputResolutionImage2() = pOutputResolution;
899 outputResolutionImage2.
write(
"resultado.vol");
909 double resolutionThreshold;
941 outputResolutionImage() = FilteredResolution;
FourierTransformer transformer_inv
void min(Image< double > &op1, const Image< double > &op2)
void lowestResolutionbyPercentile(MultidimArray< double > &resolutionVol, std::vector< double > &list, double &cut_value, double &resolutionThreshold)
double getDoubleParam(const char *param, int arg=0)
void resolution2eval(int &count_res, double step, double &resolution, double &last_resolution, double &freq, double &freqL, int &last_fourier_idx, bool &continueIter, bool &breakIter)
void localNoise(MultidimArray< double > &noiseMap, Matrix2D< double > &noiseMatrix, int boxsize, Matrix2D< double > &thresholdMatrix)
Matrix1D< double > freq_fourier_z
Image< double > VresolutionFiltered
void resizeNoCopy(const MultidimArray< T1 > &v)
void sqrt(Image< double > &op)
MultidimArray< double > iu
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)
MultidimArray< double > VRiesz
double icdf_gauss(double p)
void abs(Image< double > &op)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY3D(V)
#define DIGFREQ2FFT_IDX(freq, size, idx)
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 MAT_ELEM(m, i, j)
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
const char * getParam(const char *param, int arg=0)
Matrix1D< double > freq_fourier_y
FourierFilter lowPassFilter
double Bspline03(double Argument)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
MultidimArray< std::complex< double > > * fftN
MultidimArray< std::complex< double > > fftV
void sort(struct DCEL_T *dcel)
#define DIRECT_A3D_ELEM(v, k, i, j)
void amplitudeMonogenicSignal3D(MultidimArray< std::complex< double > > &myfftV, double freq, double freqH, double freqL, MultidimArray< double > &litude, int count, FileName fnDebug)
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
MultidimArray< std::complex< double > > fftVRiesz
void realGaussianFilter(MultidimArray< double > &img, double sigma)
String formatString(const char *format,...)
MultidimArray< std::complex< double > > fftVRiesz_aux
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Matrix1D< double > freq_fourier_x
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
void weightedLeastSquares(WeightedLeastSquaresHelper &h, Matrix1D< double > &result)
int getIntParam(const char *param, int arg=0)
void addParamsLine(const String &line)
Image< double > Vfiltered
void postProcessingLocalResolutions(MultidimArray< double > &resolutionVol, std::vector< double > &list)
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const