Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members
ProgMonogenicSignalRes Class Reference

#include <resolution_monogenic_signal.h>

Inheritance diagram for ProgMonogenicSignalRes:
Inheritance graph
[legend]
Collaboration diagram for ProgMonogenicSignalRes:
Collaboration graph
[legend]

Public Member Functions

void defineParams ()
 
void readParams ()
 
void produceSideInfo ()
 
void excludeArea (MultidimArray< int > &pMask, MultidimArray< int > &pMaskExcl)
 
void amplitudeMonogenicSignal3D (MultidimArray< std::complex< double > > &myfftV, double freq, double freqH, double freqL, MultidimArray< double > &amplitude, int count, FileName fnDebug)
 
void refiningMask (const MultidimArray< std::complex< double > > &myfftV, MultidimArray< double > &iu, int thrs, MultidimArray< int > &pMask)
 
void postProcessingLocalResolutions (MultidimArray< double > &FilteredMap, MultidimArray< double > &resolutionVol, std::vector< double > &list, double &cut_value, MultidimArray< int > &pMask)
 
void run ()
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void show () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fnOut
 
FileName fnVol
 
FileName fnVol2
 
FileName fnMask
 
FileName fnMaskExl
 
FileName fnchim
 
FileName fnSpatial
 
FileName fnMeanVol
 
FileName fnMaskOut
 
FileName fnMd
 
double sampling
 
double minRes
 
double maxRes
 
long NVoxelsOriginalMask
 
int Nvoxels
 
int nthrs
 
double freq_step
 
double significance
 
bool gaussian
 
bool noiseOnlyInHalves
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

SSNR parameters.

Definition at line 49 of file resolution_monogenic_signal.h.

Member Function Documentation

◆ amplitudeMonogenicSignal3D()

void ProgMonogenicSignalRes::amplitudeMonogenicSignal3D ( MultidimArray< std::complex< double > > &  myfftV,
double  freq,
double  freqH,
double  freqL,
MultidimArray< double > &  amplitude,
int  count,
FileName  fnDebug 
)

◆ defineParams()

void ProgMonogenicSignalRes::defineParams ( )
virtual

Function in which the param of each Program are defined.

Reimplemented from XmippProgram.

Definition at line 51 of file resolution_monogenic_signal.cpp.

52 {
53  addUsageLine("MONORES: This algorithm estimates the local resolution map from a single reconstruction");
54  addUsageLine("or two half maps.");
55  addUsageLine("Reference: J.L. Vilas et al, MonoRes: Automatic and Accurate Estimation of ");
56  addUsageLine("Local Resolution for Electron Microscopy Maps, Structure, 26, 337-344, (2018).");
57  addUsageLine(" ");
58  addUsageLine(" ");
59  addParamsLine(" --vol <vol_file=\"\"> : Input map to estimate its local resolution map.");
60  addParamsLine(" : If you want to estimate the local resolution map");
61  addParamsLine(" : by using two half maps, then --vol represents the");
62  addParamsLine(" : first half map, while the second is given by the ");
63  addParamsLine(" : optional parameter --vol2");
64  addParamsLine(" --mask <vol_file=\"\"> : Mask defining the region where the protein is.");
65  addParamsLine(" --minRes <s=30> : Lowest resolution in (A) for the resolution range");
66  addParamsLine(" : to be analyzed.");
67  addParamsLine(" --maxRes <s=1> : Highest resolution in (A) for the resolution range");
68  addParamsLine(" : to be analyzed.");
69  addParamsLine(" --sampling_rate <s=1> : Sampling rate (A/px)");
70  addParamsLine(" -o <output_folder=\"\"> : Folder where the results will be stored.");
71  addParamsLine(" [--vol2 <vol_file=\"\">] : (Optional but recommended) Second half map to estimate its");
72  addParamsLine(" : local resolution map. The first one will be the --vol label.");
73  addParamsLine(" [--maskExcl <vol_file=\"\">] : (Optional) This mask excludes the masked region in the ");
74  addParamsLine(" : estimation of the local resolution.");
75 
76  addParamsLine(" [--step <s=0.25>] : (Optional) The resolution is computed from low to high frequency");
77  addParamsLine(" : in steps of this parameter in (A).");
78  addParamsLine(" [--significance <s=0.95>] : (Optional) The level of confidence for the hypothesis test between");
79  addParamsLine(" : signal and noise.");
80  addParamsLine(" [--threads <s=4>] : (Optional) Number of threads to parallelize the algorithm.");
81  addParamsLine(" [--noiseonlyinhalves] : (Optional) The noise estimation is only performed inside the mask.");
82  addParamsLine(" : This feature only works when two half maps are provided as input.");
83  addParamsLine(" [--gaussian] : (Optional) This flag assumes than the noise is gaussian.");
84  addParamsLine(" : Usually there are no difference between this assumption and the ");
85  addParamsLine(" : exact noise distribution. If this flag is not provided, the exact");
86  addParamsLine(" : distribution is estimated. It is also a faster option than the exact one");
87 }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ excludeArea()

void ProgMonogenicSignalRes::excludeArea ( MultidimArray< int > &  pMask,
MultidimArray< int > &  pMaskExcl 
)

Definition at line 169 of file resolution_monogenic_signal.cpp.

170 {
171  if (halfMapsGiven)
172  {
173  if (noiseOnlyInHalves)
174  {
176  {
177  if (DIRECT_MULTIDIM_ELEM(pMask, n) ==1)
178  {
179  if (DIRECT_MULTIDIM_ELEM(pMaskExcl, n) == 1)
180  DIRECT_MULTIDIM_ELEM(pMask, n) = -1;
181  }
182  else
183  {
184  DIRECT_MULTIDIM_ELEM(pMask, n) = -1;
185  }
186  }
187  }
188  }
189  else
190  {
192  {
193  if (DIRECT_MULTIDIM_ELEM(pMask, n) ==1)
194  {
195  if (DIRECT_MULTIDIM_ELEM(pMaskExcl, n) == 1)
196  DIRECT_MULTIDIM_ELEM(pMask, n) = -1;
197  }
198  }
199  }
200 }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int * n

◆ postProcessingLocalResolutions()

void ProgMonogenicSignalRes::postProcessingLocalResolutions ( MultidimArray< double > &  FilteredMap,
MultidimArray< double > &  resolutionVol,
std::vector< double > &  list,
double &  cut_value,
MultidimArray< int > &  pMask 
)

Definition at line 259 of file resolution_monogenic_signal.cpp.

262 {
263  MultidimArray<double> resolutionVol_aux = FilteredMap;
264  double last_res = list[(list.size()-1)];
265  last_res = last_res - 0.001; //the value 0.001 is a tolerance
266 
267  double Nyquist;
268  Nyquist = 2*sampling;
269 
270  // Count number of voxels with resolution
271  size_t N=0;
273  if (DIRECT_MULTIDIM_ELEM(FilteredMap, n)>=last_res)
274  ++N;
275 
276 
277  // Get all resolution values
278  MultidimArray<double> resolutions(N);
279  size_t N_iter=0;
281  if (DIRECT_MULTIDIM_ELEM(FilteredMap, n)>last_res)
282  DIRECT_MULTIDIM_ELEM(resolutions,N_iter++)=DIRECT_MULTIDIM_ELEM(FilteredMap, n);
283 
284  // Sort value and get threshold
285  std::sort(&A1D_ELEM(resolutions,0),&A1D_ELEM(resolutions,N));
286  double filling_value = A1D_ELEM(resolutions, (int)(0.5*N)); //median value
287 
288  last_res = list[(list.size()-1)];
289 
291  {
292  if (DIRECT_MULTIDIM_ELEM(FilteredMap, n) < last_res)
293  {
294  DIRECT_MULTIDIM_ELEM(FilteredMap, n) = filling_value;
295  DIRECT_MULTIDIM_ELEM(pMask,n) = 0;
296  }
297  else
298  DIRECT_MULTIDIM_ELEM(pMask,n) = 1;
299  }
300 
301  //#ifdef DEBUG_MASK
302  Image<int> imgMask;
303  imgMask = pMask;
304  imgMask.write(fnOut+"/refinedMask.mrc");
305  //#endif
306 
307  double sigma = 3;
308  realGaussianFilter(FilteredMap, sigma);
309 
311  {
312  if (DIRECT_MULTIDIM_ELEM(pMask, n) > 0)
313  {
314  double valFilt = DIRECT_MULTIDIM_ELEM(FilteredMap, n);
315  double valRes = DIRECT_MULTIDIM_ELEM(resolutionVol, n);
316  if (valFilt>valRes)
317  DIRECT_MULTIDIM_ELEM(FilteredMap, n) = valRes;
318  if (valFilt<Nyquist)
319  DIRECT_MULTIDIM_ELEM(FilteredMap, n) = valRes;
320  }
321  }
322 
323  Image<double> outputResolutionImage;
324  outputResolutionImage() = FilteredMap;
325  outputResolutionImage.write(fnOut+"/monoresResolutionChimera.mrc");
326 
328  {
329  if (DIRECT_MULTIDIM_ELEM(pMask, n) == 0)
330  DIRECT_MULTIDIM_ELEM(FilteredMap, n) = 0;
331  }
332 
333  outputResolutionImage() = FilteredMap;//pOutputResolution;//resolutionFiltered;
334  outputResolutionImage.write(fnOut+"/monoresResolutionMap.mrc");
335 }
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)
#define A1D_ELEM(v, i)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
void realGaussianFilter(MultidimArray< double > &img, double sigma)
int * n

◆ produceSideInfo()

void ProgMonogenicSignalRes::produceSideInfo ( )

Definition at line 90 of file resolution_monogenic_signal.cpp.

91 {
92  std::cout << "Starting..." << std::endl;
93  Image<double> V;
94 
95  if ((! fnVol.isEmpty()) && (! fnVol2.isEmpty()))
96  {
97  Image<double> V1, V2;
99  V1.read(fnVol);
100  V2.read(fnVol2);
101  V()=0.5*(V1()+V2());
102  V.write(fnOut+"/meanMap.mrc");
103 
104  V1()-=V2();
105  V1()/=2;
106  FourierTransformer transformer2;
107  transformer2.setThreadsNumber(nthrs);
108  transformer2.FourierTransform(V1(), *fftN);
109  halfMapsGiven = true;
110  }
111  else{
112  V.read(fnVol);
113  halfMapsGiven = false;
114  fftN=&fftV;
115  }
116  V().setXmippOrigin();
117 
118  // Prepare mask
119  MultidimArray<int> &pMask=mask(), &pMaskExl=maskExcl();
120  MultidimArray<double> &inputVol = V();
121 
122  if ( ! fnMask.isEmpty()){
123  mask.read(fnMask);
124  mask().setXmippOrigin();}
125  else{
126  std::cout << "Error: a mask ought to be provided" << std::endl;
127  exit(0);}
128 
129  double smoothparam = 0;
130  int radiuslimit, radius;
131  Monogenic mono;
132  //The mask changes!! all voxels out of the inscribed sphere are set to -1
134  mono.findCliffValue(inputVol, radius, radiuslimit, pMask, smoothparam);
135 
136  if (! fnMaskExl.isEmpty()){
137  maskExcl.read(fnMaskExl);
138  maskExcl().setXmippOrigin();
139  MultidimArray<int> &pMaskExcl = maskExcl();
140  excludeArea(pMask, pMaskExcl);
141  }else
142  {
143  if (halfMapsGiven && noiseOnlyInHalves)
144  {
146  {
147  if (DIRECT_MULTIDIM_ELEM(pMask, n) <1)
148  DIRECT_MULTIDIM_ELEM(pMask, n) = -1;
149  }
150  }
151  }
152 
153  transformer_inv.setThreadsNumber(nthrs);
154  FourierTransformer transformer;
155  transformer.setThreadsNumber(nthrs);
156  VRiesz.resizeNoCopy(inputVol);
157  transformer.FourierTransform(inputVol, fftV);
158 
159  // Frequency volume
160  iu = mono.fourierFreqs_3D(fftV, inputVol, freq_fourier_x, freq_fourier_y, freq_fourier_z);
161 
162  if (freq_step < 0.25)
163  freq_step = 0.25;
164 
165  V.clear();
166 }
void setThreadsNumber(int tNumber)
Definition: xmipp_fftw.h:119
void resizeNoCopy(const MultidimArray< T1 > &v)
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 findCliffValue(MultidimArray< double > &inputmap, int &radius, int &radiuslimit, MultidimArray< int > &mask, double rsmooth)
void excludeArea(MultidimArray< int > &pMask, MultidimArray< int > &pMaskExcl)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
MultidimArray< double > fourierFreqs_3D(const MultidimArray< std::complex< double > > &myfftV, const MultidimArray< double > &inputVol, Matrix1D< double > &freq_fourier_x, Matrix1D< double > &freq_fourier_y, Matrix1D< double > &freq_fourier_z)
#define DIRECT_MULTIDIM_ELEM(v, n)
void FourierTransform(T &v, T1 &V, bool getCopy=true)
Definition: xmipp_fftw.h:166
void proteinRadiusVolumeAndShellStatistics(const MultidimArray< int > &mask, int &radius, long &vol)
bool isEmpty() const
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
int * n
void clear()
Definition: xmipp_image.h:144

◆ readParams()

void ProgMonogenicSignalRes::readParams ( )
virtual

Function in which each program will read parameters that it need. If some error occurs the usage will be printed out.

Reimplemented from XmippProgram.

Definition at line 31 of file resolution_monogenic_signal.cpp.

32 {
33  fnVol = getParam("--vol");
34  fnVol2 = getParam("--vol2");
35  minRes = getDoubleParam("--minRes");
36  maxRes = getDoubleParam("--maxRes");
37  freq_step = getDoubleParam("--step");
38 
39  fnMask = getParam("--mask");
40  fnMaskExl = getParam("--maskExcl");
41 
42  sampling = getDoubleParam("--sampling_rate");
43  significance = getDoubleParam("--significance");
44  fnOut = getParam("-o");
45  gaussian = checkParam("--gaussian");
46  noiseOnlyInHalves = checkParam("--noiseonlyinhalves");
47  nthrs = getIntParam("--threads");
48 }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
bool checkParam(const char *param)
int getIntParam(const char *param, int arg=0)

◆ refiningMask()

void ProgMonogenicSignalRes::refiningMask ( const MultidimArray< std::complex< double > > &  myfftV,
MultidimArray< double > &  iu,
int  thrs,
MultidimArray< int > &  pMask 
)

Definition at line 203 of file resolution_monogenic_signal.cpp.

205 {
206  Monogenic mono;
207  MultidimArray<double> amplitude;
208 
209  amplitude.initZeros(pMask);
210  mono.monogenicAmplitude_3D_Fourier(myfftV, iu, amplitude, thrs);
211 
212  // we smooth applying afilter of std = 4
213  realGaussianFilter(amplitude, 4);
214 
215  double sumS=0, sumN=0, NN = 0, NS = 0;
216  std::vector<double> noiseValues;
217 
219  {
220  double amplitudeValue=DIRECT_MULTIDIM_ELEM(amplitude, n);
221  if (DIRECT_MULTIDIM_ELEM(pMask, n)>=1)
222  {
223 // std::cout << "means_signal = " << amplitudeValue<< std::endl;
224  sumS += amplitudeValue;
225  NS += 1.0;
226  }
227  else if (DIRECT_MULTIDIM_ELEM(pMask, n)==0)
228  {
229  noiseValues.push_back(amplitudeValue);
230  sumN += amplitudeValue;
231  NN += 1.0;
232  }
233  }
234  std::sort(noiseValues.begin(),noiseValues.end());
235 
236  double mean_Signal = sumS/NS;
237  double mean_noise = sumN/NN;
238 
239  double thresholdFirstEstimation = noiseValues[size_t(noiseValues.size()*0.95)];
240 
243  {
244  if (DIRECT_MULTIDIM_ELEM(pMask, n) >=1)
245  {
246  if (DIRECT_MULTIDIM_ELEM(amplitude, n)<thresholdFirstEstimation)
247  {
248  DIRECT_MULTIDIM_ELEM(pMask, n) = 0;
249  }
250  else
251  {
253  }
254  }
255  }
256 }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
void monogenicAmplitude_3D_Fourier(const MultidimArray< std::complex< double > > &myfftV, MultidimArray< double > &iu, MultidimArray< double > &amplitude, int numberOfThreads)
void realGaussianFilter(MultidimArray< double > &img, double sigma)
void initZeros(const MultidimArray< T1 > &op)
int * n

◆ run()

void ProgMonogenicSignalRes::run ( )
virtual

This function will be start running the program. it also should be implemented by derived classes.

Reimplemented from XmippProgram.

Definition at line 338 of file resolution_monogenic_signal.cpp.

339 {
340  produceSideInfo();
341 
342  Image<double> outputResolution;
343  outputResolution().resizeNoCopy(VRiesz);
344 
345  MultidimArray<int> &pMask = mask(), &pMaskExcl = maskExcl();
346  MultidimArray<double> &pOutputResolution = outputResolution();
347  MultidimArray<double> amplitudeMS, amplitudeMN;
348 
349  double criticalZ=icdf_gauss(significance);
350  double criticalW=-1;
351  double resolution, resolution_2, last_resolution = maxRes; //A huge value for achieving
352  double meanS, sdS2, meanN, sdN2, thr95;
353  double freq, freqH, freqL;
354  double max_meanS = -DBL_MIN, cut_value = 0.025; //cut_value represent a percentile 2.5
355  double mean_Signal, mean_noise, thresholdFirstEstimation;
356 
357  bool doNextIteration=true, lefttrimming = false;
358 
359  int fourier_idx, last_fourier_idx = -1;
360 
361  //Defining the resolution range:
362  minRes = 2*sampling;
363  DIGFREQ2FFT_IDX((maxRes+3)/sampling, ZSIZE(VRiesz), fourier_idx);
364  FFT_IDX2DIGFREQ(fourier_idx, ZSIZE(VRiesz), freq);
365  FFT_IDX2DIGFREQ(fourier_idx + 2, ZSIZE(VRiesz), freqH);
366  FFT_IDX2DIGFREQ(fourier_idx - 2, ZSIZE(VRiesz), freqL);
367 
368  int count_res = 0;
369  FileName fnDebug;
370 
371  //TODO: Set as advanced option
372  if (noiseOnlyInHalves == false)
373  refiningMask(fftV, iu, 2, pMask);
374 
375 
376  amplitudeMS.resizeNoCopy(pOutputResolution);
377 
378  int iter=0, volsize;
379  //TODO: take minimum size
380  volsize = XSIZE(pMask);
381 
382  std::vector<double> list;
383 
384  std::cout << "Analyzing frequencies" << std::endl;
385  std::vector<double> noiseValues;
386  Monogenic mono;
387 
388  amplitudeMN.resizeNoCopy(pOutputResolution);
389 
390  pOutputResolution.initZeros(amplitudeMN);
391 
392  do
393  {
394  bool continueIter = false;
395  bool breakIter = false;
396 
397  mono.resolution2eval(count_res, freq_step,
398  resolution, last_resolution,
399  freq, freqH,
400  last_fourier_idx, volsize,
401  continueIter, breakIter,
402  sampling, maxRes);
403 
404  if (continueIter)
405  continue;
406 
407  if (breakIter)
408  break;
409 
410  std::cout << "resolution = " << resolution << std::endl;
411 
412  list.push_back(resolution);
413 
414  if (iter <2)
415  resolution_2 = list[0];
416  else
417  resolution_2 = list[iter - 2];
418 
419  fnDebug = "Signal";
420 
421  // 0.02 is the tail of the raise cosine in digital units
422  freqL = freq + 0.02;
423  freqH = freq - 0.02;
424  if (freqL>=0.5)
425  freqL = 0.5;
426  if (freqH<=0.0)
427  freqH = 0.0;
428 
429 // std::cout << resolution << " " << sampling/freqL << " " << sampling/freq << " " << sampling/freqH << std::endl;
430 
431  mono.amplitudeMonoSig3D_LPF(fftV, transformer_inv,
432  fftVRiesz, fftVRiesz_aux, VRiesz,
433  freq, freqH, freqL, iu,
434  freq_fourier_x, freq_fourier_y, freq_fourier_z,
435  amplitudeMS, iter, fnDebug);
436 
437  if (halfMapsGiven){
438  fnDebug = "Noise";
439  mono.amplitudeMonoSig3D_LPF(*fftN, transformer_inv,
440  fftVRiesz, fftVRiesz_aux, VRiesz,
441  freq, freqH, freqL, iu,
442  freq_fourier_x, freq_fourier_y, freq_fourier_z,
443  amplitudeMN, iter, fnDebug);
444  }
445 
446  double sumS=0, sumS2=0, sumN=0, sumN2=0, NN = 0, NS = 0;
447  noiseValues.clear();
448 
449  if (halfMapsGiven)
450  {
451  mono.statisticsInBinaryMask2(amplitudeMS, amplitudeMN,
452  pMask, meanS, sdS2, meanN, sdN2, significance, thr95, NS, NN);
453  }
454  else
455  {
456  mono.statisticsInOutBinaryMask2(amplitudeMS,
457  pMask, meanS, sdS2, meanN, sdN2, significance, thr95, NS, NN);
458  }
459 
460  if ( (NS/NVoxelsOriginalMask)<cut_value ) //when the 2.5% is reached then the iterative process stops
461  {
462  std::cout << "Search of resolutions stopped due to mask has been completed" << std::endl;
463  doNextIteration =false;
464  Nvoxels = 0;
465 
467  {
468  if (DIRECT_MULTIDIM_ELEM(pOutputResolution, n) == 0)
469  DIRECT_MULTIDIM_ELEM(pMask, n) = 0;
470  else
471  {
472  Nvoxels++;
473  DIRECT_MULTIDIM_ELEM(pMask, n) = 1;
474  }
475  }
476 
477  lefttrimming = true;
478  }
479  else
480  {
481  if (NS == 0)
482  {
483  std::cout << "There are no points to compute inside the mask" << std::endl;
484  std::cout << "If the number of computed frequencies is low, perhaps the provided"
485  "mask is not enough tight to the volume, in that case please try another mask" << std::endl;
486  break;
487  }
488 
489  // Check local resolution
490  double thresholdNoise;
491  if (gaussian)
492  thresholdNoise = meanN+criticalZ*sqrt(sdN2);
493  else
494  thresholdNoise = thr95;
495 
496  if (meanS>max_meanS)
497  max_meanS = meanS;
498 
499  if (meanS<0.001*max_meanS){
500  std::cout << "Search of resolutions stopped due to too low signal" << std::endl;
501  break;}
502 
503  if (halfMapsGiven)
504  {
505  mono.setLocalResolutionHalfMaps(amplitudeMS, pMask, pOutputResolution,
506  thresholdNoise, resolution, resolution_2);
507  }
508  else
509  {
510  mono.setLocalResolutionMap(amplitudeMS, pMask, pOutputResolution,
511  thresholdNoise, resolution, resolution_2);
512  }
513  //}
514 
515  // Is the mean inside the signal significantly different from the noise?
516  double z=(meanS-meanN)/sqrt(sdS2/NS+sdN2/NN);
517 
518  #ifdef DEBUG
519  std::cout << "thresholdNoise = " << thresholdNoise << std::endl;
520  std::cout << " meanS= " << meanS << " sigma2S= " << sdS2 << " NS= " << NS << std::endl;
521  std::cout << " meanN= " << meanN << " sigma2N= " << sdN2 << " NN= " << NN << std::endl;
522  std::cout << " z=" << z << " (" << criticalZ << ")" << std::endl;
523  #endif
524 
525  if (z<criticalZ){
526  criticalW = freq;
527  std::cout << "Search stopped due to z>Z (hypothesis test)" << std::endl;
528  doNextIteration=false;}
529 
530  if (doNextIteration){
531  if (resolution < minRes)
532  doNextIteration = false;}
533  }
534  iter++;
535  last_resolution = resolution;
536  } while (doNextIteration);
537 
538  if (lefttrimming == false)
539  {
540  Nvoxels = 0;
542  {
543  if (DIRECT_MULTIDIM_ELEM(pOutputResolution, n) == 0)
544  DIRECT_MULTIDIM_ELEM(pMask, n) = 0;
545  else
546  {
547  Nvoxels++;
548  DIRECT_MULTIDIM_ELEM(pMask, n) = 1;
549  }
550  }
551  }
552  amplitudeMN.clear();
553  amplitudeMS.clear();
554 
555  MultidimArray<double> FilteredResolution = pOutputResolution;
556  postProcessingLocalResolutions(FilteredResolution, pOutputResolution, list, cut_value, pMask);;
557 }
void resizeNoCopy(const MultidimArray< T1 > &v)
void sqrt(Image< double > &op)
double icdf_gauss(double p)
void statisticsInOutBinaryMask2(const MultidimArray< double > &volS, MultidimArray< int > &mask, double &meanS, double &sdS2, double &meanN, double &sdN2, double &significance, double &thr95, double &NS, double &NN)
void statisticsInBinaryMask2(const MultidimArray< double > &volS, const MultidimArray< double > &volN, MultidimArray< int > &mask, double &meanS, double &sdS2, double &meanN, double &sdN2, double &significance, double &thr95, double &NS, double &NN)
void resolution2eval(int &count_res, double step, double &resolution, double &last_resolution, double &freq, double &freqL, int &last_fourier_idx, int &volsize, bool &continueIter, bool &breakIter, double &sampling, double &maxRes)
glob_prnt iter
#define DIGFREQ2FFT_IDX(freq, size, idx)
Definition: xmipp_fft.h:61
void setLocalResolutionHalfMaps(const MultidimArray< double > &amplitudeMS, MultidimArray< int > &pMask, MultidimArray< double > &plocalResolutionMap, double thresholdNoise, double resolution, double resolution_2)
#define XSIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define ZSIZE(v)
double z
#define DIRECT_MULTIDIM_ELEM(v, n)
void amplitudeMonoSig3D_LPF(const MultidimArray< std::complex< double > > &myfftV, FourierTransformer &transformer_inv, MultidimArray< std::complex< double > > &fftVRiesz, MultidimArray< std::complex< double > > &fftVRiesz_aux, MultidimArray< double > &VRiesz, double freq, double freqH, double freqL, MultidimArray< double > &iu, Matrix1D< double > &freq_fourier_x, Matrix1D< double > &freq_fourier_y, Matrix1D< double > &freq_fourier_z, MultidimArray< double > &amplitude, int count, FileName fnDebug)
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
#define DBL_MIN
void setLocalResolutionMap(const MultidimArray< double > &amplitudeMS, MultidimArray< int > &pMask, MultidimArray< double > &plocalResolutionMap, double thresholdNoise, double resolution, double resolution_2)
void initZeros(const MultidimArray< T1 > &op)
void postProcessingLocalResolutions(MultidimArray< double > &FilteredMap, MultidimArray< double > &resolutionVol, std::vector< double > &list, double &cut_value, MultidimArray< int > &pMask)
void refiningMask(const MultidimArray< std::complex< double > > &myfftV, MultidimArray< double > &iu, int thrs, MultidimArray< int > &pMask)
int * n

Member Data Documentation

◆ fnchim

FileName ProgMonogenicSignalRes::fnchim

Definition at line 53 of file resolution_monogenic_signal.h.

◆ fnMask

FileName ProgMonogenicSignalRes::fnMask

Definition at line 53 of file resolution_monogenic_signal.h.

◆ fnMaskExl

FileName ProgMonogenicSignalRes::fnMaskExl

Definition at line 53 of file resolution_monogenic_signal.h.

◆ fnMaskOut

FileName ProgMonogenicSignalRes::fnMaskOut

Definition at line 53 of file resolution_monogenic_signal.h.

◆ fnMd

FileName ProgMonogenicSignalRes::fnMd

Definition at line 53 of file resolution_monogenic_signal.h.

◆ fnMeanVol

FileName ProgMonogenicSignalRes::fnMeanVol

Definition at line 53 of file resolution_monogenic_signal.h.

◆ fnOut

FileName ProgMonogenicSignalRes::fnOut

Filenames

Definition at line 53 of file resolution_monogenic_signal.h.

◆ fnSpatial

FileName ProgMonogenicSignalRes::fnSpatial

Definition at line 53 of file resolution_monogenic_signal.h.

◆ fnVol

FileName ProgMonogenicSignalRes::fnVol

Definition at line 53 of file resolution_monogenic_signal.h.

◆ fnVol2

FileName ProgMonogenicSignalRes::fnVol2

Definition at line 53 of file resolution_monogenic_signal.h.

◆ freq_step

double ProgMonogenicSignalRes::freq_step

Step in digital frequency

Definition at line 64 of file resolution_monogenic_signal.h.

◆ gaussian

bool ProgMonogenicSignalRes::gaussian

The search for resolutions is linear or inverse

Definition at line 67 of file resolution_monogenic_signal.h.

◆ maxRes

double ProgMonogenicSignalRes::maxRes

Definition at line 57 of file resolution_monogenic_signal.h.

◆ minRes

double ProgMonogenicSignalRes::minRes

Definition at line 57 of file resolution_monogenic_signal.h.

◆ noiseOnlyInHalves

bool ProgMonogenicSignalRes::noiseOnlyInHalves

Definition at line 67 of file resolution_monogenic_signal.h.

◆ nthrs

int ProgMonogenicSignalRes::nthrs

Definition at line 61 of file resolution_monogenic_signal.h.

◆ Nvoxels

int ProgMonogenicSignalRes::Nvoxels

Definition at line 61 of file resolution_monogenic_signal.h.

◆ NVoxelsOriginalMask

long ProgMonogenicSignalRes::NVoxelsOriginalMask

Is the volume previously masked?

Definition at line 60 of file resolution_monogenic_signal.h.

◆ sampling

double ProgMonogenicSignalRes::sampling

sampling rate, minimum resolution, and maximum resolution

Definition at line 57 of file resolution_monogenic_signal.h.

◆ significance

double ProgMonogenicSignalRes::significance

Definition at line 64 of file resolution_monogenic_signal.h.


The documentation for this class was generated from the following files: